Commit 1f7a162a authored by Georges Basile Stavracas Neto's avatar Georges Basile Stavracas Neto
Browse files

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
parent 6d4b2dee
......@@ -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: */
......@@ -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);
......
......@@ -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",
......@@ -731,6 +732,31 @@ gs_shell_main_window_mapped_cb (GtkWidget *widget, GsShell *shell)
(guint) gtk_widget_get_scale_factor (widget));
}
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,
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment