[gnome-flashback/wip/muktupavels/animations] shell: add org.gnome.Shell.Introspect interface



commit d89187022346c06b2dcfdcd95dcff524006360a8
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed Apr 29 14:58:55 2020 +0300

    shell: add org.gnome.Shell.Introspect interface
    
    GNOME Settings Daemon now uses org.gnome.Shell.Introspect D-Bus
    interface to enable/disable animations.
    
    https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/merge_requests/135

 dbus/Makefile.am                               |   9 ++
 dbus/org.gnome.Shell.Introspect.xml            |  75 +++++++++
 gnome-flashback/libshell/Makefile.am           |   2 +
 gnome-flashback/libshell/flashback-shell.c     |   8 +-
 gnome-flashback/libshell/gf-shell-introspect.c | 205 +++++++++++++++++++++++++
 gnome-flashback/libshell/gf-shell-introspect.h |  33 ++++
 6 files changed, 331 insertions(+), 1 deletion(-)
---
diff --git a/dbus/Makefile.am b/dbus/Makefile.am
index 1a699b6..c047a2e 100644
--- a/dbus/Makefile.am
+++ b/dbus/Makefile.am
@@ -159,6 +159,12 @@ gf-shell-gen.c: org.gnome.Shell.xml
                --generate-c-code gf-shell-gen \
                $(srcdir)/org.gnome.Shell.xml
 
+gf-shell-introspect-gen.h:
+gf-shell-introspect-gen.c: org.gnome.Shell.Introspect.xml
+       $(AM_V_GEN) $(GDBUS_CODEGEN) --c-namespace Gf \
+               --generate-c-code gf-shell-introspect-gen \
+               $(srcdir)/org.gnome.Shell.Introspect.xml
+
 gf-sm-client-private-gen.h:
 gf-sm-client-private-gen.c: org.gnome.SessionManager.ClientPrivate.xml
        $(AM_V_GEN) $(GDBUS_CODEGEN) --c-namespace Gf \
@@ -222,6 +228,8 @@ BUILT_SOURCES = \
        gf-session-manager-gen.h \
        gf-shell-gen.c \
        gf-shell-gen.h \
+       gf-shell-introspect-gen.c \
+       gf-shell-introspect-gen.h \
        gf-sm-client-private-gen.c \
        gf-sm-client-private-gen.h \
        gf-sm-presence-gen.c \
@@ -251,6 +259,7 @@ EXTRA_DIST = \
        org.gnome.SessionManager.xml \
        org.gnome.SettingsDaemon.Rfkill.xml \
        org.gnome.Shell.AudioDeviceSelection.xml \
+       org.gnome.Shell.Introspect.xml \
        org.gnome.Shell.Screencast.xml \
        org.gnome.Shell.Screenshot.xml \
        org.gnome.Shell.xml \
diff --git a/dbus/org.gnome.Shell.Introspect.xml b/dbus/org.gnome.Shell.Introspect.xml
new file mode 100644
index 0000000..f2f1e8f
--- /dev/null
+++ b/dbus/org.gnome.Shell.Introspect.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd";>
+<node>
+  <!--
+      org.gnome.Shell.Introspect:
+      @short_description: Introspection interface
+
+      The interface used to introspect the state of Shell, such as running
+      applications, currently active application, etc.
+  -->
+  <interface name="org.gnome.Shell.Introspect">
+    <annotation name="org.gtk.GDBus.C.Name" value="ShellIntrospectGen" />
+
+    <!--
+        RunningApplicationsChanged:
+        @short_description: Notifies when the running applications changes
+    -->
+    <signal name="RunningApplicationsChanged" />
+
+    <!--
+        GetRunningApplications:
+        @short_description: Retrieves the description of all running applications
+
+        Each application is associated by an application ID. The details of
+        each application consists of a varlist of keys and values. Available
+        keys are listed below.
+
+        'active-on-seats' - (as)   list of seats the application is active on
+                                   (a seat only has at most one active
+                                   application)
+    -->
+    <method name="GetRunningApplications">
+      <arg name="apps" direction="out" type="a{sa{sv}}" />
+    </method>
+
+    <!--
+        GetWindows:
+        @short_description: Retrieves the current list of windows and their properties
+
+        A window is exposed as:
+        * t ID: unique ID of the window
+        * a{sv} properties: high-level properties
+
+          Known properties:
+
+          - "title"       (s): (readonly) title of the window
+          - "app-id"      (s): (readonly) application ID of the window
+          - "wm-class"    (s): (readonly) class of the window
+          - "client-type" (u): (readonly) 0 for Wayland, 1 for X11
+          - "is-hidden"   (b): (readonly) if the window is currently hidden
+          - "has-focus"   (b): (readonly) if the window currently have
+                                          keyboard focus
+          - "width"       (u): (readonly) width of the window
+          - "height"      (u): (readonly) height of the window
+    -->
+    <method name="GetWindows">
+      <arg name="windows" direction="out" type="a{ta{sv}}" />
+    </method>
+
+    <!--
+       AnimationsEnabled:
+       @short_description: Whether the shell animations are enabled
+
+       By default determined by the org.gnome.desktop.interface enable-animations
+       gsetting, but may be overridden, e.g. if there is an active screen cast or
+       remote desktop session that asked for animations to be disabled.
+
+       Since: 2
+    -->
+    <property name="AnimationsEnabled" type="b" access="read"/>
+
+    <property name="version" type="u" access="read"/>
+  </interface>
+</node>
diff --git a/gnome-flashback/libshell/Makefile.am b/gnome-flashback/libshell/Makefile.am
index e0dec19..622bc3d 100644
--- a/gnome-flashback/libshell/Makefile.am
+++ b/gnome-flashback/libshell/Makefile.am
@@ -31,6 +31,8 @@ libshell_la_SOURCES = \
        gf-label-window.h \
        gf-osd-window.c \
        gf-osd-window.h \
