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

This commit is contained in:
Jasper St. Pierre 2014-03-30 22:59:46 -04:00
parent 422f2e5fe6
commit f842ea6d15
3 changed files with 45 additions and 43 deletions

View File

@ -33,6 +33,8 @@
struct _MetaIdleMonitorNative struct _MetaIdleMonitorNative
{ {
MetaIdleMonitor parent; MetaIdleMonitor parent;
guint64 last_event_time;
}; };
struct _MetaIdleMonitorNativeClass struct _MetaIdleMonitorNativeClass
@ -51,7 +53,9 @@ G_DEFINE_TYPE (MetaIdleMonitorNative, meta_idle_monitor_native, META_TYPE_IDLE_M
static gint64 static gint64
meta_idle_monitor_native_get_idletime (MetaIdleMonitor *monitor) 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 static guint32
@ -116,6 +120,7 @@ meta_idle_monitor_native_make_watch (MetaIdleMonitor *monitor,
{ {
MetaIdleMonitorWatchNative *watch_native; MetaIdleMonitorWatchNative *watch_native;
MetaIdleMonitorWatch *watch; MetaIdleMonitorWatch *watch;
MetaIdleMonitorNative *monitor_native = META_IDLE_MONITOR_NATIVE (monitor);
watch_native = g_slice_new0 (MetaIdleMonitorWatchNative); watch_native = g_slice_new0 (MetaIdleMonitorWatchNative);
watch = (MetaIdleMonitorWatch *) watch_native; 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)); GSource *source = g_source_new (&native_source_funcs, sizeof (GSource));
g_source_set_callback (source, NULL, watch, NULL); 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_attach (source, NULL);
g_source_unref (source); g_source_unref (source);
@ -161,7 +166,7 @@ meta_idle_monitor_native_init (MetaIdleMonitorNative *monitor_native)
} }
typedef struct { typedef struct {
MetaIdleMonitor *monitor; MetaIdleMonitorNative *monitor_native;
GList *fired_watches; GList *fired_watches;
} CheckNativeClosure; } CheckNativeClosure;
@ -183,7 +188,7 @@ check_native_watch (gpointer key,
else else
{ {
g_source_set_ready_time (watch_native->timeout_source, g_source_set_ready_time (watch_native->timeout_source,
closure->monitor->last_event_time + closure->monitor_native->last_event_time +
watch->timeout_msec * 1000); watch->timeout_msec * 1000);
steal = FALSE; steal = FALSE;
} }
@ -201,11 +206,12 @@ fire_native_watch (gpointer watch,
void void
meta_idle_monitor_native_reset_idletime (MetaIdleMonitor *monitor) meta_idle_monitor_native_reset_idletime (MetaIdleMonitor *monitor)
{ {
MetaIdleMonitorNative *monitor_native = META_IDLE_MONITOR_NATIVE (monitor);
CheckNativeClosure closure; 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; closure.fired_watches = NULL;
g_hash_table_foreach_steal (monitor->watches, check_native_watch, &closure); g_hash_table_foreach_steal (monitor->watches, check_native_watch, &closure);

View File

@ -44,16 +44,8 @@ struct _MetaIdleMonitor
{ {
GObject parent_instance; GObject parent_instance;
GHashTable *watches; GHashTable *watches;
int device_id; int device_id;
/* X11 implementation */
Display *display;
XSyncCounter counter;
XSyncAlarm user_active_alarm;
/* Wayland implementation */
guint64 last_event_time;
}; };
struct _MetaIdleMonitorClass struct _MetaIdleMonitorClass

View File

@ -34,7 +34,10 @@ struct _MetaIdleMonitorXSync
{ {
MetaIdleMonitor parent; MetaIdleMonitor parent;
GHashTable *alarms; GHashTable *alarms;
Display *display;
XSyncCounter counter;
XSyncAlarm user_active_alarm;
}; };
struct _MetaIdleMonitorXSyncClass struct _MetaIdleMonitorXSyncClass
@ -60,7 +63,7 @@ _xsyncvalue_to_int64 (XSyncValue value)
#define GUINT64_TO_XSYNCVALUE(value, ret) XSyncIntsToValue (ret, (value) & 0xFFFFFFFF, ((guint64)(value)) >> 32) #define GUINT64_TO_XSYNCVALUE(value, ret) XSyncIntsToValue (ret, (value) & 0xFFFFFFFF, ((guint64)(value)) >> 32)
static XSyncAlarm static XSyncAlarm
_xsync_alarm_set (MetaIdleMonitor *monitor, _xsync_alarm_set (MetaIdleMonitorXSync *monitor_xsync,
XSyncTestType test_type, XSyncTestType test_type,
guint64 interval, guint64 interval,
gboolean want_events) gboolean want_events)
@ -73,14 +76,14 @@ _xsync_alarm_set (MetaIdleMonitor *monitor,
XSyncCAValue | XSyncCADelta | XSyncCAEvents; XSyncCAValue | XSyncCADelta | XSyncCAEvents;
XSyncIntToValue (&delta, 0); XSyncIntToValue (&delta, 0);
attr.trigger.counter = monitor->counter; attr.trigger.counter = monitor_xsync->counter;
attr.trigger.value_type = XSyncAbsolute; attr.trigger.value_type = XSyncAbsolute;
attr.delta = delta; attr.delta = delta;
attr.events = want_events; attr.events = want_events;
GUINT64_TO_XSYNCVALUE (interval, &attr.trigger.wait_value); GUINT64_TO_XSYNCVALUE (interval, &attr.trigger.wait_value);
attr.trigger.test_type = test_type; attr.trigger.test_type = test_type;
return XSyncCreateAlarm (monitor->display, flags, &attr); return XSyncCreateAlarm (monitor_xsync->display, flags, &attr);
} }
static void static void
@ -129,8 +132,9 @@ counter_name_for_device (int device_id)
} }
static XSyncCounter static XSyncCounter
find_idletime_counter (MetaIdleMonitor *monitor) find_idletime_counter (MetaIdleMonitorXSync *monitor_xsync)
{ {
MetaIdleMonitor *monitor = META_IDLE_MONITOR (monitor_xsync);
int i; int i;
int ncounters; int ncounters;
XSyncSystemCounter *counters; XSyncSystemCounter *counters;
@ -138,7 +142,7 @@ find_idletime_counter (MetaIdleMonitor *monitor)
char *counter_name; char *counter_name;
counter_name = counter_name_for_device (monitor->device_id); 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++) for (i = 0; i < ncounters; i++)
{ {
if (counters[i].name != NULL && strcmp (counters[i].name, counter_name) == 0) if (counters[i].name != NULL && strcmp (counters[i].name, counter_name) == 0)
@ -154,29 +158,28 @@ find_idletime_counter (MetaIdleMonitor *monitor)
} }
static void 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? */ /* IDLETIME counter not found? */
if (monitor->counter == None) if (monitor_xsync->counter == None)
{ {
g_warning ("IDLETIME counter not found\n"); g_warning ("IDLETIME counter not found\n");
return; 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 static void
meta_idle_monitor_xsync_dispose (GObject *object) meta_idle_monitor_xsync_dispose (GObject *object)
{ {
MetaIdleMonitorXSync *monitor_xsync = META_IDLE_MONITOR_XSYNC (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); XSyncDestroyAlarm (monitor_xsync->display, monitor_xsync->user_active_alarm);
monitor->user_active_alarm = None; monitor_xsync->user_active_alarm = None;
} }
g_clear_pointer (&monitor_xsync->alarms, g_hash_table_destroy); g_clear_pointer (&monitor_xsync->alarms, g_hash_table_destroy);
@ -187,12 +190,12 @@ meta_idle_monitor_xsync_dispose (GObject *object)
static void static void
meta_idle_monitor_xsync_constructed (GObject *object) 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 ()); g_assert (!meta_is_wayland_compositor ());
monitor->display = meta_get_display ()->xdisplay; monitor_xsync->display = meta_get_display ()->xdisplay;
init_xsync (monitor); init_xsync (monitor_xsync);
G_OBJECT_CLASS (meta_idle_monitor_xsync_parent_class)->constructed (object); G_OBJECT_CLASS (meta_idle_monitor_xsync_parent_class)->constructed (object);
} }
@ -200,9 +203,10 @@ meta_idle_monitor_xsync_constructed (GObject *object)
static gint64 static gint64
meta_idle_monitor_xsync_get_idletime (MetaIdleMonitor *monitor) meta_idle_monitor_xsync_get_idletime (MetaIdleMonitor *monitor)
{ {
MetaIdleMonitorXSync *monitor_xsync = META_IDLE_MONITOR_XSYNC (monitor);
XSyncValue value; XSyncValue value;
if (!XSyncQueryCounter (monitor->display, monitor->counter, &value)) if (!XSyncQueryCounter (monitor_xsync->display, monitor_xsync->counter, &value))
return -1; return -1;
return _xsyncvalue_to_int64 (value); return _xsyncvalue_to_int64 (value);
@ -246,10 +250,10 @@ free_watch (gpointer data)
if (watch->notify != NULL) if (watch->notify != NULL)
watch->notify (watch->user_data); 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) 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); 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->notify = notify;
watch->timeout_msec = timeout_msec; watch->timeout_msec = timeout_msec;
if (monitor->user_active_alarm != None) if (monitor_xsync->user_active_alarm != None)
{ {
if (timeout_msec != 0) 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); g_hash_table_add (monitor_xsync->alarms, (gpointer) watch_xsync->xalarm);
@ -291,9 +295,9 @@ meta_idle_monitor_xsync_make_watch (MetaIdleMonitor *monitor,
} }
else 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; 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, alarm,
FALSE); FALSE);
has_alarm = TRUE; has_alarm = TRUE;
} }
else if (g_hash_table_contains (monitor_xsync->alarms, (gpointer) alarm)) else if (g_hash_table_contains (monitor_xsync->alarms, (gpointer) alarm))
{ {
ensure_alarm_rescheduled (monitor->display, ensure_alarm_rescheduled (monitor_xsync->display,
alarm); alarm);
has_alarm = TRUE; has_alarm = TRUE;
} }