idle-monitor: Move the alarms field to the XSync backend

For whatever reason, this hash table was in the generic
implementation section instead of the XSync implementation,
even though it's only used by the XSync implementation.

Use it as a first pass of things to move over.
This commit is contained in:
Jasper St. Pierre 2014-03-30 22:33:49 -04:00
parent 61d8b35254
commit 3961f291e4
3 changed files with 13 additions and 7 deletions

View File

@ -45,7 +45,6 @@ struct _MetaIdleMonitor
GObject parent_instance; GObject parent_instance;
GHashTable *watches; GHashTable *watches;
GHashTable *alarms;
int device_id; int device_id;
/* X11 implementation */ /* X11 implementation */

View File

@ -33,6 +33,8 @@
struct _MetaIdleMonitorXSync struct _MetaIdleMonitorXSync
{ {
MetaIdleMonitor parent; MetaIdleMonitor parent;
GHashTable *alarms;
}; };
struct _MetaIdleMonitorXSyncClass struct _MetaIdleMonitorXSyncClass
@ -168,7 +170,8 @@ init_xsync (MetaIdleMonitor *monitor)
static void static void
meta_idle_monitor_xsync_dispose (GObject *object) meta_idle_monitor_xsync_dispose (GObject *object)
{ {
MetaIdleMonitor *monitor = META_IDLE_MONITOR (object); MetaIdleMonitorXSync *monitor_xsync = META_IDLE_MONITOR_XSYNC (object);
MetaIdleMonitor *monitor = META_IDLE_MONITOR (monitor_xsync);
if (monitor->user_active_alarm != None) if (monitor->user_active_alarm != None)
{ {
@ -176,6 +179,8 @@ meta_idle_monitor_xsync_dispose (GObject *object)
monitor->user_active_alarm = None; monitor->user_active_alarm = None;
} }
g_clear_pointer (&monitor_xsync->alarms, g_hash_table_destroy);
G_OBJECT_CLASS (meta_idle_monitor_xsync_parent_class)->dispose (object); G_OBJECT_CLASS (meta_idle_monitor_xsync_parent_class)->dispose (object);
} }
@ -228,6 +233,7 @@ free_watch (gpointer data)
MetaIdleMonitorWatchXSync *watch_xsync = data; MetaIdleMonitorWatchXSync *watch_xsync = data;
MetaIdleMonitorWatch *watch = (MetaIdleMonitorWatch *) watch_xsync; MetaIdleMonitorWatch *watch = (MetaIdleMonitorWatch *) watch_xsync;
MetaIdleMonitor *monitor = watch->monitor; MetaIdleMonitor *monitor = watch->monitor;
MetaIdleMonitorXSync *monitor_xsync = META_IDLE_MONITOR_XSYNC (monitor);
g_object_ref (monitor); g_object_ref (monitor);
@ -244,7 +250,7 @@ free_watch (gpointer data)
watch_xsync->xalarm != None) watch_xsync->xalarm != None)
{ {
XSyncDestroyAlarm (monitor->display, watch_xsync->xalarm); XSyncDestroyAlarm (monitor->display, watch_xsync->xalarm);
g_hash_table_remove (monitor->alarms, (gpointer) watch_xsync->xalarm); g_hash_table_remove (monitor_xsync->alarms, (gpointer) watch_xsync->xalarm);
} }
g_object_unref (monitor); g_object_unref (monitor);
@ -258,6 +264,7 @@ meta_idle_monitor_xsync_make_watch (MetaIdleMonitor *monitor,
gpointer user_data, gpointer user_data,
GDestroyNotify notify) GDestroyNotify notify)
{ {
MetaIdleMonitorXSync *monitor_xsync = META_IDLE_MONITOR_XSYNC (monitor);
MetaIdleMonitorWatchXSync *watch_xsync; MetaIdleMonitorWatchXSync *watch_xsync;
MetaIdleMonitorWatch *watch; MetaIdleMonitorWatch *watch;
@ -277,7 +284,7 @@ meta_idle_monitor_xsync_make_watch (MetaIdleMonitor *monitor,
{ {
watch_xsync->xalarm = _xsync_alarm_set (monitor, XSyncPositiveTransition, timeout_msec, TRUE); watch_xsync->xalarm = _xsync_alarm_set (monitor, XSyncPositiveTransition, timeout_msec, TRUE);
g_hash_table_add (monitor->alarms, (gpointer) watch_xsync->xalarm); g_hash_table_add (monitor_xsync->alarms, (gpointer) watch_xsync->xalarm);
if (meta_idle_monitor_get_idletime (monitor) > (gint64)timeout_msec) if (meta_idle_monitor_get_idletime (monitor) > (gint64)timeout_msec)
watch->idle_source_id = g_idle_add (fire_watch_idle, watch); watch->idle_source_id = g_idle_add (fire_watch_idle, watch);
@ -312,12 +319,14 @@ meta_idle_monitor_xsync_init (MetaIdleMonitorXSync *monitor_xsync)
MetaIdleMonitor *monitor = META_IDLE_MONITOR (monitor_xsync); MetaIdleMonitor *monitor = META_IDLE_MONITOR (monitor_xsync);
monitor->watches = g_hash_table_new_full (NULL, NULL, NULL, free_watch); monitor->watches = g_hash_table_new_full (NULL, NULL, NULL, free_watch);
monitor_xsync->alarms = g_hash_table_new (NULL, NULL);
} }
void void
meta_idle_monitor_xsync_handle_xevent (MetaIdleMonitor *monitor, meta_idle_monitor_xsync_handle_xevent (MetaIdleMonitor *monitor,
XSyncAlarmNotifyEvent *alarm_event) XSyncAlarmNotifyEvent *alarm_event)
{ {
MetaIdleMonitorXSync *monitor_xsync = META_IDLE_MONITOR_XSYNC (monitor);
XSyncAlarm alarm; XSyncAlarm alarm;
GList *watches; GList *watches;
gboolean has_alarm; gboolean has_alarm;
@ -336,7 +345,7 @@ meta_idle_monitor_xsync_handle_xevent (MetaIdleMonitor *monitor,
FALSE); FALSE);
has_alarm = TRUE; has_alarm = TRUE;
} }
else if (g_hash_table_contains (monitor->alarms, (gpointer) alarm)) else if (g_hash_table_contains (monitor_xsync->alarms, (gpointer) alarm))
{ {
ensure_alarm_rescheduled (monitor->display, ensure_alarm_rescheduled (monitor->display,
alarm); alarm);

View File

@ -91,7 +91,6 @@ meta_idle_monitor_dispose (GObject *object)
MetaIdleMonitor *monitor = META_IDLE_MONITOR (object); MetaIdleMonitor *monitor = META_IDLE_MONITOR (object);
g_clear_pointer (&monitor->watches, g_hash_table_destroy); g_clear_pointer (&monitor->watches, g_hash_table_destroy);
g_clear_pointer (&monitor->alarms, g_hash_table_destroy);
G_OBJECT_CLASS (meta_idle_monitor_parent_class)->dispose (object); G_OBJECT_CLASS (meta_idle_monitor_parent_class)->dispose (object);
} }
@ -159,7 +158,6 @@ meta_idle_monitor_class_init (MetaIdleMonitorClass *klass)
static void static void
meta_idle_monitor_init (MetaIdleMonitor *monitor) meta_idle_monitor_init (MetaIdleMonitor *monitor)
{ {
monitor->alarms = g_hash_table_new (NULL, NULL);
} }
static GType static GType