+       gf-shell-introspect.c \
+       gf-shell-introspect.h \
        $(NULL)
 
 libshell_la_LDFLAGS = \
diff --git a/gnome-flashback/libshell/flashback-shell.c b/gnome-flashback/libshell/flashback-shell.c
index 3df316e..14dcc5e 100644
--- a/gnome-flashback/libshell/flashback-shell.c
+++ b/gnome-flashback/libshell/flashback-shell.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2019 Alberts Muktupāvels
+ * Copyright (C) 2015-2020 Alberts Muktupāvels
  *
  * 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
@@ -24,6 +24,7 @@
 #include "dbus/gf-shell-gen.h"
 #include "flashback-monitor-labeler.h"
 #include "flashback-osd.h"
+#include "gf-shell-introspect.h"
 
 #define SHELL_DBUS_NAME "org.gnome.Shell"
 #define SHELL_DBUS_PATH "/org/gnome/Shell"
@@ -52,6 +53,8 @@ struct _FlashbackShell
 
   /* osd */
   FlashbackOsd            *osd;
+
+  GfShellIntrospect       *introspect;
 };
 
 G_DEFINE_TYPE (FlashbackShell, flashback_shell, G_TYPE_OBJECT)
@@ -509,6 +512,7 @@ flashback_shell_finalize (GObject *object)
   g_clear_object (&shell->keybindings);
   g_clear_object (&shell->labeler);
   g_clear_object (&shell->osd);
+  g_clear_object (&shell->introspect);
 
   G_OBJECT_CLASS (flashback_shell_parent_class)->finalize (object);
 }
@@ -537,6 +541,8 @@ flashback_shell_init (FlashbackShell *shell)
   shell->labeler = flashback_monitor_labeler_new ();
   shell->osd = flashback_osd_new ();
 
