idle-monitor: Move watch implementations to be private to the subclass
This commit is contained in:
parent
78457cf7b4
commit
61d8b35254
@ -40,6 +40,12 @@ struct _MetaIdleMonitorNativeClass
|
|||||||
MetaIdleMonitorClass parent_class;
|
MetaIdleMonitorClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MetaIdleMonitorWatch base;
|
||||||
|
|
||||||
|
GSource *timeout_source;
|
||||||
|
} MetaIdleMonitorWatchNative;
|
||||||
|
|
||||||
G_DEFINE_TYPE (MetaIdleMonitorNative, meta_idle_monitor_native, META_TYPE_IDLE_MONITOR)
|
G_DEFINE_TYPE (MetaIdleMonitorNative, meta_idle_monitor_native, META_TYPE_IDLE_MONITOR)
|
||||||
|
|
||||||
static gint64
|
static gint64
|
||||||
@ -61,10 +67,11 @@ native_dispatch_timeout (GSource *source,
|
|||||||
GSourceFunc callback,
|
GSourceFunc callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MetaIdleMonitorWatch *watch = user_data;
|
MetaIdleMonitorWatchNative *watch_native = user_data;
|
||||||
|
MetaIdleMonitorWatch *watch = (MetaIdleMonitorWatch *) watch;
|
||||||
|
|
||||||
_meta_idle_monitor_watch_fire (watch);
|
_meta_idle_monitor_watch_fire (watch);
|
||||||
g_source_set_ready_time (watch->timeout_source, -1);
|
g_source_set_ready_time (watch_native->timeout_source, -1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +82,31 @@ static GSourceFuncs native_source_funcs = {
|
|||||||
NULL, /* finalize */
|
NULL, /* finalize */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_watch (gpointer data)
|
||||||
|
{
|
||||||
|
MetaIdleMonitorWatchNative *watch_native = data;
|
||||||
|
MetaIdleMonitorWatch *watch = (MetaIdleMonitorWatch *) watch_native;
|
||||||
|
MetaIdleMonitor *monitor = watch->monitor;
|
||||||
|
|
||||||
|
g_object_ref (monitor);
|
||||||
|
|
||||||
|
if (watch->idle_source_id)
|
||||||
|
{
|
||||||
|
g_source_remove (watch->idle_source_id);
|
||||||
|
watch->idle_source_id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (watch->notify != NULL)
|
||||||
|
watch->notify (watch->user_data);
|
||||||
|
|
||||||
|
if (watch_native->timeout_source != NULL)
|
||||||
|
g_source_destroy (watch_native->timeout_source);
|
||||||
|
|
||||||
|
g_object_unref (monitor);
|
||||||
|
g_slice_free (MetaIdleMonitorWatchNative, watch_native);
|
||||||
|
}
|
||||||
|
|
||||||
static MetaIdleMonitorWatch *
|
static MetaIdleMonitorWatch *
|
||||||
meta_idle_monitor_native_make_watch (MetaIdleMonitor *monitor,
|
meta_idle_monitor_native_make_watch (MetaIdleMonitor *monitor,
|
||||||
guint64 timeout_msec,
|
guint64 timeout_msec,
|
||||||
@ -82,8 +114,12 @@ meta_idle_monitor_native_make_watch (MetaIdleMonitor *monitor,
|
|||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
GDestroyNotify notify)
|
GDestroyNotify notify)
|
||||||
{
|
{
|
||||||
|
MetaIdleMonitorWatchNative *watch_native;
|
||||||
MetaIdleMonitorWatch *watch;
|
MetaIdleMonitorWatch *watch;
|
||||||
|
|
||||||
|
watch_native = g_slice_new0 (MetaIdleMonitorWatchNative);
|
||||||
|
watch = (MetaIdleMonitorWatch *) watch_native;
|
||||||
|
|
||||||
watch = g_slice_new0 (MetaIdleMonitorWatch);
|
watch = g_slice_new0 (MetaIdleMonitorWatch);
|
||||||
watch->monitor = monitor;
|
watch->monitor = monitor;
|
||||||
watch->id = get_next_watch_serial ();
|
watch->id = get_next_watch_serial ();
|
||||||
@ -101,7 +137,7 @@ meta_idle_monitor_native_make_watch (MetaIdleMonitor *monitor,
|
|||||||
g_source_attach (source, NULL);
|
g_source_attach (source, NULL);
|
||||||
g_source_unref (source);
|
g_source_unref (source);
|
||||||
|
|
||||||
watch->timeout_source = source;
|
watch_native->timeout_source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
return watch;
|
return watch;
|
||||||
@ -117,8 +153,11 @@ meta_idle_monitor_native_class_init (MetaIdleMonitorNativeClass *klass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
meta_idle_monitor_native_init (MetaIdleMonitorNative *monitor)
|
meta_idle_monitor_native_init (MetaIdleMonitorNative *monitor_native)
|
||||||
{
|
{
|
||||||
|
MetaIdleMonitor *monitor = META_IDLE_MONITOR (monitor_native);
|
||||||
|
|
||||||
|
monitor->watches = g_hash_table_new_full (NULL, NULL, NULL, free_watch);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -131,7 +170,8 @@ check_native_watch (gpointer key,
|
|||||||
gpointer value,
|
gpointer value,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MetaIdleMonitorWatch *watch = value;
|
MetaIdleMonitorWatchNative *watch_native = value;
|
||||||
|
MetaIdleMonitorWatch *watch = (MetaIdleMonitorWatch *) watch_native;
|
||||||
CheckNativeClosure *closure = user_data;
|
CheckNativeClosure *closure = user_data;
|
||||||
gboolean steal;
|
gboolean steal;
|
||||||
|
|
||||||
@ -142,7 +182,7 @@ check_native_watch (gpointer key,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_source_set_ready_time (watch->timeout_source,
|
g_source_set_ready_time (watch_native->timeout_source,
|
||||||
closure->monitor->last_event_time +
|
closure->monitor->last_event_time +
|
||||||
watch->timeout_msec * 1000);
|
watch->timeout_msec * 1000);
|
||||||
steal = FALSE;
|
steal = FALSE;
|
||||||
|
@ -37,13 +37,7 @@ typedef struct
|
|||||||
gpointer user_data;
|
gpointer user_data;
|
||||||
GDestroyNotify notify;
|
GDestroyNotify notify;
|
||||||
guint64 timeout_msec;
|
guint64 timeout_msec;
|
||||||
|
|
||||||
/* x11 */
|
|
||||||
XSyncAlarm xalarm;
|
|
||||||
int idle_source_id;
|
int idle_source_id;
|
||||||
|
|
||||||
/* wayland */
|
|
||||||
GSource *timeout_source;
|
|
||||||
} MetaIdleMonitorWatch;
|
} MetaIdleMonitorWatch;
|
||||||
|
|
||||||
struct _MetaIdleMonitor
|
struct _MetaIdleMonitor
|
||||||
|
@ -40,6 +40,12 @@ struct _MetaIdleMonitorXSyncClass
|
|||||||
MetaIdleMonitorClass parent_class;
|
MetaIdleMonitorClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MetaIdleMonitorWatch base;
|
||||||
|
|
||||||
|
XSyncAlarm xalarm;
|
||||||
|
} MetaIdleMonitorWatchXSync;
|
||||||
|
|
||||||
G_DEFINE_TYPE (MetaIdleMonitorXSync, meta_idle_monitor_xsync, META_TYPE_IDLE_MONITOR)
|
G_DEFINE_TYPE (MetaIdleMonitorXSync, meta_idle_monitor_xsync, META_TYPE_IDLE_MONITOR)
|
||||||
|
|
||||||
static gint64
|
static gint64
|
||||||
@ -101,10 +107,11 @@ static void
|
|||||||
check_x11_watch (gpointer data,
|
check_x11_watch (gpointer data,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MetaIdleMonitorWatch *watch = data;
|
MetaIdleMonitorWatchXSync *watch_xsync = data;
|
||||||
|
MetaIdleMonitorWatch *watch = (MetaIdleMonitorWatch *) watch_xsync;
|
||||||
XSyncAlarm alarm = (XSyncAlarm) user_data;
|
XSyncAlarm alarm = (XSyncAlarm) user_data;
|
||||||
|
|
||||||
if (watch->xalarm != alarm)
|
if (watch_xsync->xalarm != alarm)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_meta_idle_monitor_watch_fire (watch);
|
_meta_idle_monitor_watch_fire (watch);
|
||||||
@ -215,6 +222,35 @@ get_next_watch_serial (void)
|
|||||||
return serial;
|
return serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_watch (gpointer data)
|
||||||
|
{
|
||||||
|
MetaIdleMonitorWatchXSync *watch_xsync = data;
|
||||||
|
MetaIdleMonitorWatch *watch = (MetaIdleMonitorWatch *) watch_xsync;
|
||||||
|
MetaIdleMonitor *monitor = watch->monitor;
|
||||||
|
|
||||||
|
g_object_ref (monitor);
|
||||||
|
|
||||||
|
if (watch->idle_source_id)
|
||||||
|
{
|
||||||
|
g_source_remove (watch->idle_source_id);
|
||||||
|
watch->idle_source_id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (watch->notify != NULL)
|
||||||
|
watch->notify (watch->user_data);
|
||||||
|
|
||||||
|
if (watch_xsync->xalarm != monitor->user_active_alarm &&
|
||||||
|
watch_xsync->xalarm != None)
|
||||||
|
{
|
||||||
|
XSyncDestroyAlarm (monitor->display, watch_xsync->xalarm);
|
||||||
|
g_hash_table_remove (monitor->alarms, (gpointer) watch_xsync->xalarm);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (monitor);
|
||||||
|
g_slice_free (MetaIdleMonitorWatchXSync, watch_xsync);
|
||||||
|
}
|
||||||
|
|
||||||
static MetaIdleMonitorWatch *
|
static MetaIdleMonitorWatch *
|
||||||
meta_idle_monitor_xsync_make_watch (MetaIdleMonitor *monitor,
|
meta_idle_monitor_xsync_make_watch (MetaIdleMonitor *monitor,
|
||||||
guint64 timeout_msec,
|
guint64 timeout_msec,
|
||||||
@ -222,9 +258,12 @@ meta_idle_monitor_xsync_make_watch (MetaIdleMonitor *monitor,
|
|||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
GDestroyNotify notify)
|
GDestroyNotify notify)
|
||||||
{
|
{
|
||||||
|
MetaIdleMonitorWatchXSync *watch_xsync;
|
||||||
MetaIdleMonitorWatch *watch;
|
MetaIdleMonitorWatch *watch;
|
||||||
|
|
||||||
watch = g_slice_new0 (MetaIdleMonitorWatch);
|
watch_xsync = g_slice_new0 (MetaIdleMonitorWatchXSync);
|
||||||
|
watch = (MetaIdleMonitorWatch *) watch_xsync;
|
||||||
|
|
||||||
watch->monitor = monitor;
|
watch->monitor = monitor;
|
||||||
watch->id = get_next_watch_serial ();
|
watch->id = get_next_watch_serial ();
|
||||||
watch->callback = callback;
|
watch->callback = callback;
|
||||||
@ -236,16 +275,16 @@ meta_idle_monitor_xsync_make_watch (MetaIdleMonitor *monitor,
|
|||||||
{
|
{
|
||||||
if (timeout_msec != 0)
|
if (timeout_msec != 0)
|
||||||
{
|
{
|
||||||
watch->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->xalarm);
|
g_hash_table_add (monitor->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);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
watch->xalarm = monitor->user_active_alarm;
|
watch_xsync->xalarm = monitor->user_active_alarm;
|
||||||
|
|
||||||
set_alarm_enabled (monitor->display, monitor->user_active_alarm, TRUE);
|
set_alarm_enabled (monitor->display, monitor->user_active_alarm, TRUE);
|
||||||
}
|
}
|
||||||
@ -268,8 +307,11 @@ meta_idle_monitor_xsync_class_init (MetaIdleMonitorXSyncClass *klass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
meta_idle_monitor_xsync_init (MetaIdleMonitorXSync *monitor)
|
meta_idle_monitor_xsync_init (MetaIdleMonitorXSync *monitor_xsync)
|
||||||
{
|
{
|
||||||
|
MetaIdleMonitor *monitor = META_IDLE_MONITOR (monitor_xsync);
|
||||||
|
|
||||||
|
monitor->watches = g_hash_table_new_full (NULL, NULL, NULL, free_watch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -85,40 +85,6 @@ _meta_idle_monitor_watch_fire (MetaIdleMonitorWatch *watch)
|
|||||||
g_object_unref (monitor);
|
g_object_unref (monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
idle_monitor_watch_free (MetaIdleMonitorWatch *watch)
|
|
||||||
{
|
|
||||||
MetaIdleMonitor *monitor;
|
|
||||||
|
|
||||||
if (watch == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
monitor = watch->monitor;
|
|
||||||
g_object_ref (monitor);
|
|
||||||
|
|
||||||
if (watch->idle_source_id)
|
|
||||||
{
|
|
||||||
g_source_remove (watch->idle_source_id);
|
|
||||||
watch->idle_source_id = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (watch->notify != NULL)
|
|
||||||
watch->notify (watch->user_data);
|
|
||||||
|
|
||||||
if (watch->xalarm != monitor->user_active_alarm &&
|
|
||||||
watch->xalarm != None)
|
|
||||||
{
|
|
||||||
XSyncDestroyAlarm (monitor->display, watch->xalarm);
|
|
||||||
g_hash_table_remove (monitor->alarms, (gpointer) watch->xalarm);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (watch->timeout_source != NULL)
|
|
||||||
g_source_destroy (watch->timeout_source);
|
|
||||||
|
|
||||||
g_object_unref (monitor);
|
|
||||||
g_slice_free (MetaIdleMonitorWatch, watch);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
meta_idle_monitor_dispose (GObject *object)
|
meta_idle_monitor_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
@ -193,11 +159,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->watches = g_hash_table_new_full (NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
(GDestroyNotify)idle_monitor_watch_free);
|
|
||||||
|
|
||||||
monitor->alarms = g_hash_table_new (NULL, NULL);
|
monitor->alarms = g_hash_table_new (NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user