[gcr/wip/nielsdg/lose-x11-dependency: 1/2] prompt: Support transient_for in Wayland
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcr/wip/nielsdg/lose-x11-dependency: 1/2] prompt: Support transient_for in Wayland
- Date: Tue, 3 Dec 2019 08:07:26 +0000 (UTC)
commit aa49547f2d06fd1cafab4e23a2a8470015993fbe
Author: Niels De Graef <nielsdegraef gmail com>
Date: Tue Dec 3 08:51:28 2019 +0100
prompt: Support transient_for in Wayland
GDK provides an interface to the _xdg-foreign_ protocol extension, which
exactly allows to export a handle that another window can use to set
itself transient to.
gcr/gcr-prompt.c | 4 +++
ui/gcr-prompt-dialog.c | 71 +++++++++++++++++++++++++++++++++++++-------------
2 files changed, 57 insertions(+), 18 deletions(-)
---
diff --git a/gcr/gcr-prompt.c b/gcr/gcr-prompt.c
index d1e71a4..a2a6aaf 100644
--- a/gcr/gcr-prompt.c
+++ b/gcr/gcr-prompt.c
@@ -210,6 +210,10 @@ gcr_prompt_default_init (GcrPromptIface *iface)
* The caller window indicates to the prompt which window is prompting the
* user. The prompt may choose to ignore this information or use it in whatever
* way it sees fit.
+ *
+ * In X11, this will be a stringified version of the XWindow handle; in
+ * Wayland this is the result of an export using the XDG foreign
+ * protocol.
*/
g_object_interface_install_property (iface,
g_param_spec_string ("caller-window", "Caller window", "Window ID of
application window requesting prompt",
diff --git a/ui/gcr-prompt-dialog.c b/ui/gcr-prompt-dialog.c
index f623df1..9646069 100644
--- a/ui/gcr-prompt-dialog.c
+++ b/ui/gcr-prompt-dialog.c
@@ -126,14 +126,54 @@ G_DEFINE_TYPE_WITH_CODE (GcrPromptDialog, gcr_prompt_dialog, GTK_TYPE_DIALOG,
G_IMPLEMENT_INTERFACE (GCR_TYPE_PROMPT, gcr_prompt_dialog_prompt_iface);
);
+#ifdef GDK_WINDOWING_X11
+static gboolean
+update_transient_for_x11 (GcrPromptDialog *self, GdkWindow *window)
+{
+ gint64 handle;
+ gchar *end;
+ GdkDisplay *display;
+ GdkWindow *transient_for;
+
+ handle = g_ascii_strtoll (self->pv->caller_window, &end, 10);
+ if (!end || *end != '\0') {
+ g_warning ("couldn't parse caller-window property: %s", self->pv->caller_window);
+ return FALSE;
+ }
+
+ display = gtk_widget_get_display (GTK_WIDGET (self));
+ transient_for = gdk_x11_window_foreign_new_for_display (display, (Window)handle);
+ if (transient_for == NULL) {
+ g_warning ("caller-window property doesn't represent a window on current display: %s",
+ self->pv->caller_window);
+ return FALSE;
+
+ gdk_window_set_transient_for (window, transient_for);
+ g_object_unref (transient_for);
+ return TRUE;
+}
+#endif
+
+#ifdef GDK_WINDOWING_WAYLAND
+static gboolean
+update_transient_for_wl (GcrPromptDialog *self, GdkWindow *window)
+{
+ if (gdk_wayland_window_set_transient_for_exported (window, self->pv->caller_window)) {
+ g_debug ("Succesfully set transient for WL window %s", self->pv->caller_window);
+ return TRUE;
+ }
+
+ g_warning ("caller-window property doesn't represent a window on current display: %s",
+ self->pv->caller_window);
+ return FALSE;
+}
+#endif
+
static void
update_transient_for (GcrPromptDialog *self)
{
- GdkDisplay *display;
- GdkWindow *transient_for = NULL;
GdkWindow *window;
- gint64 handle;
- gchar *end;
+ gboolean success = FALSE;
if (self->pv->caller_window == NULL || g_str_equal (self->pv->caller_window, "")) {
gtk_window_set_modal (GTK_WINDOW (self), FALSE);
@@ -145,22 +185,17 @@ update_transient_for (GcrPromptDialog *self)
return;
#ifdef GDK_WINDOWING_X11
- handle = g_ascii_strtoll (self->pv->caller_window, &end, 10);
- if (!end || *end != '\0') {
- g_warning ("couldn't parse caller-window property: %s", self->pv->caller_window);
- return;
- }
+ if (!success)
+ success |= update_transient_for_x11 ();
+#endif
+#ifdef GDK_WINDOWING_WAYLAND
+ if (!success)
+ success |= update_transient_for_wl ();
+#endif
- display = gtk_widget_get_display (GTK_WIDGET (self));
- transient_for = gdk_x11_window_foreign_new_for_display (display, (Window)handle);
- if (transient_for == NULL) {
- g_warning ("caller-window property doesn't represent a window on current display: %s",
- self->pv->caller_window);
- } else {
- gdk_window_set_transient_for (window, transient_for);
- g_object_unref (transient_for);
+ if (!success) {
+ g_warning ("Couldn't set transient to caller window");
}
-#endif
gtk_window_set_modal (GTK_WINDOW (self), TRUE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]