+  shell->introspect = gf_shell_introspect_new ();
+
   shell->bus_name = g_bus_watch_name (G_BUS_TYPE_SESSION,
                                       SHELL_DBUS_NAME,
                                       G_BUS_NAME_WATCHER_FLAGS_NONE,
diff --git a/gnome-flashback/libshell/gf-shell-introspect.c b/gnome-flashback/libshell/gf-shell-introspect.c
new file mode 100644
index 0000000..3da62df
--- /dev/null
+++ b/gnome-flashback/libshell/gf-shell-introspect.c
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2020 Alberts Muktupāvels
+ *
+ * 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 3 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "gf-shell-introspect.h"
+
+#include "dbus/gf-shell-introspect-gen.h"
+
+#define SHELL_INTROSPECT_DBUS_NAME "org.gnome.Shell.Introspect"
+#define SHELL_INTROSPECT_DBUS_PATH "/org/gnome/Shell/Introspect"
+
+#define INTROSPECT_DBUS_API_VERSION 2
+
+struct _GfShellIntrospect
+{
+  GObject               parent;
+
+  GfShellIntrospectGen *introspect;
+  gint                  bus_name_id;
+
+  GSettings            *interface_settings;
+};
+
+G_DEFINE_TYPE (GfShellIntrospect, gf_shell_introspect, G_TYPE_OBJECT)
+
+static void
+enable_animations_changed_cb (GSettings         *settings,
+                              const char        *key,
+                              GfShellIntrospect *self)
+{
+  gboolean animations_enabled;
+
+  animations_enabled = g_settings_get_boolean (settings, key);
+
+  gf_shell_introspect_gen_set_animations_enabled (self->introspect,
+                                                  animations_enabled);
+}
+
+static gboolean
+handle_get_running_applications (GfShellIntrospectGen  *object,
+                                 GDBusMethodInvocation *invocation,
+                                 GfShellIntrospect     *self)
+{
+  g_dbus_method_invocation_return_error_literal (invocation,
+                                                 G_DBUS_ERROR,
+                                                 G_DBUS_ERROR_NOT_SUPPORTED,
+                                                 "GetRunningApplications method "
+                                                 "is not implemented in GNOME "
+                                                 "Flashback!");
+
+  return TRUE;
+}
+
+static gboolean
+handle_get_windows (GfShellIntrospectGen  *object,
+                    GDBusMethodInvocation *invocation,
+                    GfShellIntrospect     *self)
+{
+  g_dbus_method_invocation_return_error_literal (invocation,
+                                                 G_DBUS_ERROR,
+                                                 G_DBUS_ERROR_NOT_SUPPORTED,
+                                                 "GetWindows method is not "
+                                                 "implemented in GNOME "
+                                                 "Flashback!");
+
+  return TRUE;
+}
+
+static void
+bus_acquired_handler (GDBusConnection *connection,
+                      const char      *name,
+                      gpointer         user_data)
+{
+  GfShellIntrospect *self;
+  GDBusInterfaceSkeleton *skeleton;
+  GError *error;
+
+  self = GF_SHELL_INTROSPECT (user_data);
+
+  skeleton = G_DBUS_INTERFACE_SKELETON (self->introspect);
+  error = NULL;
+
+  if (!g_dbus_interface_skeleton_export (skeleton,
+                                         connection,
+                                         SHELL_INTROSPECT_DBUS_PATH,
+                                         &error))
+    {
+      g_warning ("Failed to export interface: %s", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  g_signal_connect (self->introspect,
+                    "handle-get-running-applications",
+                    G_CALLBACK (handle_get_running_applications),
+                    self);
+
+  g_signal_connect (self->introspect,
+                    "handle-get-windows",
+                    G_CALLBACK (handle_get_windows),
+                    self);
+
+  gf_shell_introspect_gen_set_version (self->introspect,
+                                       INTROSPECT_DBUS_API_VERSION);
+}
+
+static void
+name_acquired_handler (GDBusConnection *connection,
+                       const char      *name,
+                       gpointer         user_data)
+{
+}
+
+static void
+name_lost_handler (GDBusConnection *connection,
+                   const char      *name,
+                   gpointer         user_data)
+{
+}
+
+static void
+gf_shell_introspect_dispose (GObject *object)
+{
+  GfShellIntrospect *self;
+
+  self = GF_SHELL_INTROSPECT (object);
+
+  if (self->bus_name_id != 0)
+    {
+      g_bus_unown_name (self->bus_name_id);
+      self->bus_name_id = 0;
+    }
+
+  if (self->introspect != NULL)
+    {
+      GDBusInterfaceSkeleton *skeleton;
+
+      skeleton = G_DBUS_INTERFACE_SKELETON (self->introspect);
+      g_dbus_interface_skeleton_unexport (skeleton);
+
+      g_object_unref (self->introspect);
+      self->introspect = NULL;
+    }
+
+  g_clear_object (&self->interface_settings);
+
+  G_OBJECT_CLASS (gf_shell_introspect_parent_class)->dispose (object);
+}
+
+static void
+gf_shell_introspect_class_init (GfShellIntrospectClass *self_class)
+{
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (self_class);
+
+  object_class->dispose = gf_shell_introspect_dispose;
+}
+
+static void
+gf_shell_introspect_init (GfShellIntrospect *self)
+{
+  self->introspect = gf_shell_introspect_gen_skeleton_new ();
+
+  self->interface_settings = g_settings_new ("org.gnome.desktop.interface");
+
+  g_signal_connect (self->interface_settings,
+                    "changed::enable-animations",
+                    G_CALLBACK (enable_animations_changed_cb),
+                    self);
+
+  enable_animations_changed_cb (self->interface_settings,
+                                "enable-animations",
+                                self);
+
+  self->bus_name_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+                                      SHELL_INTROSPECT_DBUS_NAME,
+                                      G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
+                                      G_BUS_NAME_OWNER_FLAGS_REPLACE,
+                                      bus_acquired_handler,
+                                      name_acquired_handler,
+                                      name_lost_handler,
+                                      self,
+                                      NULL);
+}
+
+GfShellIntrospect *
+gf_shell_introspect_new (void)
+{
+  return g_object_new (GF_TYPE_SHELL_INTROSPECT, NULL);
+}
diff --git a/gnome-flashback/libshell/gf-shell-introspect.h b/gnome-flashback/libshell/gf-shell-introspect.h
new file mode 100644
index 0000000..3caa3b9
--- /dev/null
+++ b/gnome-flashback/libshell/gf-shell-introspect.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2020 Alberts Muktupāvels
+ *
+ * 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 3 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GF_SHELL_INTROSPECT_H
+#define GF_SHELL_INTROSPECT_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GF_TYPE_SHELL_INTROSPECT (gf_shell_introspect_get_type ())
+G_DECLARE_FINAL_TYPE (GfShellIntrospect, gf_shell_introspect,
+                      GF, SHELL_INTROSPECT, GObject)
+
+GfShellIntrospect *gf_shell_introspect_new (void);
+
+G_END_DECLS
+
+#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]