phosh-arch/gtk3-mobile/messagedialog-Set-orientation-based-on-device.patch

235 lines
12 KiB
Diff
Raw Normal View History

2024-08-13 17:17:11 +02:00
From: Adrien Plazas <kekun.plazas@laposte.net>
Date: Mon, 24 Jun 2019 14:49:07 +0200
Subject: messagedialog: Set orientation based on device
This makes the dialog work better with horizontally constrained screens.
---
gtk/gtkmessagedialog.c | 39 ++++++++++++++++++++++++
gtk/theme/Adwaita/_common.scss | 22 +++++++++++--
gtk/theme/Adwaita/gtk-contained-dark.css | 12 ++++++--
gtk/theme/Adwaita/gtk-contained.css | 12 ++++++--
gtk/theme/HighContrast/gtk-contained-inverse.css | 12 ++++++--
gtk/theme/HighContrast/gtk-contained.css | 12 ++++++--
6 files changed, 95 insertions(+), 14 deletions(-)
diff --git a/gtk/gtkmessagedialog.c b/gtk/gtkmessagedialog.c
index e70c820..e3a6659 100644
--- a/gtk/gtkmessagedialog.c
+++ b/gtk/gtkmessagedialog.c
@@ -36,6 +36,7 @@
#include "gtkimage.h"
#include "gtkintl.h"
#include "gtkprivate.h"
+#include "gtkorientable.h"
#include "gtktypebuiltins.h"
/**
@@ -108,6 +109,8 @@ struct _GtkMessageDialogPrivate
guint has_primary_markup : 1;
guint has_secondary_text : 1;
guint message_type : 3;
+
+ GSettings *settings;
};
static void gtk_message_dialog_style_updated (GtkWidget *widget);
@@ -144,6 +147,31 @@ G_DEFINE_TYPE_WITH_CODE (GtkMessageDialog, gtk_message_dialog, GTK_TYPE_DIALOG,
static GtkBuildableIface *parent_buildable_iface;
+static void
+update_orientation (GtkMessageDialog *dialog)
+{
+ GtkWidget *action_area;
+
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
+G_GNUC_END_IGNORE_DEPRECATIONS
+
+ if (_gtk_get_is_phone ())
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area), GTK_ORIENTATION_VERTICAL);
+ else
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area), GTK_ORIENTATION_HORIZONTAL);
+}
+
+static void
+gtk_message_dialog_destroy (GtkWidget *widget)
+{
+ GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG (widget);
+
+ g_clear_object (&dialog->priv->settings);
+
+ GTK_WIDGET_CLASS (gtk_message_dialog_parent_class)->destroy (widget);
+}
+
static void
gtk_message_dialog_buildable_interface_init (GtkBuildableIface *iface)
{
@@ -162,6 +190,7 @@ gtk_message_dialog_class_init (GtkMessageDialogClass *class)
gobject_class = G_OBJECT_CLASS (class);
widget_class->style_updated = gtk_message_dialog_style_updated;
+ widget_class->destroy = gtk_message_dialog_destroy;
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_ALERT);
@@ -327,6 +356,16 @@ gtk_message_dialog_init (GtkMessageDialog *dialog)
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
G_GNUC_END_IGNORE_DEPRECATIONS
+
+ priv->settings = _gtk_get_purism_settings ();
+
+ if (priv->settings)
+ g_signal_connect_object (priv->settings, "changed::is-phone",
+ G_CALLBACK (update_orientation), dialog,
+ G_CONNECT_SWAPPED);
+
+ update_orientation (dialog);
+
gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_EXPAND);
settings = gtk_widget_get_settings (GTK_WIDGET (dialog));
diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss
index e40e429..b6609f9 100644
--- a/gtk/theme/Adwaita/_common.scss
+++ b/gtk/theme/Adwaita/_common.scss
@@ -3987,10 +3987,13 @@ messagedialog { // Message Dialog styling
.dialog-action-area button {
padding: 10px 14px; // labels are not vertically centered on message dialog, this is a workaround
- border-right-style: none;
- border-bottom-style: none;
border-radius: 0;
-gtk-outline-radius: 0;
+ }
+
+ .dialog-action-area.horizontal button {
+ border-right-style: none;
+ border-bottom-style: none;
&:first-child {
border-left-style: none;
@@ -4003,6 +4006,21 @@ messagedialog { // Message Dialog styling
-gtk-outline-bottom-right-radius: $button_radius + 2;
}
}
+
+ .dialog-action-area.vertical button {
+ border-right-style: none;
+ border-left-style: none;
+ border-radius: 0;
+ -gtk-outline-radius: 0;
+
+ &:last-child {
+ border-bottom-style: none;
+ border-bottom-left-radius: $button_radius + 2;
+ border-bottom-right-radius: $button_radius + 2;
+ -gtk-outline-bottom-left-radius: $button_radius + 2;
+ -gtk-outline-bottom-right-radius: $button_radius + 2;
+ }
+ }
}
}
diff --git a/gtk/theme/Adwaita/gtk-contained-dark.css b/gtk/theme/Adwaita/gtk-contained-dark.css
index 3cd917d..76e816b 100644
--- a/gtk/theme/Adwaita/gtk-contained-dark.css
+++ b/gtk/theme/Adwaita/gtk-contained-dark.css
@@ -1602,11 +1602,17 @@ messagedialog .titlebar { min-height: 20px; background-image: none; background-c
messagedialog.csd.background { border-bottom-left-radius: 9px; border-bottom-right-radius: 9px; }
-messagedialog.csd .dialog-action-area button { padding: 10px 14px; border-right-style: none; border-bottom-style: none; border-radius: 0; -gtk-outline-radius: 0; }
+messagedialog.csd .dialog-action-area button { padding: 10px 14px; border-radius: 0; -gtk-outline-radius: 0; }
-messagedialog.csd .dialog-action-area button:first-child { border-left-style: none; border-bottom-left-radius: 7px; -gtk-outline-bottom-left-radius: 7px; }
+messagedialog.csd .dialog-action-area.horizontal button { border-right-style: none; border-bottom-style: none; }
-messagedialog.csd .dialog-action-area button:last-child { border-bottom-right-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
+messagedialog.csd .dialog-action-area.horizontal button:first-child { border-left-style: none; border-bottom-left-radius: 7px; -gtk-outline-bottom-left-radius: 7px; }
+
+messagedialog.csd .dialog-action-area.horizontal button:last-child { border-bottom-right-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
+
+messagedialog.csd .dialog-action-area.vertical button { border-right-style: none; border-left-style: none; border-radius: 0; -gtk-outline-radius: 0; }
+
+messagedialog.csd .dialog-action-area.vertical button:last-child { border-bottom-style: none; border-bottom-left-radius: 7px; border-bottom-right-radius: 7px; -gtk-outline-bottom-left-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
filechooser .dialog-action-box { border-top: 1px solid #1b1b1b; }
diff --git a/gtk/theme/Adwaita/gtk-contained.css b/gtk/theme/Adwaita/gtk-contained.css
index 4eff74f..ffbd2ae 100644
--- a/gtk/theme/Adwaita/gtk-contained.css
+++ b/gtk/theme/Adwaita/gtk-contained.css
@@ -1618,11 +1618,17 @@ messagedialog .titlebar { min-height: 20px; background-image: none; background-c
messagedialog.csd.background { border-bottom-left-radius: 9px; border-bottom-right-radius: 9px; }
-messagedialog.csd .dialog-action-area button { padding: 10px 14px; border-right-style: none; border-bottom-style: none; border-radius: 0; -gtk-outline-radius: 0; }
+messagedialog.csd .dialog-action-area button { padding: 10px 14px; border-radius: 0; -gtk-outline-radius: 0; }
-messagedialog.csd .dialog-action-area button:first-child { border-left-style: none; border-bottom-left-radius: 7px; -gtk-outline-bottom-left-radius: 7px; }
+messagedialog.csd .dialog-action-area.horizontal button { border-right-style: none; border-bottom-style: none; }
-messagedialog.csd .dialog-action-area button:last-child { border-bottom-right-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
+messagedialog.csd .dialog-action-area.horizontal button:first-child { border-left-style: none; border-bottom-left-radius: 7px; -gtk-outline-bottom-left-radius: 7px; }
+
+messagedialog.csd .dialog-action-area.horizontal button:last-child { border-bottom-right-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
+
+messagedialog.csd .dialog-action-area.vertical button { border-right-style: none; border-left-style: none; border-radius: 0; -gtk-outline-radius: 0; }
+
+messagedialog.csd .dialog-action-area.vertical button:last-child { border-bottom-style: none; border-bottom-left-radius: 7px; border-bottom-right-radius: 7px; -gtk-outline-bottom-left-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
filechooser .dialog-action-box { border-top: 1px solid #cdc7c2; }
diff --git a/gtk/theme/HighContrast/gtk-contained-inverse.css b/gtk/theme/HighContrast/gtk-contained-inverse.css
index 5a2cf09..7e9f8ec 100644
--- a/gtk/theme/HighContrast/gtk-contained-inverse.css
+++ b/gtk/theme/HighContrast/gtk-contained-inverse.css
@@ -1682,11 +1682,17 @@ messagedialog .titlebar { min-height: 20px; background-image: none; background-c
messagedialog.csd.background { border-bottom-left-radius: 9px; border-bottom-right-radius: 9px; }
-messagedialog.csd .dialog-action-area button { padding: 10px 14px; border-right-style: none; border-bottom-style: none; border-radius: 0; -gtk-outline-radius: 0; }
+messagedialog.csd .dialog-action-area button { padding: 10px 14px; border-radius: 0; -gtk-outline-radius: 0; }
-messagedialog.csd .dialog-action-area button:first-child { border-left-style: none; border-bottom-left-radius: 7px; -gtk-outline-bottom-left-radius: 7px; }
+messagedialog.csd .dialog-action-area.horizontal button { border-right-style: none; border-bottom-style: none; }
-messagedialog.csd .dialog-action-area button:last-child { border-bottom-right-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
+messagedialog.csd .dialog-action-area.horizontal button:first-child { border-left-style: none; border-bottom-left-radius: 7px; -gtk-outline-bottom-left-radius: 7px; }
+
+messagedialog.csd .dialog-action-area.horizontal button:last-child { border-bottom-right-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
+
+messagedialog.csd .dialog-action-area.vertical button { border-right-style: none; border-left-style: none; border-radius: 0; -gtk-outline-radius: 0; }
+
+messagedialog.csd .dialog-action-area.vertical button:last-child { border-bottom-style: none; border-bottom-left-radius: 7px; border-bottom-right-radius: 7px; -gtk-outline-bottom-left-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
filechooser .dialog-action-box { border-top: 1px solid #686868; }
diff --git a/gtk/theme/HighContrast/gtk-contained.css b/gtk/theme/HighContrast/gtk-contained.css
index ba598cc..20fbd2c 100644
--- a/gtk/theme/HighContrast/gtk-contained.css
+++ b/gtk/theme/HighContrast/gtk-contained.css
@@ -1698,11 +1698,17 @@ messagedialog .titlebar { min-height: 20px; background-image: none; background-c
messagedialog.csd.background { border-bottom-left-radius: 9px; border-bottom-right-radius: 9px; }
-messagedialog.csd .dialog-action-area button { padding: 10px 14px; border-right-style: none; border-bottom-style: none; border-radius: 0; -gtk-outline-radius: 0; }
+messagedialog.csd .dialog-action-area button { padding: 10px 14px; border-radius: 0; -gtk-outline-radius: 0; }
-messagedialog.csd .dialog-action-area button:first-child { border-left-style: none; border-bottom-left-radius: 7px; -gtk-outline-bottom-left-radius: 7px; }
+messagedialog.csd .dialog-action-area.horizontal button { border-right-style: none; border-bottom-style: none; }
-messagedialog.csd .dialog-action-area button:last-child { border-bottom-right-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
+messagedialog.csd .dialog-action-area.horizontal button:first-child { border-left-style: none; border-bottom-left-radius: 7px; -gtk-outline-bottom-left-radius: 7px; }
+
+messagedialog.csd .dialog-action-area.horizontal button:last-child { border-bottom-right-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
+
+messagedialog.csd .dialog-action-area.vertical button { border-right-style: none; border-left-style: none; border-radius: 0; -gtk-outline-radius: 0; }
+
+messagedialog.csd .dialog-action-area.vertical button:last-child { border-bottom-style: none; border-bottom-left-radius: 7px; border-bottom-right-radius: 7px; -gtk-outline-bottom-left-radius: 7px; -gtk-outline-bottom-right-radius: 7px; }
filechooser .dialog-action-box { border-top: 1px solid #877b6e; }