[gnome-flashback] desktop: check if other application is managing desktop
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] desktop: check if other application is managing desktop
- Date: Thu, 14 Nov 2019 15:05:55 +0000 (UTC)
commit 2486fdc96081ab2a695599d33bd50fc2be0a2541
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Thu Nov 14 16:56:27 2019 +0200
desktop: check if other application is managing desktop
Do not create desktop window if another desktop manager is running.
gnome-flashback/libdesktop/gf-desktop-window.c | 85 ++++++++++++++++++++++----
gnome-flashback/libdesktop/gf-desktop-window.h | 11 ++--
gnome-flashback/libdesktop/gf-desktop.c | 12 +++-
3 files changed, 91 insertions(+), 17 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/gf-desktop-window.c b/gnome-flashback/libdesktop/gf-desktop-window.c
index 25cbdd3..2800b8e 100644
--- a/gnome-flashback/libdesktop/gf-desktop-window.c
+++ b/gnome-flashback/libdesktop/gf-desktop-window.c
@@ -67,7 +67,11 @@ enum
static guint window_signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (GfDesktopWindow, gf_desktop_window, GTK_TYPE_WINDOW)
+static void initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GfDesktopWindow, gf_desktop_window, GTK_TYPE_WINDOW,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ initable_iface_init))
static gboolean
get_representative_color (GfDesktopWindow *self,
@@ -463,6 +467,54 @@ monitor_removed_cb (GdkDisplay *display,
queue_move_resize (self);
}
+static gboolean
+gf_desktop_window_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GtkWidget *widget;
+ GdkDisplay *display;
+ Display *xdisplay;
+ char *atom_name;
+ Atom atom;
+ GdkWindow *window;
+ Window xwindow;
+
+ widget = GTK_WIDGET (initable);
+
+ display = gtk_widget_get_display (widget);
+ xdisplay = gdk_x11_display_get_xdisplay (display);
+
+ atom_name = g_strdup_printf ("_NET_DESKTOP_MANAGER_S%d",
+ XDefaultScreen (xdisplay));
+
+ atom = XInternAtom (xdisplay, atom_name, False);
+ g_free (atom_name);
+
+ if (XGetSelectionOwner (xdisplay, atom) != None)
+ {
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Another desktop manager is running.");
+
+ return FALSE;
+ }
+
+ gtk_widget_realize (widget);
+
+ window = gtk_widget_get_window (widget);
+ xwindow = gdk_x11_window_get_xid (window);
+
+ XSetSelectionOwner (xdisplay, atom, xwindow, CurrentTime);
+
+ return TRUE;
+}
+
+static void
+initable_iface_init (GInitableIface *iface)
+{
+ iface->init = gf_desktop_window_initable_init;
+}
+
static void
gf_desktop_window_constructed (GObject *object)
{
@@ -690,16 +742,27 @@ gf_desktop_window_init (GfDesktopWindow *self)
}
GtkWidget *
-gf_desktop_window_new (gboolean draw_background,
- gboolean show_icons)
-{
- return g_object_new (GF_TYPE_DESKTOP_WINDOW,
- "app-paintable", TRUE,
- "type", GTK_WINDOW_TOPLEVEL,
- "type-hint", GDK_WINDOW_TYPE_HINT_DESKTOP,
- "draw-background", draw_background,
- "show-icons", show_icons,
- NULL);
+gf_desktop_window_new (gboolean draw_background,
+ gboolean show_icons,
+ GError **error)
+{
+ GtkWidget *window;
+
+ window = g_object_new (GF_TYPE_DESKTOP_WINDOW,
+ "app-paintable", TRUE,
+ "type", GTK_WINDOW_TOPLEVEL,
+ "type-hint", GDK_WINDOW_TYPE_HINT_DESKTOP,
+ "draw-background", draw_background,
+ "show-icons", show_icons,
+ NULL);
+
+ if (!g_initable_init (G_INITABLE (window), NULL, error))
+ {
+ gtk_widget_destroy (window);
+ return NULL;
+ }
+
+ return window;
}
gboolean
diff --git a/gnome-flashback/libdesktop/gf-desktop-window.h b/gnome-flashback/libdesktop/gf-desktop-window.h
index 38a47f1..56e9e1f 100644
--- a/gnome-flashback/libdesktop/gf-desktop-window.h
+++ b/gnome-flashback/libdesktop/gf-desktop-window.h
@@ -26,14 +26,15 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GfDesktopWindow, gf_desktop_window,
GF, DESKTOP_WINDOW, GtkWindow)
-GtkWidget *gf_desktop_window_new (gboolean draw_background,
- gboolean show_icons);
+GtkWidget *gf_desktop_window_new (gboolean draw_background,
+ gboolean show_icons,
+ GError **error);
-gboolean gf_desktop_window_is_ready (GfDesktopWindow *self);
+gboolean gf_desktop_window_is_ready (GfDesktopWindow *self);
-int gf_desktop_window_get_width (GfDesktopWindow *self);
+int gf_desktop_window_get_width (GfDesktopWindow *self);
-int gf_desktop_window_get_height (GfDesktopWindow *self);
+int gf_desktop_window_get_height (GfDesktopWindow *self);
G_END_DECLS
diff --git a/gnome-flashback/libdesktop/gf-desktop.c b/gnome-flashback/libdesktop/gf-desktop.c
index 014d094..6a582ba 100644
--- a/gnome-flashback/libdesktop/gf-desktop.c
+++ b/gnome-flashback/libdesktop/gf-desktop.c
@@ -68,13 +68,23 @@ gf_desktop_init (GfDesktop *self)
{
gboolean draw_background;
gboolean show_icons;
+ GError *error;
self->settings = g_settings_new ("org.gnome.gnome-flashback.desktop");
draw_background = g_settings_get_boolean (self->settings, "draw-background");
show_icons = g_settings_get_boolean (self->settings, "show-icons");
- self->window = gf_desktop_window_new (draw_background, show_icons);
+ error = NULL;
+ self->window = gf_desktop_window_new (draw_background, show_icons, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ return;
+ }
g_settings_bind (self->settings, "draw-background",
self->window, "draw-background",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]