[gnome-flashback] idle-monitor: remove GTK dependency
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] idle-monitor: remove GTK dependency
- Date: Tue, 24 May 2022 20:48:10 +0000 (UTC)
commit c2e1afbe96b52abd4bfe80d4b923d2ab305407cd
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue May 24 22:26:04 2022 +0300
idle-monitor: remove GTK dependency
configure.ac | 1 -
daemons/idle-monitor/flashback-idle-monitor.c | 139 ++++++++++++++++++++++----
daemons/idle-monitor/gf-idle-monitor-main.c | 3 -
3 files changed, 119 insertions(+), 24 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9e351f4..a5da422 100644
--- a/configure.ac
+++ b/configure.ac
@@ -169,7 +169,6 @@ PKG_CHECK_MODULES([END_SESSION_DIALOG], [
PKG_CHECK_MODULES([IDLE_MONITOR], [
gio-unix-2.0 >= $GLIB_REQUIRED
- gtk+-3.0 >= $GTK_REQUIRED
x11
xext
])
diff --git a/daemons/idle-monitor/flashback-idle-monitor.c b/daemons/idle-monitor/flashback-idle-monitor.c
index e229993..5b05476 100644
--- a/daemons/idle-monitor/flashback-idle-monitor.c
+++ b/daemons/idle-monitor/flashback-idle-monitor.c
@@ -21,8 +21,7 @@
#include "config.h"
-#include <gdk/gdk.h>
-#include <gdk/gdkx.h>
+#include <stdint.h>
#include <X11/Xlib.h>
#include <X11/extensions/sync.h>
@@ -30,11 +29,22 @@
#include "meta-idle-monitor.h"
#include "meta-dbus-idle-monitor.h"
+typedef struct
+{
+ GSource source;
+ GPollFD event_poll_fd;
+
+ FlashbackIdleMonitor *monitor;
+} XEventSource;
+
struct _FlashbackIdleMonitor
{
GObject parent;
Display *xdisplay;
+
+ GSource *source;
+
XSyncCounter counter;
XSyncAlarm user_active_alarm;
@@ -283,21 +293,87 @@ handle_alarm_notify (FlashbackIdleMonitor *self,
meta_idle_monitor_reset_idletime (self->monitor);
}
-static GdkFilterReturn
-filter_func (GdkXEvent *xevent,
- GdkEvent *event,
- gpointer user_data)
+static void
+handle_xevent (FlashbackIdleMonitor *monitor,
+ XEvent *xevent)
{
+ if (xevent->type == (monitor->xsync_event_base + XSyncAlarmNotify))
+ handle_alarm_notify (monitor, (XSyncAlarmNotifyEvent *) xevent);
+}
+
+static gboolean
+x_event_source_prepare (GSource *source,
+ int *timeout)
+{
+ XEventSource *x_source;
FlashbackIdleMonitor *monitor;
- XEvent *xev;
- monitor = FLASHBACK_IDLE_MONITOR (user_data);
- xev = (XEvent *) xevent;
+ x_source = (XEventSource *) source;
+ monitor = x_source->monitor;
+
+ *timeout = -1;
+
+ return XPending (monitor->xdisplay);
+}
+
+static gboolean
+x_event_source_check (GSource *source)
+{
+ XEventSource *x_source;
+ FlashbackIdleMonitor *monitor;
+
+ x_source = (XEventSource *) source;
+ monitor = x_source->monitor;
+
+ return XPending (monitor->xdisplay);
+}
+
+static gboolean
+x_event_source_dispatch (GSource *source,
+ GSourceFunc callback,
+ gpointer user_data)
+{
+ XEventSource *x_source;
+ FlashbackIdleMonitor *monitor;
+
+ x_source = (XEventSource *) source;
+ monitor = x_source->monitor;
+
+ while (XPending (monitor->xdisplay))
+ {
+ XEvent event;
+
+ XNextEvent (monitor->xdisplay, &event);
+ handle_xevent (monitor, &event);
+ }
+
+ return TRUE;
+}
+
+static GSourceFuncs x_event_funcs =
+ {
+ x_event_source_prepare,
+ x_event_source_check,
+ x_event_source_dispatch,
+ };
+
+static GSource *
+x_event_source_new (FlashbackIdleMonitor *monitor)
+{
+ GSource *source;
+ XEventSource *x_source;
+
+ source = g_source_new (&x_event_funcs, sizeof (XEventSource));
- if (xev->type == (monitor->xsync_event_base + XSyncAlarmNotify))
- handle_alarm_notify (monitor, (XSyncAlarmNotifyEvent *) xev);
+ x_source = (XEventSource *) source;
+ x_source->event_poll_fd.fd = ConnectionNumber (monitor->xdisplay);
+ x_source->event_poll_fd.events = G_IO_IN;
+ x_source->monitor = monitor;
- return GDK_FILTER_CONTINUE;
+ g_source_add_poll (source, &x_source->event_poll_fd);
+ g_source_attach (source, NULL);
+
+ return source;
}
static void
@@ -384,8 +460,6 @@ flashback_idle_monitor_finalize (GObject *object)
monitor = FLASHBACK_IDLE_MONITOR (object);
- gdk_window_remove_filter (NULL, (GdkFilterFunc) filter_func, monitor);
-
if (monitor->user_active_alarm != None)
{
XSyncDestroyAlarm (monitor->xdisplay, monitor->user_active_alarm);
@@ -394,18 +468,48 @@ flashback_idle_monitor_finalize (GObject *object)
g_object_unref (monitor->monitor);
+ if (monitor->source != NULL)
+ {
+ g_source_unref (monitor->source);
+ monitor->source = NULL;
+ }
+
+ if (monitor->xdisplay != NULL)
+ {
+ XCloseDisplay (monitor->xdisplay);
+ monitor->xdisplay = NULL;
+ }
+
G_OBJECT_CLASS (flashback_idle_monitor_parent_class)->finalize (object);
}
static void
flashback_idle_monitor_init (FlashbackIdleMonitor *monitor)
{
- GdkDisplay *display;
+ const char *display;
gint event_base;
gint error_base;
gint major;
gint minor;
+ display = g_getenv ("DISPLAY");
+
+ if (display == NULL)
+ {
+ g_critical ("Unable to open display, DISPLAY not set");
+ return;
+ }
+
+ monitor->xdisplay = XOpenDisplay (display);
+
+ if (monitor->xdisplay == NULL)
+ {
+ g_critical ("Unable to open display '%s'", display);
+ return;
+ }
+
+ monitor->source = x_event_source_new (monitor);
+
monitor->monitor = g_object_new (META_TYPE_IDLE_MONITOR,
NULL);
@@ -418,9 +522,6 @@ flashback_idle_monitor_init (FlashbackIdleMonitor *monitor)
(GBusNameLostCallback) on_name_lost,
monitor, NULL);
- display = gdk_display_get_default ();
- monitor->xdisplay = gdk_x11_display_get_xdisplay (display);
-
if (!XSyncQueryExtension (monitor->xdisplay, &event_base, &error_base))
{
g_critical ("Could not query XSync extension");
@@ -447,8 +548,6 @@ flashback_idle_monitor_init (FlashbackIdleMonitor *monitor)
XSyncNegativeTransition,
1,
TRUE);
-
- gdk_window_add_filter (NULL, (GdkFilterFunc) filter_func, monitor);
}
static void
diff --git a/daemons/idle-monitor/gf-idle-monitor-main.c b/daemons/idle-monitor/gf-idle-monitor-main.c
index f7ef026..27b20b2 100644
--- a/daemons/idle-monitor/gf-idle-monitor-main.c
+++ b/daemons/idle-monitor/gf-idle-monitor-main.c
@@ -18,7 +18,6 @@
#include "config.h"
#include <glib-unix.h>
-#include <gtk/gtk.h>
#include <stdlib.h>
#include "dbus/gf-session-manager-gen.h"
@@ -191,8 +190,6 @@ main (int argc,
startup_id = g_strdup (autostart_id != NULL ? autostart_id : "");
g_unsetenv ("DESKTOP_AUTOSTART_ID");
- gtk_init (&argc, &argv);
-
loop = g_main_loop_new (NULL, FALSE);
idle_monitor = flashback_idle_monitor_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]