Transfer most available gtk-xt code to xoptions.c
[xboard.git] / xtimer.c
index 46dd334..96313f9 100644 (file)
--- a/xtimer.c
+++ b/xtimer.c
@@ -57,6 +57,8 @@
 #include <signal.h>
 #include <sys/types.h>
 
+#include <gtk/gtk.h>
+
 #if STDC_HEADERS
 # include <stdlib.h>
 # include <string.h>
@@ -92,17 +94,9 @@ extern char *getenv();
 # include <sys/wait.h>
 #endif
 
-#include <X11/Intrinsic.h>
-
-// [HGM] bitmaps: put before incuding the bitmaps / pixmaps, to know how many piece types there are.
 #include "common.h"
-#include "frontend.h"
 #include "backend.h"
-#include "backendz.h"
-#include "moves.h"
-#include "xboard.h"
-#include "xboard2.h"
-
+#include "frontend.h"
 
 #ifdef __EMX__
 #ifndef HAVE_USLEEP
@@ -111,35 +105,32 @@ extern char *getenv();
 #define usleep(t)   _sleep2(((t)+500)/1000)
 #endif
 
-// in xboard.c (should go to xtimer.h ?)
-extern XtAppContext appContext;
-
-XtIntervalId delayedEventTimerXID = 0;
+guint delayedEventTimerTag = 0;
 DelayedEventCallback delayedEventCallback = 0;
 
 void
-FireDelayedEvent ()
+FireDelayedEvent(gpointer data)
 {
-    delayedEventTimerXID = 0;
+    g_source_remove(delayedEventTimerTag);
+    delayedEventTimerTag = 0;
     delayedEventCallback();
 }
 
 void
 ScheduleDelayedEvent (DelayedEventCallback cb, long millisec)
 {
-    if(delayedEventTimerXID && delayedEventCallback == cb)
+    if(delayedEventTimerTag && delayedEventCallback == cb)
        // [HGM] alive: replace, rather than add or flush identical event
-       XtRemoveTimeOut(delayedEventTimerXID);
+        g_source_remove(delayedEventTimerTag);
+    delayedEventCallback = cb;
     delayedEventCallback = cb;
-    delayedEventTimerXID =
-      XtAppAddTimeOut(appContext, millisec,
-                     (XtTimerCallbackProc) FireDelayedEvent, (XtPointer) 0);
+    delayedEventTimerTag = g_timeout_add(millisec,(GSourceFunc) FireDelayedEvent, NULL);
 }
 
 DelayedEventCallback
 GetDelayedEvent ()
 {
-  if (delayedEventTimerXID) {
+  if (delayedEventTimerTag) {
     return delayedEventCallback;
   } else {
     return NULL;
@@ -149,26 +140,26 @@ GetDelayedEvent ()
 void
 CancelDelayedEvent ()
 {
-  if (delayedEventTimerXID) {
-    XtRemoveTimeOut(delayedEventTimerXID);
-    delayedEventTimerXID = 0;
+  if (delayedEventTimerTag) {
+    g_source_remove(delayedEventTimerTag);
+    delayedEventTimerTag = 0;
   }
 }
 
-XtIntervalId loadGameTimerXID = 0;
 
-int
-LoadGameTimerRunning ()
+guint loadGameTimerTag = 0;
+
+int LoadGameTimerRunning()
 {
-    return loadGameTimerXID != 0;
+    return loadGameTimerTag != 0;
 }
 
 int
 StopLoadGameTimer ()
 {
-    if (loadGameTimerXID != 0) {
-       XtRemoveTimeOut(loadGameTimerXID);
-       loadGameTimerXID = 0;
+    if (loadGameTimerTag != 0) {
+       g_source_remove(loadGameTimerTag);
+       loadGameTimerTag = 0;
        return TRUE;
     } else {
        return FALSE;
@@ -176,56 +167,53 @@ StopLoadGameTimer ()
 }
 
 void
-LoadGameTimerCallback (XtPointer arg, XtIntervalId *id)
+LoadGameTimerCallback(gpointer data)
 {
-    loadGameTimerXID = 0;
+    g_source_remove(loadGameTimerTag);
+    loadGameTimerTag = 0;
     AutoPlayGameLoop();
 }
 
 void
 StartLoadGameTimer (long millisec)
 {
-    loadGameTimerXID =
-      XtAppAddTimeOut(appContext, millisec,
-                     (XtTimerCallbackProc) LoadGameTimerCallback,
-                     (XtPointer) 0);
+    loadGameTimerTag =
+       g_timeout_add( millisec, (GSourceFunc) LoadGameTimerCallback, NULL);
 }
 
-XtIntervalId analysisClockXID = 0;
+guint analysisClockTag = 0;
 
 void
-AnalysisClockCallback (XtPointer arg, XtIntervalId *id)
+AnalysisClockCallback(gpointer data)
 {
     if (gameMode == AnalyzeMode || gameMode == AnalyzeFile
          || appData.icsEngineAnalyze) { // [DM]
        AnalysisPeriodicEvent(0);
-       StartAnalysisClock();
     }
 }
 
 void
 StartAnalysisClock ()
 {
-    analysisClockXID =
-      XtAppAddTimeOut(appContext, 2000,
-                     (XtTimerCallbackProc) AnalysisClockCallback,
-                     (XtPointer) 0);
+    analysisClockTag =
+       g_timeout_add( 2000,(GSourceFunc) AnalysisClockCallback, NULL);
 }
 
-XtIntervalId clockTimerXID = 0;
+guint clockTimerTag = 0;
 
 int
 ClockTimerRunning ()
 {
-    return clockTimerXID != 0;
+    return clockTimerTag != 0;
 }
 
 int
 StopClockTimer ()
 {
-    if (clockTimerXID != 0) {
-       XtRemoveTimeOut(clockTimerXID);
-       clockTimerXID = 0;
+    if (clockTimerTag != 0)
+    {
+       g_source_remove(clockTimerTag);
+       clockTimerTag = 0;
        return TRUE;
     } else {
        return FALSE;
@@ -233,19 +221,19 @@ StopClockTimer ()
 }
 
 void
-ClockTimerCallback (XtPointer arg, XtIntervalId *id)
+ClockTimerCallback(gpointer data)
 {
-    clockTimerXID = 0;
+    /* remove timer */
+    g_source_remove(clockTimerTag);
+    clockTimerTag = 0;
+
     DecrementClocks();
 }
 
 void
 StartClockTimer (long millisec)
 {
-    clockTimerXID =
-      XtAppAddTimeOut(appContext, millisec,
-                     (XtTimerCallbackProc) ClockTimerCallback,
-                     (XtPointer) 0);
+    clockTimerTag = g_timeout_add(millisec,(GSourceFunc) ClockTimerCallback,NULL);
 }