[gnome-packagekit/wip/mak/fix-smallscreen] Fix smallscreen support




commit 924f44c712cc028847ccf4ba0114de8536d6aea8
Author: Matthias Klumpp <matthias tenstral net>
Date:   Wed Jul 20 21:27:47 2022 +0200

    Fix smallscreen support
    
    A bad int -> uint conversion was leading to any screen being recognized
    as "small screen" and therefore the application window was always
    maximized.
    This patch fixes the problem and also gets rid of some deprecated API
    use.
    
    Resolves: #3

 meson.build      |  2 +-
 src/gpk-common.c | 38 ++++++++++++++++++++++----------------
 src/gpk-common.h |  4 ++--
 3 files changed, 25 insertions(+), 19 deletions(-)
---
diff --git a/meson.build b/meson.build
index 1c35b1d4..d06bde93 100644
--- a/meson.build
+++ b/meson.build
@@ -80,7 +80,7 @@ foreach arg: test_link_args
 endforeach
 
 gio = dependency('gio-2.0', version : '>= 2.25.9')
-gtk = dependency('gtk+-3.0', version : '>= 3.15.3')
+gtk = dependency('gtk+-3.0', version : '>= 3.22')
 packagekit = dependency('packagekit-glib2', version : '>= 0.9.1')
 libm = cc.find_library('libm', required: false)
 
diff --git a/src/gpk-common.c b/src/gpk-common.c
index 9ea02dc0..53f64080 100644
--- a/src/gpk-common.c
+++ b/src/gpk-common.c
@@ -72,29 +72,34 @@ pk_strv_to_ptr_array (gchar **array)
 }
 
 gboolean
-gpk_window_set_size_request (GtkWindow *window, guint width, guint height)
+gpk_window_set_size_request (GtkWindow *window, gint width, gint height)
 {
 #ifdef PK_BUILD_SMALL_FORM_FACTOR
-       GdkScreen *screen;
-       guint screen_w;
-       guint screen_h;
-       guint percent_w;
-       guint percent_h;
+       GdkDisplay *display;
+       GdkMonitor *monitor;
+       GdkRectangle workarea;
+       guint win_w;
+       guint win_h;
+       gdouble percent_scr;
 
        /* check for tiny screen, like for instance a OLPC or EEE */
-       screen = gdk_screen_get_default ();
-       screen_w = gdk_screen_get_width (screen);
-       screen_h = gdk_screen_get_height (screen);
+       display = gdk_display_get_default ();
+       monitor = gdk_display_get_primary_monitor (display);
+       if (monitor == NULL) {
+               g_debug ("no primary monitor was found, unable to determine small screen support");
+               goto out_normal_size;
+       }
 
        /* find percentage of screen area */
-       percent_w = (width * 100) / screen_w;
-       percent_h = (height * 100) / screen_h;
-       g_debug ("window coverage x:%i%% y:%i%%", percent_w, percent_h);
+       gdk_monitor_get_workarea (monitor, &workarea);
+       win_w = (width > 0)? width : workarea.width;
+       win_h = (height > 0)? height : workarea.height;
+       percent_scr = (100.0 / (workarea.width * workarea.height)) * (win_w * win_h);
 
-       if (percent_w > GPK_SMALL_FORM_FACTOR_SCREEN_PERCENT ||
-           percent_h > GPK_SMALL_FORM_FACTOR_SCREEN_PERCENT) {
+       g_debug ("window coverage %.2f%%", percent_scr);
+       if (percent_scr > GPK_SMALL_FORM_FACTOR_SCREEN_PERCENT) {
                g_debug ("using small form factor mode as %ix%i and requested %ix%i",
-                          screen_w, screen_h, width, height);
+                          workarea.width, workarea.height, width, height);
                gtk_window_maximize (window);
                small_form_factor_mode = TRUE;
                goto out;
@@ -104,8 +109,9 @@ gpk_window_set_size_request (GtkWindow *window, guint width, guint height)
        if (width == 0 || height == 0)
                goto out;
 #endif
+out_normal_size:
        /* normal size laptop panel */
-       g_debug ("using native mode: %ux%u", width, height);
+       g_debug ("using native mode: %ix%i", width, height);
        gtk_window_set_default_size (window, width, height);
        small_form_factor_mode = FALSE;
 out:
diff --git a/src/gpk-common.h b/src/gpk-common.h
index ed98f460..aa0744e2 100644
--- a/src/gpk-common.h
+++ b/src/gpk-common.h
@@ -68,8 +68,8 @@ gboolean       gpk_check_privileged_user              (const gchar    *application_name,
                                                         gboolean        show_ui);
 gchar          *gpk_strv_join_locale                   (gchar          **array);
 gboolean        gpk_window_set_size_request            (GtkWindow      *window,
-                                                        guint           width,
-                                                        guint           height);
+                                                        gint            width,
+                                                        gint            height);
 gboolean        gpk_window_set_parent_xid              (GtkWindow      *window,
                                                         guint32         xid);
 GPtrArray      *pk_strv_to_ptr_array                   (gchar          **array)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]