2013-08-14 06:50:48 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2014-05-02 09:34:02 -04:00
|
|
|
/*
|
2013-08-14 06:50:48 -04:00
|
|
|
* Copyright 2013 Red Hat, Inc.
|
2014-05-02 09:34:02 -04:00
|
|
|
*
|
2013-08-14 06:50:48 -04:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
2014-05-02 09:34:02 -04:00
|
|
|
*
|
2013-08-14 06:50:48 -04:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-11 20:42:06 -05:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2013-08-14 06:50:48 -04:00
|
|
|
*
|
|
|
|
* Adapted from gnome-session/gnome-session/gs-idle-monitor.c and
|
|
|
|
* from gnome-desktop/libgnome-desktop/gnome-idle-monitor.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:idle-monitor
|
|
|
|
* @title: MetaIdleMonitor
|
|
|
|
* @short_description: Mutter idle counter (similar to X's IDLETIME)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/extensions/sync.h>
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/gsm-inhibitor-flag.h"
|
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "backends/meta-idle-monitor-private.h"
|
|
|
|
#include "backends/meta-idle-monitor-dbus.h"
|
|
|
|
#include "clutter/clutter.h"
|
|
|
|
#include "meta/main.h"
|
|
|
|
#include "meta/meta-idle-monitor.h"
|
|
|
|
#include "meta/util.h"
|
2013-08-14 06:50:48 -04:00
|
|
|
|
|
|
|
G_STATIC_ASSERT(sizeof(unsigned long) == sizeof(gpointer));
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2019-10-09 10:03:24 -04:00
|
|
|
PROP_DEVICE,
|
2013-08-14 06:50:48 -04:00
|
|
|
PROP_LAST,
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *obj_props[PROP_LAST];
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaIdleMonitor, meta_idle_monitor, G_TYPE_OBJECT)
|
|
|
|
|
2019-09-16 10:17:48 -04:00
|
|
|
static void
|
|
|
|
meta_idle_monitor_watch_fire (MetaIdleMonitorWatch *watch)
|
2013-08-14 06:50:48 -04:00
|
|
|
{
|
|
|
|
MetaIdleMonitor *monitor;
|
2013-08-26 16:22:08 -04:00
|
|
|
guint id;
|
|
|
|
gboolean is_user_active_watch;
|
2013-08-14 06:50:48 -04:00
|
|
|
|
|
|
|
monitor = watch->monitor;
|
|
|
|
g_object_ref (monitor);
|
|
|
|
|
2019-11-21 18:25:30 -05:00
|
|
|
g_clear_handle_id (&watch->idle_source_id, g_source_remove);
|
2013-09-16 08:27:08 -04:00
|
|
|
|
2013-08-26 16:22:08 -04:00
|
|
|
id = watch->id;
|
|
|
|
is_user_active_watch = (watch->timeout_msec == 0);
|
|
|
|
|
2013-08-14 06:50:48 -04:00
|
|
|
if (watch->callback)
|
2013-08-26 16:22:08 -04:00
|
|
|
watch->callback (monitor, id, watch->user_data);
|
|
|
|
|
|
|
|
if (is_user_active_watch)
|
|
|
|
meta_idle_monitor_remove_watch (monitor, id);
|
2013-08-14 06:50:48 -04:00
|
|
|
|
|
|
|
g_object_unref (monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_idle_monitor_dispose (GObject *object)
|
|
|
|
{
|
2014-03-30 20:52:25 -04:00
|
|
|
MetaIdleMonitor *monitor = META_IDLE_MONITOR (object);
|
2013-08-14 06:50:48 -04:00
|
|
|
|
|
|
|
g_clear_pointer (&monitor->watches, g_hash_table_destroy);
|
2018-03-20 06:45:35 -04:00
|
|
|
g_clear_object (&monitor->session_proxy);
|
2013-08-14 06:50:48 -04:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_idle_monitor_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_idle_monitor_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MetaIdleMonitor *monitor = META_IDLE_MONITOR (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2019-10-09 10:03:24 -04:00
|
|
|
case PROP_DEVICE:
|
|
|
|
g_value_set_object (value, monitor->device);
|
2013-08-14 06:50:48 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_idle_monitor_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MetaIdleMonitor *monitor = META_IDLE_MONITOR (object);
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2019-10-09 10:03:24 -04:00
|
|
|
case PROP_DEVICE:
|
|
|
|
monitor->device = g_value_get_object (value);
|
2013-08-14 06:50:48 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_idle_monitor_class_init (MetaIdleMonitorClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->dispose = meta_idle_monitor_dispose;
|
|
|
|
object_class->get_property = meta_idle_monitor_get_property;
|
|
|
|
object_class->set_property = meta_idle_monitor_set_property;
|
|
|
|
|
|
|
|
/**
|
2019-10-09 10:03:24 -04:00
|
|
|
* MetaIdleMonitor:device:
|
2013-08-14 06:50:48 -04:00
|
|
|
*
|
|
|
|
* The device to listen to idletime on.
|
|
|
|
*/
|
2019-10-09 10:03:24 -04:00
|
|
|
obj_props[PROP_DEVICE] =
|
|
|
|
g_param_spec_object ("device",
|
|
|
|
"Device",
|
|
|
|
"The device to listen to idletime on",
|
|
|
|
CLUTTER_TYPE_INPUT_DEVICE,
|
|
|
|
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_DEVICE, obj_props[PROP_DEVICE]);
|
2013-08-14 06:50:48 -04:00
|
|
|
}
|
|
|
|
|
2018-03-20 05:59:04 -04:00
|
|
|
static void
|
|
|
|
free_watch (gpointer data)
|
|
|
|
{
|
|
|
|
MetaIdleMonitorWatch *watch = (MetaIdleMonitorWatch *) data;
|
|
|
|
MetaIdleMonitor *monitor = watch->monitor;
|
|
|
|
|
|
|
|
g_object_ref (monitor);
|
|
|
|
|
2019-11-21 18:25:30 -05:00
|
|
|
g_clear_handle_id (&watch->idle_source_id, g_source_remove);
|
2018-03-20 05:59:04 -04:00
|
|
|
|
|
|
|
if (watch->notify != NULL)
|
|
|
|
watch->notify (watch->user_data);
|
|
|
|
|
|
|
|
if (watch->timeout_source != NULL)
|
|
|
|
g_source_destroy (watch->timeout_source);
|
|
|
|
|
|
|
|
g_object_unref (monitor);
|
|
|
|
g_slice_free (MetaIdleMonitorWatch, watch);
|
|
|
|
}
|
|
|
|
|
2018-03-20 06:45:35 -04:00
|
|
|
static void
|
|
|
|
update_inhibited_watch (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaIdleMonitor *monitor = user_data;
|
|
|
|
MetaIdleMonitorWatch *watch = value;
|
|
|
|
|
|
|
|
if (!watch->timeout_source)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (monitor->inhibited)
|
|
|
|
{
|
|
|
|
g_source_set_ready_time (watch->timeout_source, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_source_set_ready_time (watch->timeout_source,
|
|
|
|
monitor->last_event_time +
|
|
|
|
watch->timeout_msec * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_inhibited (MetaIdleMonitor *monitor,
|
|
|
|
gboolean inhibited)
|
|
|
|
{
|
|
|
|
if (inhibited == monitor->inhibited)
|
|
|
|
return;
|
|
|
|
|
2019-10-09 04:24:54 -04:00
|
|
|
monitor->inhibited = inhibited;
|
|
|
|
|
2018-03-20 06:45:35 -04:00
|
|
|
g_hash_table_foreach (monitor->watches,
|
|
|
|
update_inhibited_watch,
|
|
|
|
monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_idle_monitor_inhibited_actions_changed (GDBusProxy *session,
|
|
|
|
GVariant *changed,
|
|
|
|
char **invalidated,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaIdleMonitor *monitor = user_data;
|
|
|
|
GVariant *v;
|
|
|
|
|
|
|
|
v = g_variant_lookup_value (changed, "InhibitedActions", G_VARIANT_TYPE_UINT32);
|
|
|
|
if (v)
|
|
|
|
{
|
|
|
|
gboolean inhibited;
|
|
|
|
|
2018-05-16 07:08:54 -04:00
|
|
|
inhibited = !!(g_variant_get_uint32 (v) & GSM_INHIBITOR_FLAG_IDLE);
|
2018-03-20 06:45:35 -04:00
|
|
|
g_variant_unref (v);
|
|
|
|
|
|
|
|
if (!inhibited)
|
|
|
|
monitor->last_event_time = g_get_monotonic_time ();
|
|
|
|
update_inhibited (monitor, inhibited);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 06:50:48 -04:00
|
|
|
static void
|
|
|
|
meta_idle_monitor_init (MetaIdleMonitor *monitor)
|
|
|
|
{
|
2018-03-20 06:45:35 -04:00
|
|
|
GVariant *v;
|
|
|
|
|
2018-03-20 05:59:04 -04:00
|
|
|
monitor->watches = g_hash_table_new_full (NULL, NULL, NULL, free_watch);
|
|
|
|
monitor->last_event_time = g_get_monotonic_time ();
|
2018-03-20 06:45:35 -04:00
|
|
|
|
|
|
|
/* Monitor inhibitors */
|
|
|
|
monitor->session_proxy =
|
|
|
|
g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
|
2018-04-29 16:43:47 -04:00
|
|
|
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
|
|
|
|
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
2018-03-20 06:45:35 -04:00
|
|
|
NULL,
|
|
|
|
"org.gnome.SessionManager",
|
|
|
|
"/org/gnome/SessionManager",
|
|
|
|
"org.gnome.SessionManager",
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (!monitor->session_proxy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_signal_connect (monitor->session_proxy, "g-properties-changed",
|
|
|
|
G_CALLBACK (meta_idle_monitor_inhibited_actions_changed),
|
|
|
|
monitor);
|
|
|
|
|
|
|
|
v = g_dbus_proxy_get_cached_property (monitor->session_proxy,
|
|
|
|
"InhibitedActions");
|
2018-06-14 11:43:27 -04:00
|
|
|
if (v)
|
|
|
|
{
|
2018-05-16 07:08:54 -04:00
|
|
|
monitor->inhibited = !!(g_variant_get_uint32 (v) &
|
|
|
|
GSM_INHIBITOR_FLAG_IDLE);
|
2018-06-14 11:43:27 -04:00
|
|
|
g_variant_unref (v);
|
|
|
|
}
|
2013-08-14 06:50:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_idle_monitor_get_core:
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the #MetaIdleMonitor that tracks the server-global
|
|
|
|
* idletime for all devices. To track device-specific idletime,
|
|
|
|
* use meta_idle_monitor_get_for_device().
|
|
|
|
*/
|
|
|
|
MetaIdleMonitor *
|
|
|
|
meta_idle_monitor_get_core (void)
|
|
|
|
{
|
2014-04-21 19:03:22 -04:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
2019-10-09 10:03:24 -04:00
|
|
|
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
|
|
|
|
ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
|
|
|
|
|
|
|
|
return meta_backend_get_idle_monitor (backend, clutter_seat_get_pointer (seat));
|
2013-08-14 06:50:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_idle_monitor_get_for_device:
|
2019-10-09 10:03:24 -04:00
|
|
|
* @device: the device to get the idle time for.
|
2013-08-14 06:50:48 -04:00
|
|
|
*
|
|
|
|
* Returns: (transfer none): a new #MetaIdleMonitor that tracks the
|
|
|
|
* device-specific idletime for @device. To track server-global idletime
|
|
|
|
* for all devices, use meta_idle_monitor_get_core().
|
|
|
|
*/
|
|
|
|
MetaIdleMonitor *
|
2019-10-09 10:03:24 -04:00
|
|
|
meta_idle_monitor_get_for_device (ClutterInputDevice *device)
|
2013-08-14 06:50:48 -04:00
|
|
|
{
|
2014-04-21 19:03:22 -04:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
2019-10-09 10:03:24 -04:00
|
|
|
return meta_backend_get_idle_monitor (backend, device);
|
2013-08-14 06:50:48 -04:00
|
|
|
}
|
|
|
|
|
2018-03-20 05:59:04 -04:00
|
|
|
static guint32
|
|
|
|
get_next_watch_serial (void)
|
|
|
|
{
|
|
|
|
static guint32 serial = 0;
|
|
|
|
|
|
|
|
g_atomic_int_inc (&serial);
|
|
|
|
|
|
|
|
return serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
idle_monitor_dispatch_timeout (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaIdleMonitorWatch *watch = (MetaIdleMonitorWatch *) user_data;
|
2019-04-16 12:07:31 -04:00
|
|
|
int64_t now;
|
|
|
|
int64_t ready_time;
|
|
|
|
|
|
|
|
now = g_source_get_time (source);
|
|
|
|
ready_time = g_source_get_ready_time (source);
|
|
|
|
if (ready_time > now)
|
|
|
|
return G_SOURCE_CONTINUE;
|
2018-03-20 05:59:04 -04:00
|
|
|
|
|
|
|
g_source_set_ready_time (watch->timeout_source, -1);
|
|
|
|
|
2019-09-16 10:36:51 -04:00
|
|
|
meta_idle_monitor_watch_fire (watch);
|
|
|
|
|
2019-04-16 12:06:54 -04:00
|
|
|
return G_SOURCE_CONTINUE;
|
2018-03-20 05:59:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static GSourceFuncs idle_monitor_source_funcs = {
|
|
|
|
.prepare = NULL,
|
|
|
|
.check = NULL,
|
|
|
|
.dispatch = idle_monitor_dispatch_timeout,
|
|
|
|
.finalize = NULL,
|
|
|
|
};
|
|
|
|
|
2013-08-14 06:50:48 -04:00
|
|
|
static MetaIdleMonitorWatch *
|
|
|
|
make_watch (MetaIdleMonitor *monitor,
|
|
|
|
guint64 timeout_msec,
|
2014-03-30 20:52:25 -04:00
|
|
|
MetaIdleMonitorWatchFunc callback,
|
|
|
|
gpointer user_data,
|
|
|
|
GDestroyNotify notify)
|
2013-08-14 06:50:48 -04:00
|
|
|
{
|
|
|
|
MetaIdleMonitorWatch *watch;
|
|
|
|
|
2018-03-20 05:59:04 -04:00
|
|
|
watch = g_slice_new0 (MetaIdleMonitorWatch);
|
|
|
|
|
|
|
|
watch->monitor = monitor;
|
|
|
|
watch->id = get_next_watch_serial ();
|
|
|
|
watch->callback = callback;
|
|
|
|
watch->user_data = user_data;
|
|
|
|
watch->notify = notify;
|
|
|
|
watch->timeout_msec = timeout_msec;
|
|
|
|
|
|
|
|
if (timeout_msec != 0)
|
|
|
|
{
|
|
|
|
GSource *source = g_source_new (&idle_monitor_source_funcs,
|
|
|
|
sizeof (GSource));
|
|
|
|
|
|
|
|
g_source_set_callback (source, NULL, watch, NULL);
|
2018-03-20 06:45:35 -04:00
|
|
|
if (!monitor->inhibited)
|
|
|
|
{
|
|
|
|
g_source_set_ready_time (source,
|
|
|
|
monitor->last_event_time +
|
|
|
|
timeout_msec * 1000);
|
|
|
|
}
|
2018-03-20 05:59:04 -04:00
|
|
|
g_source_attach (source, NULL);
|
|
|
|
g_source_unref (source);
|
|
|
|
|
|
|
|
watch->timeout_source = source;
|
|
|
|
}
|
2013-08-14 06:50:48 -04:00
|
|
|
|
|
|
|
g_hash_table_insert (monitor->watches,
|
|
|
|
GUINT_TO_POINTER (watch->id),
|
|
|
|
watch);
|
|
|
|
return watch;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_idle_monitor_add_idle_watch:
|
|
|
|
* @monitor: A #MetaIdleMonitor
|
|
|
|
* @interval_msec: The idletime interval, in milliseconds
|
2014-05-28 15:44:23 -04:00
|
|
|
* @callback: (nullable): The callback to call when the user has
|
2013-08-14 06:50:48 -04:00
|
|
|
* accumulated @interval_msec milliseconds of idle time.
|
2014-05-28 15:44:23 -04:00
|
|
|
* @user_data: (nullable): The user data to pass to the callback
|
2013-08-14 06:50:48 -04:00
|
|
|
* @notify: A #GDestroyNotify
|
|
|
|
*
|
|
|
|
* Returns: a watch id
|
|
|
|
*
|
|
|
|
* Adds a watch for a specific idle time. The callback will be called
|
|
|
|
* when the user has accumulated @interval_msec milliseconds of idle time.
|
|
|
|
* This function will return an ID that can either be passed to
|
|
|
|
* meta_idle_monitor_remove_watch(), or can be used to tell idle time
|
|
|
|
* watches apart if you have more than one.
|
|
|
|
*
|
|
|
|
* Also note that this function will only care about positive transitions
|
|
|
|
* (user's idle time exceeding a certain time). If you want to know about
|
|
|
|
* when the user has become active, use
|
|
|
|
* meta_idle_monitor_add_user_active_watch().
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
meta_idle_monitor_add_idle_watch (MetaIdleMonitor *monitor,
|
|
|
|
guint64 interval_msec,
|
|
|
|
MetaIdleMonitorWatchFunc callback,
|
|
|
|
gpointer user_data,
|
|
|
|
GDestroyNotify notify)
|
|
|
|
{
|
|
|
|
MetaIdleMonitorWatch *watch;
|
|
|
|
|
|
|
|
g_return_val_if_fail (META_IS_IDLE_MONITOR (monitor), 0);
|
|
|
|
g_return_val_if_fail (interval_msec > 0, 0);
|
|
|
|
|
|
|
|
watch = make_watch (monitor,
|
|
|
|
interval_msec,
|
|
|
|
callback,
|
|
|
|
user_data,
|
|
|
|
notify);
|
|
|
|
|
|
|
|
return watch->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_idle_monitor_add_user_active_watch:
|
|
|
|
* @monitor: A #MetaIdleMonitor
|
2014-05-28 15:44:23 -04:00
|
|
|
* @callback: (nullable): The callback to call when the user is
|
2013-08-14 06:50:48 -04:00
|
|
|
* active again.
|
2014-05-28 15:44:23 -04:00
|
|
|
* @user_data: (nullable): The user data to pass to the callback
|
2013-08-14 06:50:48 -04:00
|
|
|
* @notify: A #GDestroyNotify
|
|
|
|
*
|
|
|
|
* Returns: a watch id
|
|
|
|
*
|
|
|
|
* Add a one-time watch to know when the user is active again.
|
|
|
|
* Note that this watch is one-time and will de-activate after the
|
|
|
|
* function is called, for efficiency purposes. It's most convenient
|
|
|
|
* to call this when an idle watch, as added by
|
|
|
|
* meta_idle_monitor_add_idle_watch(), has triggered.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
meta_idle_monitor_add_user_active_watch (MetaIdleMonitor *monitor,
|
|
|
|
MetaIdleMonitorWatchFunc callback,
|
|
|
|
gpointer user_data,
|
|
|
|
GDestroyNotify notify)
|
|
|
|
{
|
|
|
|
MetaIdleMonitorWatch *watch;
|
|
|
|
|
|
|
|
g_return_val_if_fail (META_IS_IDLE_MONITOR (monitor), 0);
|
|
|
|
|
|
|
|
watch = make_watch (monitor,
|
|
|
|
0,
|
|
|
|
callback,
|
|
|
|
user_data,
|
|
|
|
notify);
|
|
|
|
|
|
|
|
return watch->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_idle_monitor_remove_watch:
|
|
|
|
* @monitor: A #MetaIdleMonitor
|
|
|
|
* @id: A watch ID
|
|
|
|
*
|
|
|
|
* Removes an idle time watcher, previously added by
|
|
|
|
* meta_idle_monitor_add_idle_watch() or
|
|
|
|
* meta_idle_monitor_add_user_active_watch().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_idle_monitor_remove_watch (MetaIdleMonitor *monitor,
|
|
|
|
guint id)
|
|
|
|
{
|
|
|
|
g_return_if_fail (META_IS_IDLE_MONITOR (monitor));
|
|
|
|
|
2014-02-22 14:16:28 -05:00
|
|
|
g_object_ref (monitor);
|
2013-08-14 06:50:48 -04:00
|
|
|
g_hash_table_remove (monitor->watches,
|
|
|
|
GUINT_TO_POINTER (id));
|
2014-02-22 14:16:28 -05:00
|
|
|
g_object_unref (monitor);
|
2013-08-14 06:50:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_idle_monitor_get_idletime:
|
|
|
|
* @monitor: A #MetaIdleMonitor
|
|
|
|
*
|
|
|
|
* Returns: The current idle time, in milliseconds, or -1 for not supported
|
|
|
|
*/
|
|
|
|
gint64
|
|
|
|
meta_idle_monitor_get_idletime (MetaIdleMonitor *monitor)
|
|
|
|
{
|
2018-03-20 05:59:04 -04:00
|
|
|
return (g_get_monotonic_time () - monitor->last_event_time) / 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_idle_monitor_reset_idletime (MetaIdleMonitor *monitor)
|
|
|
|
{
|
|
|
|
GList *node, *watch_ids;
|
|
|
|
|
|
|
|
monitor->last_event_time = g_get_monotonic_time ();
|
|
|
|
|
|
|
|
watch_ids = g_hash_table_get_keys (monitor->watches);
|
|
|
|
|
|
|
|
for (node = watch_ids; node != NULL; node = node->next)
|
|
|
|
{
|
|
|
|
guint watch_id = GPOINTER_TO_UINT (node->data);
|
|
|
|
MetaIdleMonitorWatch *watch;
|
|
|
|
|
|
|
|
watch = g_hash_table_lookup (monitor->watches,
|
|
|
|
GUINT_TO_POINTER (watch_id));
|
|
|
|
if (!watch)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (watch->timeout_msec == 0)
|
|
|
|
{
|
2019-09-16 10:36:05 -04:00
|
|
|
meta_idle_monitor_watch_fire (watch);
|
2018-03-20 05:59:04 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-09 04:24:54 -04:00
|
|
|
if (monitor->inhibited)
|
|
|
|
{
|
|
|
|
g_source_set_ready_time (watch->timeout_source, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_source_set_ready_time (watch->timeout_source,
|
|
|
|
monitor->last_event_time +
|
|
|
|
watch->timeout_msec * 1000);
|
|
|
|
}
|
2018-03-20 05:59:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (watch_ids);
|
2013-08-23 09:07:57 -04:00
|
|
|
}
|