Skip to content

Commit 982a89b

Browse files
vkarehraveit65
authored andcommitted
Scale OSD size correctly on HiDPI displays (#212)
Also fix build warnings on xsettings
1 parent a7700a9 commit 982a89b

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

plugins/common/msd-osd-window.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct MsdOsdWindowPrivate
5353
guint hide_timeout_id;
5454
guint fade_timeout_id;
5555
double fade_out_alpha;
56+
gint scale_factor;
5657
};
5758

5859
enum {
@@ -422,13 +423,16 @@ msd_osd_window_is_composited (MsdOsdWindow *window)
422423
* @window: a #MsdOsdWindow
423424
*
424425
* Return value: TRUE if the @window's idea of being composited matches whether
425-
* its current screen is actually composited.
426+
* its current screen is actually composited, and whether the scale factor has
427+
* not changed since last draw.
426428
*/
427429
gboolean
428430
msd_osd_window_is_valid (MsdOsdWindow *window)
429431
{
430432
GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (window));
431-
return gdk_screen_is_composited (screen) == window->priv->is_composited;
433+
gint scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (window));
434+
return gdk_screen_is_composited (screen) == window->priv->is_composited
435+
&& scale_factor == window->priv->scale_factor;
432436
}
433437

434438
static void
@@ -441,6 +445,7 @@ msd_osd_window_init (MsdOsdWindow *window)
441445
screen = gtk_widget_get_screen (GTK_WIDGET (window));
442446

443447
window->priv->is_composited = gdk_screen_is_composited (screen);
448+
window->priv->scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (window));
444449

445450
if (window->priv->is_composited) {
446451
gdouble scalew, scaleh, scale;
@@ -453,16 +458,16 @@ msd_osd_window_init (MsdOsdWindow *window)
453458
gtk_style_context_add_class (style, "window-frame");
454459

455460
/* assume 130x130 on a 640x480 display and scale from there */
456-
scalew = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / 640.0;
457-
scaleh = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / 480.0;
461+
scalew = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / (640.0 * window->priv->scale_factor);
462+
scaleh = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / (480.0 * window->priv->scale_factor);
458463
scale = MIN (scalew, scaleh);
459464
size = 130 * MAX (1, scale);
460465

461466
gtk_window_set_default_size (GTK_WINDOW (window), size, size);
462467

463468
window->priv->fade_out_alpha = 1.0;
464469
} else {
465-
gtk_container_set_border_width (GTK_CONTAINER (window), 12);
470+
gtk_container_set_border_width (GTK_CONTAINER (window), 12);
466471
}
467472
}
468473

plugins/xsettings/msd-xsettings-manager.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ scale_change_workarounds (MateXSettingsManager *manager, int new_scale)
542542
wm_common_update_window();
543543
gchar *wm = wm_common_get_current_window_manager ();
544544
if (g_strcmp0 (wm, WM_COMMON_MARCO) == 0) {
545-
const gchar * const marco[] = {"marco", "--replace", NULL};
545+
gchar *marco[3] = {"marco", "--replace", NULL};
546546
if (!g_spawn_async (NULL, marco, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error)) {
547547
g_warning ("There was a problem restarting marco: %s", error->message);
548548
g_clear_error (&error);
@@ -554,7 +554,7 @@ scale_change_workarounds (MateXSettingsManager *manager, int new_scale)
554554
/* FIXME: The ideal scenario would be for mate-panel to respect window scaling and thus
555555
* resize itself. Currently this is not happening, so msd restarts it when the window
556556
* scaling factor changes so that it's visually correct. */
557-
const gchar * const mate_panel[] = {"killall", "mate-panel", NULL};
557+
gchar *mate_panel[3] = {"killall", "mate-panel", NULL};
558558
if (!g_spawn_async (NULL, mate_panel, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error)) {
559559
g_warning ("There was a problem restarting mate-panel: %s", error->message);
560560
g_clear_error (&error);

0 commit comments

Comments
 (0)