[gtk+] gtk-shell: extend the protocol with shell capabilities



commit 7f8bf416334746510be0b4810f4bf4923964037a
Author: Giovanni Campagna <gcampagn redhat com>
Date:   Tue Sep 3 09:54:53 2013 +0200

    gtk-shell: extend the protocol with shell capabilities
    
    Add the concept of shell capabilities, which allow the compositor
    to advertise support for the app menu and the global menubar,
    which are then propagated as GdkSettings.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707129

 gdk/wayland/gdkdisplay-wayland.c   |    3 ++
 gdk/wayland/gdkprivate-wayland.h   |    2 +
 gdk/wayland/gdkscreen-wayland.c    |   42 ++++++++++++++++++++++++++++++++++++
 gdk/wayland/protocol/gtk-shell.xml |    9 +++++++
 4 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index d0d12e2..71debb9 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -170,6 +170,9 @@ gdk_registry_handle_global(void *data, struct wl_registry *registry, uint32_t id
   } else if (strcmp(interface, "gtk_shell") == 0) {
     display_wayland->gtk_shell =
       wl_registry_bind(display_wayland->wl_registry, id, &gtk_shell_interface, 1);
+    _gdk_wayland_screen_set_has_gtk_shell (display_wayland->screen);
+    /* We need another roundtrip to receive the shell capabilities */
+    wait_for_roundtrip(display_wayland);
   } else if (strcmp(interface, "wl_output") == 0) {
     output =
       wl_registry_bind(display_wayland->wl_registry, id, &wl_output_interface, MIN (version, 2));
diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h
index e0d48d3..6334f5f 100644
--- a/gdk/wayland/gdkprivate-wayland.h
+++ b/gdk/wayland/gdkprivate-wayland.h
@@ -171,6 +171,8 @@ int _gdk_wayland_screen_get_output_refresh_rate (GdkScreen        *screen,
 guint32 _gdk_wayland_screen_get_output_scale (GdkScreen        *screen,
                                              struct wl_output *output);
 
+void _gdk_wayland_screen_set_has_gtk_shell (GdkScreen       *screen);
+
 void _gdk_wayland_window_set_device_grabbed (GdkWindow      *window,
                                              GdkDevice      *device,
                                              struct wl_seat *seat,
diff --git a/gdk/wayland/gdkscreen-wayland.c b/gdk/wayland/gdkscreen-wayland.c
index d25a954..daf9b29 100644
--- a/gdk/wayland/gdkscreen-wayland.c
+++ b/gdk/wayland/gdkscreen-wayland.c
@@ -68,6 +68,8 @@ struct _GdkWaylandScreen
 
   GHashTable *settings;
   GsdXftSettings xft_settings;
+
+  guint32    shell_capabilities;
 };
 
 struct _GdkWaylandScreenClass
@@ -605,6 +607,28 @@ init_settings (GdkScreen *screen)
 }
 
 static void
+gtk_shell_handle_capabilities (void             *data,
+                              struct gtk_shell *shell,
+                              uint32_t          capabilities)
+{
+  GdkWaylandScreen *screen_wayland = data;
+
+  screen_wayland->shell_capabilities = capabilities;
+}
+
+struct gtk_shell_listener gdk_screen_gtk_shell_listener = {
+  gtk_shell_handle_capabilities
+};
+
+void
+_gdk_wayland_screen_set_has_gtk_shell (GdkScreen *screen)
+{
+  GdkWaylandDisplay *wayland_display = GDK_WAYLAND_DISPLAY (GDK_WAYLAND_SCREEN (screen)->display);
+
+  gtk_shell_add_listener (wayland_display->gtk_shell, &gdk_screen_gtk_shell_listener, screen);
+}
+
+static void
 set_value_from_entry (GdkScreen        *screen,
                       TranslationEntry *entry,
                       GValue           *value)
@@ -658,6 +682,18 @@ set_value_from_entry (GdkScreen        *screen,
 }
 
 static gboolean
+set_capability_setting (GdkScreen                 *screen,
+                       GValue                    *value,
+                       enum gtk_shell_capability  test)
+{
+  GdkWaylandScreen *wayland_screen = GDK_WAYLAND_SCREEN (screen);
+
+  g_value_set_boolean (value, (wayland_screen->shell_capabilities & test) == test);
+
+  return TRUE;
+}
+
+static gboolean
 gdk_wayland_screen_get_setting (GdkScreen   *screen,
                                const gchar *name,
                                GValue      *value)
@@ -673,6 +709,12 @@ gdk_wayland_screen_get_setting (GdkScreen   *screen,
       return TRUE;
    }
 
+  if (strcmp (name, "gtk-shell-shows-app-menu") == 0)
+    return set_capability_setting (screen, value, GTK_SHELL_CAPABILITY_GLOBAL_APP_MENU);
+
+  if (strcmp (name, "gtk-shell-shows-menubar") == 0)
+    return set_capability_setting (screen, value, GTK_SHELL_CAPABILITY_GLOBAL_MENU_BAR);
+
   return FALSE;
 }
 
diff --git a/gdk/wayland/protocol/gtk-shell.xml b/gdk/wayland/protocol/gtk-shell.xml
index 785d380..a4e2565 100644
--- a/gdk/wayland/protocol/gtk-shell.xml
+++ b/gdk/wayland/protocol/gtk-shell.xml
@@ -1,6 +1,15 @@
 <protocol name="gtk">
 
   <interface name="gtk_shell" version="1">
+    <enum name="capability">
+      <entry name="global_app_menu" value="1"/>
+      <entry name="global_menu_bar" value="2"/>
+    </enum>
+    
+    <event name="capabilities">
+      <arg name="capabilities" type="uint"/>
+    </event>
+
     <request name="get_gtk_surface">
       <arg name="gtk_surface" type="new_id" interface="gtk_surface"/>
       <arg name="surface" type="object" interface="wl_surface"/>


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