From 9a751a95e3f1f038c8a40c0e6fd4038d395ce18a Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sun, 30 Mar 2014 20:36:47 -0400 Subject: [PATCH] idle-monitor: Rearrange code to make it a cleaner split We're going to push this to be subclasses soon. --- src/core/meta-idle-monitor.c | 48 +++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/core/meta-idle-monitor.c b/src/core/meta-idle-monitor.c index 4f853ea1b..baadaf068 100644 --- a/src/core/meta-idle-monitor.c +++ b/src/core/meta-idle-monitor.c @@ -96,15 +96,6 @@ G_DEFINE_TYPE (MetaIdleMonitor, meta_idle_monitor, G_TYPE_OBJECT) static MetaIdleMonitor *device_monitors[256]; static int device_id_max; -static gint64 -_xsyncvalue_to_int64 (XSyncValue value) -{ - return ((guint64) XSyncValueHigh32 (value)) << 32 - | (guint64) XSyncValueLow32 (value); -} - -#define GUINT64_TO_XSYNCVALUE(value, ret) XSyncIntsToValue (ret, (value) & 0xFFFFFFFF, ((guint64)(value)) >> 32) - static void fire_watch (MetaIdleMonitorWatch *watch) { @@ -133,6 +124,15 @@ fire_watch (MetaIdleMonitorWatch *watch) g_object_unref (monitor); } +static gint64 +_xsyncvalue_to_int64 (XSyncValue value) +{ + return ((guint64) XSyncValueHigh32 (value)) << 32 + | (guint64) XSyncValueLow32 (value); +} + +#define GUINT64_TO_XSYNCVALUE(value, ret) XSyncIntsToValue (ret, (value) & 0xFFFFFFFF, ((guint64)(value)) >> 32) + static XSyncAlarm _xsync_alarm_set (MetaIdleMonitor *monitor, XSyncTestType test_type, @@ -659,6 +659,23 @@ meta_idle_monitor_remove_watch (MetaIdleMonitor *monitor, g_object_unref (monitor); } +static gint64 +meta_idle_monitor_get_idletime_wayland (MetaIdleMonitor *monitor) +{ + return (g_get_monotonic_time () - monitor->last_event_time) / 1000; +} + +static gint64 +meta_idle_monitor_get_idletime_x11 (MetaIdleMonitor *monitor) +{ + XSyncValue value; + + if (!XSyncQueryCounter (monitor->display, monitor->counter, &value)) + return -1; + + return _xsyncvalue_to_int64 (value); +} + /** * meta_idle_monitor_get_idletime: * @monitor: A #MetaIdleMonitor @@ -668,19 +685,10 @@ meta_idle_monitor_remove_watch (MetaIdleMonitor *monitor, gint64 meta_idle_monitor_get_idletime (MetaIdleMonitor *monitor) { - XSyncValue value; - if (meta_is_wayland_compositor ()) - { - return (g_get_monotonic_time () - monitor->last_event_time) / 1000; - } + return meta_idle_monitor_get_idletime_wayland (monitor); else - { - if (!XSyncQueryCounter (monitor->display, monitor->counter, &value)) - return -1; - - return _xsyncvalue_to_int64 (value); - } + return meta_idle_monitor_get_idletime_x11 (monitor); } typedef struct {