[gnome-software] Adapt header buttons on low resolution displays
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Adapt header buttons on low resolution displays
- Date: Wed, 6 Sep 2017 15:21:02 +0000 (UTC)
commit 1f7a162aa8deb0a1261bd3ca9780b75c42b0bfa7
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Sep 6 11:41:40 2017 -0300
Adapt header buttons on low resolution displays
The header buttons are the major offenders when dealing with low
resolution displays, and they render the window unresizable even
on views that can resize.
In order to detect that, this commit adds a new method to check
if the current display has a low resolution. We're considering
anything below 800x600 as low resolution right now. This assumption
can change as we see fit.
The header buttons are adapted on realize, when it is guaranteed
that the window is in a monitor, and the fix is making the views
buttons non-homogeneous.
https://bugzilla.gnome.org/show_bug.cgi?id=787366
lib/gs-utils.c | 25 +++++++++++++++++++++++++
lib/gs-utils.h | 1 +
src/gs-shell.c | 28 ++++++++++++++++++++++++++++
3 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index b126147..846da9c 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -47,6 +47,9 @@
#include "gs-utils.h"
#include "gs-plugin.h"
+#define LOW_RESOLUTION_WIDTH 800
+#define LOW_RESOLUTION_HEIGHT 600
+
/**
* gs_mkdir_parent:
* @path: A full pathname
@@ -999,4 +1002,26 @@ gs_utils_append_key_value (GString *str, gsize align_len,
g_string_append (str, "\n");
}
+/**
+ * gs_utils_is_low_resolution:
+ *
+ * Retrieves whether the primary monitor has a low resolution.
+ *
+ * Returns: %TRUE if the monitor has low resolution
+ **/
+gboolean
+gs_utils_is_low_resolution (GtkWidget *toplevel)
+{
+ GdkRectangle geometry;
+ GdkDisplay *display;
+ GdkMonitor *monitor;
+
+ display = gtk_widget_get_display (toplevel);
+ monitor = gdk_display_get_monitor_at_window (display, gtk_widget_get_window (toplevel));
+
+ gdk_monitor_get_geometry (monitor, &geometry);
+
+ return geometry.width < LOW_RESOLUTION_WIDTH || geometry.height < LOW_RESOLUTION_HEIGHT;
+}
+
/* vim: set noexpandtab: */
diff --git a/lib/gs-utils.h b/lib/gs-utils.h
index b92d2f8..b40a0d7 100644
--- a/lib/gs-utils.h
+++ b/lib/gs-utils.h
@@ -81,6 +81,7 @@ gboolean gs_utils_error_convert_gdbus (GError **perror);
gboolean gs_utils_error_convert_gdk_pixbuf(GError **perror);
gboolean gs_utils_error_convert_json_glib (GError **perror);
gboolean gs_utils_error_convert_appstream (GError **perror);
+gboolean gs_utils_is_low_resolution (GtkWidget *toplevel);
gchar *gs_utils_get_url_scheme (const gchar *url);
gchar *gs_utils_get_url_path (const gchar *url);
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 7a68492..9b21854 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -39,6 +39,7 @@
#include "gs-sources-dialog.h"
#include "gs-update-dialog.h"
#include "gs-update-monitor.h"
+#include "gs-utils.h"
static const gchar *page_name[] = {
"unknown",
@@ -732,6 +733,31 @@ gs_shell_main_window_mapped_cb (GtkWidget *widget, GsShell *shell)
}
static void
+gs_shell_main_window_realized_cb (GtkWidget *widget, GsShell *shell)
+{
+
+ GsShellPrivate *priv = gs_shell_get_instance_private (shell);
+
+ /* adapt the window for low resolution screens */
+ if (gs_utils_is_low_resolution (GTK_WIDGET (priv->main_window))) {
+ GtkWidget *buttonbox = GTK_WIDGET (gtk_builder_get_object (priv->builder,
"buttonbox_main"));
+
+ gtk_container_child_set (GTK_CONTAINER (buttonbox),
+ GTK_WIDGET (gtk_builder_get_object (priv->builder,
"button_all")),
+ "non-homogeneous", TRUE,
+ NULL);
+ gtk_container_child_set (GTK_CONTAINER (buttonbox),
+ GTK_WIDGET (gtk_builder_get_object (priv->builder,
"button_installed")),
+ "non-homogeneous", TRUE,
+ NULL);
+ gtk_container_child_set (GTK_CONTAINER (buttonbox),
+ GTK_WIDGET (gtk_builder_get_object (priv->builder,
"button_updates")),
+ "non-homogeneous", TRUE,
+ NULL);
+ }
+}
+
+static void
gs_shell_allow_updates_notify_cb (GsPluginLoader *plugin_loader,
GParamSpec *pspec,
GsShell *shell)
@@ -1701,6 +1727,8 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
priv->main_window = GTK_WINDOW (gtk_builder_get_object (priv->builder, "window_software"));
g_signal_connect (priv->main_window, "map",
G_CALLBACK (gs_shell_main_window_mapped_cb), shell);
+ g_signal_connect (priv->main_window, "realize",
+ G_CALLBACK (gs_shell_main_window_realized_cb), shell);
g_signal_connect (priv->main_window, "delete-event",
G_CALLBACK (main_window_closed_cb), shell);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]