[mutter/wayland] idle-monitor: Make the rest of the implementation-specific fields private



commit f842ea6d15d9036cc4f482aa7c00530d0fdc1827
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Mar 30 22:59:46 2014 -0400

    idle-monitor: Make the rest of the implementation-specific fields private

 src/core/meta-idle-monitor-native.c  |   18 +++++++---
 src/core/meta-idle-monitor-private.h |   12 +------
 src/core/meta-idle-monitor-xsync.c   |   58 ++++++++++++++++++----------------
 3 files changed, 45 insertions(+), 43 deletions(-)
---
diff --git a/src/core/meta-idle-monitor-native.c b/src/core/meta-idle-monitor-native.c
index a2c5c3a..75b4e5a 100644
--- a/src/core/meta-idle-monitor-native.c
+++ b/src/core/meta-idle-monitor-native.c
@@ -33,6 +33,8 @@
 struct _MetaIdleMonitorNative
 {
   MetaIdleMonitor parent;
+
+  guint64 last_event_time;
 };
 
 struct _MetaIdleMonitorNativeClass
@@ -51,7 +53,9 @@ G_DEFINE_TYPE (MetaIdleMonitorNative, meta_idle_monitor_native, META_TYPE_IDLE_M
 static gint64
 meta_idle_monitor_native_get_idletime (MetaIdleMonitor *monitor)
 {
-  return (g_get_monotonic_time () - monitor->last_event_time) / 1000;
+  MetaIdleMonitorNative *monitor_native = META_IDLE_MONITOR_NATIVE (monitor);
+
+  return (g_get_monotonic_time () - monitor_native->last_event_time) / 1000;
 }
 
 static guint32
@@ -116,6 +120,7 @@ meta_idle_monitor_native_make_watch (MetaIdleMonitor           *monitor,
 {
   MetaIdleMonitorWatchNative *watch_native;
   MetaIdleMonitorWatch *watch;
+  MetaIdleMonitorNative *monitor_native = META_IDLE_MONITOR_NATIVE (monitor);
 
   watch_native = g_slice_new0 (MetaIdleMonitorWatchNative);
   watch = (MetaIdleMonitorWatch *) watch_native;
@@ -133,7 +138,7 @@ meta_idle_monitor_native_make_watch (MetaIdleMonitor           *monitor,
       GSource *source = g_source_new (&native_source_funcs, sizeof (GSource));
 
       g_source_set_callback (source, NULL, watch, NULL);
-      g_source_set_ready_time (source, monitor->last_event_time + timeout_msec * 1000);
+      g_source_set_ready_time (source, monitor_native->last_event_time + timeout_msec * 1000);
       g_source_attach (source, NULL);
       g_source_unref (source);
 
@@ -161,7 +166,7 @@ meta_idle_monitor_native_init (MetaIdleMonitorNative *monitor_native)
 }
 
 typedef struct {
-  MetaIdleMonitor *monitor;
+  MetaIdleMonitorNative *monitor_native;
   GList *fired_watches;
 } CheckNativeClosure;
 
@@ -183,7 +188,7 @@ check_native_watch (gpointer key,
   else
     {
       g_source_set_ready_time (watch_native->timeout_source,
-                               closure->monitor->last_event_time +
+                               closure->monitor_native->last_event_time +
                                watch->timeout_msec * 1000);
       steal = FALSE;
     }
@@ -201,11 +206,12 @@ fire_native_watch (gpointer watch,
 void
 meta_idle_monitor_native_reset_idletime (MetaIdleMonitor *monitor)
 {
+  MetaIdleMonitorNative *monitor_native = META_IDLE_MONITOR_NATIVE (monitor);
   CheckNativeClosure closure;
 
-  monitor->last_event_time = g_get_monotonic_time ();
+  monitor_native->last_event_time = g_get_monotonic_time ();
 
-  closure.monitor = monitor;
+  closure.monitor_native = monitor_native;
   closure.fired_watches = NULL;
   g_hash_table_foreach_steal (monitor->watches, check_native_watch, &closure);
 
diff --git a/src/core/meta-idle-monitor-private.h b/src/core/meta-idle-monitor-private.h
index 8508462..ea414e1 100644
--- a/src/core/meta-idle-monitor-private.h
+++ b/src/core/meta-idle-monitor-private.h
@@ -44,16 +44,8 @@ struct _MetaIdleMonitor
 {
   GObject parent_instance;
 
-  GHashTable  *watches;
-  int          device_id;
-
-  /* X11 implementation */
-  Display     *display;
-  XSyncCounter counter;
-  XSyncAlarm   user_active_alarm;
-
-  /* Wayland implementation */
-  guint64      last_event_time;
+  GHashTable *watches;
+  int device_id;
 };
 
 struct _MetaIdleMonitorClass
diff --git a/src/core/meta-idle-monitor-xsync.c b/src/core/meta-idle-monitor-xsync.c
index df04a12..25338a7 100644
--- a/src/core/meta-idle-monitor-xsync.c
+++ b/src/core/meta-idle-monitor-xsync.c
@@ -34,7 +34,10 @@ struct _MetaIdleMonitorXSync
 {
   MetaIdleMonitor parent;
 
-  GHashTable *alarms;
+  GHashTable  *alarms;
+  Display     *display;
+  XSyncCounter counter;
+  XSyncAlarm   user_active_alarm;
 };
 
 struct _MetaIdleMonitorXSyncClass
@@ -60,7 +63,7 @@ _xsyncvalue_to_int64 (XSyncValue value)
 #define GUINT64_TO_XSYNCVALUE(value, ret) XSyncIntsToValue (ret, (value) & 0xFFFFFFFF, ((guint64)(value)) >> 
32)
 
 static XSyncAlarm
-_xsync_alarm_set (MetaIdleMonitor      *monitor,
+_xsync_alarm_set (MetaIdleMonitorXSync *monitor_xsync,
                  XSyncTestType          test_type,
                  guint64                interval,
                  gboolean               want_events)
@@ -73,14 +76,14 @@ _xsync_alarm_set (MetaIdleMonitor   *monitor,
     XSyncCAValue | XSyncCADelta | XSyncCAEvents;
 
   XSyncIntToValue (&delta, 0);
-  attr.trigger.counter = monitor->counter;
+  attr.trigger.counter = monitor_xsync->counter;
   attr.trigger.value_type = XSyncAbsolute;
   attr.delta = delta;
   attr.events = want_events;
 
   GUINT64_TO_XSYNCVALUE (interval, &attr.trigger.wait_value);
   attr.trigger.test_type = test_type;
-  return XSyncCreateAlarm (monitor->display, flags, &attr);
+  return XSyncCreateAlarm (monitor_xsync->display, flags, &attr);
 }
 
 static void
@@ -129,8 +132,9 @@ counter_name_for_device (int device_id)
 }
 
 static XSyncCounter
-find_idletime_counter (MetaIdleMonitor *monitor)
+find_idletime_counter (MetaIdleMonitorXSync *monitor_xsync)
 {
+  MetaIdleMonitor *monitor = META_IDLE_MONITOR (monitor_xsync);
   int                i;
   int                ncounters;
   XSyncSystemCounter *counters;
@@ -138,7 +142,7 @@ find_idletime_counter (MetaIdleMonitor *monitor)
   char               *counter_name;
 
   counter_name = counter_name_for_device (monitor->device_id);
-  counters = XSyncListSystemCounters (monitor->display, &ncounters);
+  counters = XSyncListSystemCounters (monitor_xsync->display, &ncounters);
   for (i = 0; i < ncounters; i++)
     {
       if (counters[i].name != NULL && strcmp (counters[i].name, counter_name) == 0)
@@ -154,29 +158,28 @@ find_idletime_counter (MetaIdleMonitor *monitor)
 }
 
 static void
-init_xsync (MetaIdleMonitor *monitor)
+init_xsync (MetaIdleMonitorXSync *monitor_xsync)
 {
-  monitor->counter = find_idletime_counter (monitor);
+  monitor_xsync->counter = find_idletime_counter (monitor_xsync);
   /* IDLETIME counter not found? */
-  if (monitor->counter == None)
+  if (monitor_xsync->counter == None)
     {
       g_warning ("IDLETIME counter not found\n");
       return;
     }
 
-  monitor->user_active_alarm = _xsync_alarm_set (monitor, XSyncNegativeTransition, 1, FALSE);
+  monitor_xsync->user_active_alarm = _xsync_alarm_set (monitor_xsync, XSyncNegativeTransition, 1, FALSE);
 }
 
 static void
 meta_idle_monitor_xsync_dispose (GObject *object)
 {
   MetaIdleMonitorXSync *monitor_xsync = META_IDLE_MONITOR_XSYNC (object);
-  MetaIdleMonitor *monitor = META_IDLE_MONITOR (monitor_xsync);
 
-  if (monitor->user_active_alarm != None)
+  if (monitor_xsync->user_active_alarm != None)
     {
-      XSyncDestroyAlarm (monitor->display, monitor->user_active_alarm);
-      monitor->user_active_alarm = None;
+      XSyncDestroyAlarm (monitor_xsync->display, monitor_xsync->user_active_alarm);
+      monitor_xsync->user_active_alarm = None;
     }
 
   g_clear_pointer (&monitor_xsync->alarms, g_hash_table_destroy);
@@ -187,12 +190,12 @@ meta_idle_monitor_xsync_dispose (GObject *object)
 static void
 meta_idle_monitor_xsync_constructed (GObject *object)
 {
-  MetaIdleMonitor *monitor = META_IDLE_MONITOR (object);
+  MetaIdleMonitorXSync *monitor_xsync = META_IDLE_MONITOR_XSYNC (object);
 
   g_assert (!meta_is_wayland_compositor ());
 
-  monitor->display = meta_get_display ()->xdisplay;
-  init_xsync (monitor);
+  monitor_xsync->display = meta_get_display ()->xdisplay;
+  init_xsync (monitor_xsync);
 
   G_OBJECT_CLASS (meta_idle_monitor_xsync_parent_class)->constructed (object);
 }
@@ -200,9 +203,10 @@ meta_idle_monitor_xsync_constructed (GObject *object)
 static gint64
 meta_idle_monitor_xsync_get_idletime (MetaIdleMonitor *monitor)
 {
+  MetaIdleMonitorXSync *monitor_xsync = META_IDLE_MONITOR_XSYNC (monitor);
   XSyncValue value;
 
-  if (!XSyncQueryCounter (monitor->display, monitor->counter, &value))
+  if (!XSyncQueryCounter (monitor_xsync->display, monitor_xsync->counter, &value))
     return -1;
 
   return _xsyncvalue_to_int64 (value);
@@ -246,10 +250,10 @@ free_watch (gpointer data)
   if (watch->notify != NULL)
     watch->notify (watch->user_data);
 
-  if (watch_xsync->xalarm != monitor->user_active_alarm &&
+  if (watch_xsync->xalarm != monitor_xsync->user_active_alarm &&
       watch_xsync->xalarm != None)
     {
-      XSyncDestroyAlarm (monitor->display, watch_xsync->xalarm);
+      XSyncDestroyAlarm (monitor_xsync->display, watch_xsync->xalarm);
       g_hash_table_remove (monitor_xsync->alarms, (gpointer) watch_xsync->xalarm);
     }
 
@@ -278,11 +282,11 @@ meta_idle_monitor_xsync_make_watch (MetaIdleMonitor           *monitor,
   watch->notify = notify;
   watch->timeout_msec = timeout_msec;
 
-  if (monitor->user_active_alarm != None)
+  if (monitor_xsync->user_active_alarm != None)
     {
       if (timeout_msec != 0)
         {
-          watch_xsync->xalarm = _xsync_alarm_set (monitor, XSyncPositiveTransition, timeout_msec, TRUE);
+          watch_xsync->xalarm = _xsync_alarm_set (monitor_xsync, XSyncPositiveTransition, timeout_msec, 
TRUE);
 
           g_hash_table_add (monitor_xsync->alarms, (gpointer) watch_xsync->xalarm);
 
@@ -291,9 +295,9 @@ meta_idle_monitor_xsync_make_watch (MetaIdleMonitor           *monitor,
         }
       else
         {
-          watch_xsync->xalarm = monitor->user_active_alarm;
+          watch_xsync->xalarm = monitor_xsync->user_active_alarm;
 
-          set_alarm_enabled (monitor->display, monitor->user_active_alarm, TRUE);
+          set_alarm_enabled (monitor_xsync->display, monitor_xsync->user_active_alarm, TRUE);
         }
     }
 
@@ -338,16 +342,16 @@ meta_idle_monitor_xsync_handle_xevent (MetaIdleMonitor       *monitor,
 
   has_alarm = FALSE;
 
-  if (alarm == monitor->user_active_alarm)
+  if (alarm == monitor_xsync->user_active_alarm)
     {
-      set_alarm_enabled (monitor->display,
+      set_alarm_enabled (monitor_xsync->display,
                          alarm,
                          FALSE);
       has_alarm = TRUE;
     }
   else if (g_hash_table_contains (monitor_xsync->alarms, (gpointer) alarm))
     {
-      ensure_alarm_rescheduled (monitor->display,
+      ensure_alarm_rescheduled (monitor_xsync->display,
                                 alarm);
       has_alarm = TRUE;
     }


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