[gnome-desktop/gnome-3-8] idle-monitor: Refactor code a bit



commit 1a439b1d7a8f03bd4ef0a5e7f9782d8442d07d92
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Mar 24 19:56:09 2013 -0400

    idle-monitor: Refactor code a bit
    
    Merge two similar methods.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696522

 libgnome-desktop/gnome-idle-monitor.c |   54 ++++++++++++++++++++-------------
 1 files changed, 33 insertions(+), 21 deletions(-)
---
diff --git a/libgnome-desktop/gnome-idle-monitor.c b/libgnome-desktop/gnome-idle-monitor.c
index 5490c3a..f62be0f 100644
--- a/libgnome-desktop/gnome-idle-monitor.c
+++ b/libgnome-desktop/gnome-idle-monitor.c
@@ -467,6 +467,29 @@ gnome_idle_monitor_new_for_device (GdkDevice  *device)
                                                   "device", device, NULL));
 }
 
+static GnomeIdleMonitorWatch *
+make_watch (GnomeIdleMonitor          *monitor,
+           XSyncAlarm                 xalarm,
+           GnomeIdleMonitorWatchFunc  callback,
+           gpointer                   user_data,
+           GDestroyNotify             notify)
+{
+       GnomeIdleMonitorWatch *watch;
+
+       watch = g_slice_new0 (GnomeIdleMonitorWatch);
+       watch->monitor = monitor;
+       watch->id = get_next_watch_serial ();
+       watch->callback = callback;
+       watch->user_data = user_data;
+       watch->notify = notify;
+       watch->xalarm = xalarm;
+
+       g_hash_table_insert (monitor->priv->watches,
+                            GUINT_TO_POINTER (watch->id),
+                            watch);
+       return watch;
+}
+
 /**
  * gnome_idle_monitor_add_idle_watch:
  * @monitor: A #GnomeIdleMonitor
@@ -500,20 +523,15 @@ gnome_idle_monitor_add_idle_watch (GnomeIdleMonitor              *monitor,
 
        g_return_val_if_fail (GNOME_IS_IDLE_MONITOR (monitor), 0);
 
-       watch = g_slice_new0 (GnomeIdleMonitorWatch);
-       watch->monitor = monitor;
-       watch->id = get_next_watch_serial ();
-       watch->callback = callback;
-       watch->user_data = user_data;
-       watch->notify = notify;
-       watch->xalarm = _xsync_alarm_set (monitor, XSyncPositiveTransition, interval_msec, TRUE);
+       watch = make_watch (monitor,
+                           _xsync_alarm_set (monitor, XSyncPositiveTransition, interval_msec, TRUE),
+                           callback,
+                           user_data,
+                           notify);
 
        g_hash_table_add (monitor->priv->alarms,
                          (gpointer) watch->xalarm);
 
-       g_hash_table_insert (monitor->priv->watches,
-                            GUINT_TO_POINTER (watch->id),
-                            watch);
        return watch->id;
 }
 
@@ -543,21 +561,15 @@ gnome_idle_monitor_add_user_active_watch (GnomeIdleMonitor          *monitor,
 
        g_return_val_if_fail (GNOME_IS_IDLE_MONITOR (monitor), 0);
 
-       watch = g_slice_new0 (GnomeIdleMonitorWatch);
-       watch->monitor = monitor;
-       watch->id = get_next_watch_serial ();
-       watch->callback = callback;
-       watch->user_data = user_data;
-       watch->notify = notify;
-       watch->xalarm = monitor->priv->user_active_alarm;
-
        set_alarm_enabled (monitor->priv->display,
                           monitor->priv->user_active_alarm,
                           TRUE);
 
-       g_hash_table_insert (monitor->priv->watches,
-                            GUINT_TO_POINTER (watch->id),
-                            watch);
+       watch = make_watch (monitor,
+                           monitor->priv->user_active_alarm,
+                           callback,
+                           user_data,
+                           notify);
 
        return watch->id;
 }


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