[gnome-desktop] idle-monitor: Use an incrementing watch ID for the active alarm as well



commit 7baf58512cf488d8544e4ddab478b92c324949e2
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Mar 24 19:51:09 2013 -0400

    idle-monitor: Use an incrementing watch ID for the active alarm as well
    
    This makes sure that:
    
        add_user_active_alarm (callback1);
        add_user_active_alarm (callback2);
    
    doesn't remove callback1 from getting an alarm, as we won't overwrite
    the alarm IDs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696522

 libgnome-desktop/gnome-idle-monitor.c |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/libgnome-desktop/gnome-idle-monitor.c b/libgnome-desktop/gnome-idle-monitor.c
index 0a4a8bb..ec9ac1d 100644
--- a/libgnome-desktop/gnome-idle-monitor.c
+++ b/libgnome-desktop/gnome-idle-monitor.c
@@ -36,8 +36,6 @@
 
 #define GNOME_IDLE_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNOME_TYPE_IDLE_MONITOR, 
GnomeIdleMonitorPrivate))
 
-#define USER_ACTIVE_WATCH_ID 1
-
 G_STATIC_ASSERT(sizeof(unsigned long) == sizeof(gpointer));
 
 struct _GnomeIdleMonitorPrivate
@@ -150,6 +148,10 @@ fire_watch (gpointer data,
                                 watch->id,
                                 watch->user_data);
        }
+
+       if (watch->xalarm == watch->monitor->priv->user_active_alarm) {
+               gnome_idle_monitor_remove_watch (watch->monitor, watch->id);
+       }
 }
 
 static void
@@ -247,7 +249,7 @@ find_idletime_counter (GnomeIdleMonitor *monitor)
 static guint32
 get_next_watch_serial (void)
 {
-       static guint32 serial = USER_ACTIVE_WATCH_ID;
+       static guint32 serial = 0;
        g_atomic_int_inc (&serial);
        return serial;
 }
@@ -255,17 +257,21 @@ get_next_watch_serial (void)
 static void
 idle_monitor_watch_free (GnomeIdleMonitorWatch *watch)
 {
+       GnomeIdleMonitor *monitor;
+
        if (watch == NULL) {
                return;
        }
 
+       monitor = watch->monitor;
+
        if (watch->notify != NULL) {
                watch->notify (watch->user_data);
        }
 
-       if (watch->id != USER_ACTIVE_WATCH_ID) {
-               XSyncDestroyAlarm (watch->monitor->priv->display, watch->xalarm);
-               g_hash_table_remove (watch->monitor->priv->alarms, (gpointer) watch->xalarm);
+       if (watch->xalarm != monitor->priv->user_active_alarm) {
+               XSyncDestroyAlarm (monitor->priv->display, watch->xalarm);
+               g_hash_table_remove (monitor->priv->alarms, (gpointer) watch->xalarm);
        }
 
        g_slice_free (GnomeIdleMonitorWatch, watch);
@@ -536,7 +542,7 @@ gnome_idle_monitor_add_user_active_watch (GnomeIdleMonitor          *monitor,
 
        watch = g_slice_new0 (GnomeIdleMonitorWatch);
        watch->monitor = monitor;
-       watch->id = USER_ACTIVE_WATCH_ID;
+       watch->id = get_next_watch_serial ();
        watch->callback = callback;
        watch->user_data = user_data;
        watch->notify = notify;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]