[gtk/wip/carlosg/imwayland: 3/4] gdk/wayland: Add GdkDisplay call to query available globals



commit 3b568fbe7701eeeab89cc995f2a616bb43d17985
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Feb 13 14:28:44 2018 +0100

    gdk/wayland: Add GdkDisplay call to query available globals
    
    The internal known_globals hashtable is used to carry accounting for
    interfaces that depend on others (as ordering is not guaranteed), extend
    its usage so it also keeps track of unimplemented interfaces (here at
    least).
    
    The API call will then use this to allow querying the globals offered by
    the compositor, it will be useful to determine whether we can use
    text-input protocols or should fallback to other IMs.

 docs/reference/gdk/gdk4-sections.txt |  1 +
 gdk/wayland/gdkdisplay-wayland.c     | 42 ++++++++++++++++++++++++++++++------
 gdk/wayland/gdkwaylanddisplay.h      |  4 ++++
 3 files changed, 41 insertions(+), 6 deletions(-)
---
diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt
index 76c1e161e9..fb4615c1d3 100644
--- a/docs/reference/gdk/gdk4-sections.txt
+++ b/docs/reference/gdk/gdk4-sections.txt
@@ -975,6 +975,7 @@ gdk_wayland_device_get_wl_pointer
 gdk_wayland_device_get_wl_seat
 gdk_wayland_display_get_wl_compositor
 gdk_wayland_display_get_wl_display
+gdk_wayland_display_query_registry
 gdk_wayland_window_new_subsurface
 gdk_wayland_window_get_wl_surface
 gdk_wayland_window_set_use_custom_surface
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index 6861f7de21..645f1352d8 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -384,7 +384,6 @@ gdk_registry_handle_global (void               *data,
 {
   GdkWaylandDisplay *display_wayland = data;
   struct wl_output *output;
-  gboolean handled = TRUE;
 
   GDK_NOTE (MISC,
             g_message ("add global %u, interface %s, version %u", id, interface, version));
@@ -507,12 +506,9 @@ gdk_registry_handle_global (void               *data,
                                                            &server_decoration_listener,
                                                            display_wayland);
     }
-  else
-    handled = FALSE;
 
-  if (handled)
-    g_hash_table_insert (display_wayland->known_globals,
-                         GUINT_TO_POINTER (id), g_strdup (interface));
+  g_hash_table_insert (display_wayland->known_globals,
+                       GUINT_TO_POINTER (id), g_strdup (interface));
 
   process_on_globals_closures (display_wayland);
 }
@@ -2077,3 +2073,37 @@ gdk_wayland_display_get_output_scale (GdkWaylandDisplay *display_wayland,
 
   return 0;
 }
+
+/**
+ * gdk_wayland_display_query_registry:
+ * @display: a wayland #GdkDisplay
+ * @interface: global interface to query in the registry
+ *
+ * Returns %TRUE if the the interface was found in the display
+ * wl_registry.global handler.
+ *
+ * Returns: %TRUE if the global is offered by the compositor
+ *
+ * Since: 3.94
+ **/
+gboolean
+gdk_wayland_display_query_registry (GdkDisplay  *display,
+                                   const gchar *global)
+{
+  GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
+  GHashTableIter iter;
+  gchar *value;
+
+  g_return_val_if_fail (GDK_IS_WAYLAND_DISPLAY (display), FALSE);
+  g_return_val_if_fail (global != NULL, FALSE);
+
+  g_hash_table_iter_init (&iter, display_wayland->known_globals);
+
+  while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &value))
+    {
+      if (strcmp (value, global) == 0)
+        return TRUE;
+    }
+
+  return FALSE;
+}
diff --git a/gdk/wayland/gdkwaylanddisplay.h b/gdk/wayland/gdkwaylanddisplay.h
index 7087566330..8eee643530 100644
--- a/gdk/wayland/gdkwaylanddisplay.h
+++ b/gdk/wayland/gdkwaylanddisplay.h
@@ -59,6 +59,10 @@ void                    gdk_wayland_display_set_startup_notification_id (GdkDisp
 
 gboolean                gdk_wayland_display_prefers_ssd         (GdkDisplay *display);
 
+GDK_AVAILABLE_IN_4_0
+gboolean                gdk_wayland_display_query_registry      (GdkDisplay  *display,
+                                                                const gchar *global);
+
 G_END_DECLS
 
 #endif /* __GDK_WAYLAND_DISPLAY_H__ */


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