phosh-arch/gtk3-mobile/headerbar-Use-a-back-button-in-dialogs-on-mobile.patch

102 lines
3.6 KiB
Diff
Raw Normal View History

2024-08-13 17:17:11 +02:00
From: Adrien Plazas <kekun.plazas@laposte.net>
Date: Thu, 11 Jul 2019 10:44:14 +0200
Subject: headerbar: Use a back button in dialogs on mobile
This will allow to drop the close buttons and make the dialogs and
transient windows look like proper mobile dialogs.
---
gtk/gtkheaderbar.c | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index 0ef94e3..9a4833a 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -30,6 +30,7 @@
#include "gtkwindowprivate.h"
#include "gtkwidgetprivate.h"
#include "gtkcontainerprivate.h"
+#include "gtkdialog.h"
#include "a11y/gtkheaderbaraccessible.h"
#include <string.h>
@@ -88,6 +89,7 @@ struct _GtkHeaderBarPrivate
GtkWidget *titlebar_icon;
GtkCssGadget *gadget;
+ GSettings *settings;
};
typedef struct _Child Child;
@@ -280,6 +282,7 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
GMenuModel *menu;
gboolean shown_by_shell;
gboolean is_sovereign_window;
+ gboolean is_mobile_dialog;
toplevel = gtk_widget_get_toplevel (widget);
if (!gtk_widget_is_toplevel (toplevel))
@@ -310,7 +313,15 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
"gtk-decoration-layout", &layout_desc,
NULL);
- if (priv->decoration_layout_set)
+ is_mobile_dialog = GTK_IS_DIALOG (toplevel) ||
+ (GTK_IS_WINDOW (toplevel) && !!gtk_window_get_transient_for (GTK_WINDOW (toplevel)));
+
+ if (is_mobile_dialog && _gtk_get_is_phone ())
+ {
+ g_free (layout_desc);
+ layout_desc = g_strdup ("back:");
+ }
+ else if (priv->decoration_layout_set)
{
g_free (layout_desc);
layout_desc = g_strdup (priv->decoration_layout);
@@ -457,6 +468,23 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
if (GTK_IS_ACCESSIBLE (accessible))
atk_object_set_name (accessible, _("Close"));
}
+ else if (strcmp (t[j], "back") == 0 &&
+ gtk_window_get_deletable (window))
+ {
+ button = gtk_button_new ();
+ gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
+ image = gtk_image_new_from_icon_name ("go-previous-symbolic", GTK_ICON_SIZE_BUTTON);
+ g_object_set (image, "use-fallback", TRUE, NULL);
+ gtk_container_add (GTK_CONTAINER (button), image);
+ gtk_widget_set_can_focus (button, TRUE);
+ gtk_widget_show_all (button);
+ g_signal_connect_swapped (button, "clicked",
+ G_CALLBACK (gtk_window_close), window);
+
+ accessible = gtk_widget_get_accessible (button);
+ if (GTK_IS_ACCESSIBLE (accessible))
+ atk_object_set_name (accessible, _("Back"));
+ }
if (button)
{
@@ -1514,6 +1542,8 @@ gtk_header_bar_destroy (GtkWidget *widget)
priv->titlebar_end_separator = NULL;
}
+ g_clear_object (&priv->settings);
+
GTK_WIDGET_CLASS (gtk_header_bar_parent_class)->destroy (widget);
}
@@ -2154,6 +2184,12 @@ gtk_header_bar_init (GtkHeaderBar *bar)
NULL,
NULL);
+ priv->settings = _gtk_get_purism_settings ();
+
+ if (priv->settings)
+ g_signal_connect_object (priv->settings, "changed::is-phone",
+ G_CALLBACK (_gtk_header_bar_update_window_buttons), bar,
+ G_CONNECT_SWAPPED);
}
static void