tUse new API for GTK timeouts - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 5e1b6dffc76d08b7c479d420b46a66711538632d
 (DIR) parent 54b9e74c81e0dc4bb786f7de94d96bda1569e101
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Wed, 11 Nov 2020 15:38:06 -0800
       
       Use new API for GTK timeouts
       
       Don't use the deprecated gtk_timeout_(add|remove)
       functions to add timeouts to the main event loop;
       use the new equivalent glib functions.
       
       Diffstat:
         M src/gtkport/gtkport.c               |      75 +------------------------------
         M src/gtkport/gtkport.h               |       3 ---
         M src/serverside.c                    |       6 +++---
       
       3 files changed, 4 insertions(+), 80 deletions(-)
       ---
 (DIR) diff --git a/src/gtkport/gtkport.c b/src/gtkport/gtkport.c
       t@@ -245,15 +245,6 @@ struct _GdkInput {
          gpointer data;
        };
        
       -typedef struct _GtkTimeout GtkTimeout;
       -
       -struct _GtkTimeout {
       -  guint32 interval;
       -  GtkFunction function;
       -  gpointer data;
       -  guint id;
       -};
       -
        struct _OurSource {
          guint id;     /* Unique identifier */
        
       t@@ -654,7 +645,6 @@ static HFONT urlFont;
        static GSList *WindowList = NULL;
        static GSList *GdkInputs = NULL;
        static GSList *OurSources = NULL;
       -static GSList *GtkTimeouts = NULL;
        static HWND TopLevel = NULL;
        
        static WNDPROC wpOrigEntryProc, wpOrigTextProc;
       t@@ -709,19 +699,7 @@ static void DispatchTimeoutEvent(UINT id)
        {
          GSList *list;
          OurSource *s;
       -  GtkTimeout *timeout;
       -
       -  for (list = GtkTimeouts; list; list = g_slist_next(list)) {
       -    timeout = (GtkTimeout *)list->data;
       -    if (timeout->id == id) {
       -      if (timeout->function) {
       -        if (!(*timeout->function) (timeout->data)) {
       -          gtk_timeout_remove(id);
       -        }
       -      }
       -      break;
       -    }
       -  }
       +
          for (list = OurSources; list; list = g_slist_next(list)) {
            s = (OurSource *)list->data;
            if (s->id == id) {
       t@@ -5431,57 +5409,6 @@ gboolean dp_g_source_remove(guint tag)
          return TRUE;
        }
        
       -guint gtk_timeout_add(guint32 interval, GtkFunction function,
       -                      gpointer data)
       -{
       -  GtkTimeout *timeout;
       -  GSList *list;
       -  guint id = 1;
       -
       -  /* Get an unused ID */
       -  list = GtkTimeouts;
       -  while (list) {
       -    timeout = (GtkTimeout *)list->data;
       -    if (timeout->id == id) {
       -      id++;
       -      list = GtkTimeouts;
       -    } else {
       -      list = g_slist_next(list);
       -    }
       -  }
       -
       -  timeout = g_new(GtkTimeout, 1);
       -  timeout->interval = interval;
       -  timeout->function = function;
       -  timeout->data = data;
       -
       -  timeout->id = SetTimer(TopLevel, id, interval, NULL);
       -  if (timeout->id == 0) {
       -    g_warning("Failed to create timer!");
       -  }
       -
       -  GtkTimeouts = g_slist_append(GtkTimeouts, timeout);
       -  return timeout->id;
       -}
       -
       -void gtk_timeout_remove(guint timeout_handler_id)
       -{
       -  GSList *list;
       -  GtkTimeout *timeout;
       -
       -  for (list = GtkTimeouts; list; list = g_slist_next(list)) {
       -    timeout = (GtkTimeout *)list->data;
       -    if (timeout->id == timeout_handler_id) {
       -      if (KillTimer(TopLevel, timeout->id) == 0) {
       -        g_warning("Failed to kill timer!");
       -      }
       -      GtkTimeouts = g_slist_remove(GtkTimeouts, timeout);
       -      g_free(timeout);
       -      break;
       -    }
       -  }
       -}
       -
        GtkWidget *NewStockButton(const gchar *label, GtkAccelGroup *accel_group)
        {
          return gtk_button_new_with_label(_(label));
 (DIR) diff --git a/src/gtkport/gtkport.h b/src/gtkport/gtkport.h
       t@@ -688,9 +688,6 @@ GtkWidget *gtk_progress_bar_new();
        void gtk_progress_bar_set_orientation(GtkProgressBar *pbar,
                                              GtkProgressBarOrientation orientation);
        void gtk_progress_bar_update(GtkProgressBar *pbar, gfloat percentage);
       -guint gtk_timeout_add(guint32 interval, GtkFunction function,
       -                      gpointer data);
       -void gtk_timeout_remove(guint timeout_handler_id);
        guint gtk_main_level(void);
        GtkObject *GtkNewObject(GtkClass *klass);
        BOOL GetTextSize(HWND hWnd, char *text, LPSIZE lpSize, HFONT hFont);
 (DIR) diff --git a/src/serverside.c b/src/serverside.c
       t@@ -1369,7 +1369,7 @@ static void GuiSetTimeouts(void);
        static time_t NextTimeout = 0;
        static guint TimeoutTag = 0;
        
       -static gint GuiDoTimeouts(gpointer data)
       +static gboolean GuiDoTimeouts(gpointer data)
        {
          /* Forget the TimeoutTag so that GuiSetTimeouts doesn't delete it -
           * it'll be deleted automatically anyway when we return FALSE */
       t@@ -1390,10 +1390,10 @@ void GuiSetTimeouts(void)
          MinTimeout = GetMinimumTimeout(FirstServer);
          if (TimeNow + MinTimeout < NextTimeout || NextTimeout < TimeNow) {
            if (TimeoutTag > 0)
       -      gtk_timeout_remove(TimeoutTag);
       +      dp_g_source_remove(TimeoutTag);
            TimeoutTag = 0;
            if (MinTimeout > 0) {
       -      TimeoutTag = gtk_timeout_add(MinTimeout * 1000, GuiDoTimeouts, NULL);
       +      TimeoutTag = dp_g_timeout_add(MinTimeout * 1000, GuiDoTimeouts, NULL);
              NextTimeout = TimeNow + MinTimeout;
            }
          }