shell-global: Get UI scaling factor from mutter

Let mutter determine the UI scale, while taking things like monitor
layout mode into consideration.

https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
Jonas Ådahl 2017-03-31 17:03:23 +08:00
parent 32ea7d763a
commit 082bc20bb9

View File

@ -22,6 +22,7 @@
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <gio/gio.h> #include <gio/gio.h>
#include <girepository.h> #include <girepository.h>
#include <meta/meta-backend.h>
#include <meta/display.h> #include <meta/display.h>
#include <meta/util.h> #include <meta/util.h>
#include <meta/meta-shaped-texture.h> #include <meta/meta-shaped-texture.h>
@ -833,34 +834,38 @@ global_stage_after_swap (gpointer data)
return TRUE; return TRUE;
} }
static void static void
update_scale_factor (GtkSettings *settings, update_scaling_factor (ShellGlobal *global,
GParamSpec *pspec, MetaBackend *backend)
gpointer data)
{ {
ShellGlobal *global = SHELL_GLOBAL (data);
ClutterStage *stage = CLUTTER_STAGE (global->stage); ClutterStage *stage = CLUTTER_STAGE (global->stage);
StThemeContext *context = st_theme_context_get_for_stage (stage); StThemeContext *context = st_theme_context_get_for_stage (stage);
GValue value = G_VALUE_INIT; int scaling_factor;
g_value_init (&value, G_TYPE_INT); scaling_factor = meta_backend_get_ui_scaling_factor (backend);
if (gdk_screen_get_setting (global->gdk_screen, "gdk-window-scaling-factor", &value))
{ g_object_set (context, "scale-factor", scaling_factor, NULL);
g_object_set (context, "scale-factor", g_value_get_int (&value), NULL);
if (meta_is_wayland_compositor ()) if (meta_is_wayland_compositor ())
{ {
GtkSettings *settings = gtk_settings_get_default ();
int xft_dpi; int xft_dpi;
g_object_get (settings, "gtk-xft-dpi", &xft_dpi, NULL);
g_object_get (settings, "gtk-xft-dpi", &xft_dpi, NULL);
g_object_set (clutter_settings_get_default (), "font-dpi", xft_dpi, NULL); g_object_set (clutter_settings_get_default (), "font-dpi", xft_dpi, NULL);
} }
}
/* Make sure clutter and gdk scaling stays disabled */ /* Make sure clutter and gdk scaling stays disabled */
gdk_x11_display_set_window_scale (gdk_display_get_default (), 1); gdk_x11_display_set_window_scale (gdk_display_get_default (), 1);
} }
static void
ui_scaling_factor_changed (MetaBackend *backend,
ShellGlobal *global)
{
update_scaling_factor (global, backend);
}
/* This is an IBus workaround. The flow of events with IBus is that every time /* This is an IBus workaround. The flow of events with IBus is that every time
* it gets gets a key event, it: * it gets gets a key event, it:
* *
@ -964,6 +969,8 @@ void
_shell_global_set_plugin (ShellGlobal *global, _shell_global_set_plugin (ShellGlobal *global,
MetaPlugin *plugin) MetaPlugin *plugin)
{ {
MetaBackend *backend;
g_return_if_fail (SHELL_IS_GLOBAL (global)); g_return_if_fail (SHELL_IS_GLOBAL (global));
g_return_if_fail (global->plugin == NULL); g_return_if_fail (global->plugin == NULL);
@ -1044,18 +1051,15 @@ _shell_global_set_plugin (ShellGlobal *global,
g_signal_connect (global->meta_display, "notify::focus-window", g_signal_connect (global->meta_display, "notify::focus-window",
G_CALLBACK (focus_window_changed), global); G_CALLBACK (focus_window_changed), global);
/* gdk-window-scaling-factor is not exported to gtk-settings backend = meta_get_backend ();
* because it is handled inside gdk, so we use gtk-xft-dpi instead g_signal_connect (backend, "ui-scaling-factor-changed",
* which also changes when the scale factor changes. G_CALLBACK (ui_scaling_factor_changed), global);
*/
g_signal_connect (gtk_settings_get_default (), "notify::gtk-xft-dpi",
G_CALLBACK (update_scale_factor), global);
gdk_event_handler_set (gnome_shell_gdk_event_handler, global, NULL); gdk_event_handler_set (gnome_shell_gdk_event_handler, global, NULL);
global->focus_manager = st_focus_manager_get_for_stage (global->stage); global->focus_manager = st_focus_manager_get_for_stage (global->stage);
update_scale_factor (gtk_settings_get_default (), NULL, global); update_scaling_factor (global, meta_get_backend ());
} }
GjsContext * GjsContext *