From fe8a2c3f2fb897e558869e7824bec4959ba547b0 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Sun, 22 Sep 2024 21:30:48 +0100 Subject: [PATCH 1/3] Create the new X11 scaling dbus interface that GSD 47 requires #32 This code creates the dbus interface allowing GSD to call the dbus API. There is now a new UIScalingFactor property. Next is to work out how BCC signals that a scaling change has occurred. --- data/dbus-interfaces/org.gnome.Mutter.X11.xml | 8 ++ src/meson.build | 7 ++ src/x11/meta-x11-display.c | 104 +++++++++++++++++- 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 data/dbus-interfaces/org.gnome.Mutter.X11.xml diff --git a/data/dbus-interfaces/org.gnome.Mutter.X11.xml b/data/dbus-interfaces/org.gnome.Mutter.X11.xml new file mode 100644 index 0000000000..3d3c8a42f8 --- /dev/null +++ b/data/dbus-interfaces/org.gnome.Mutter.X11.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/src/meson.build b/src/meson.build index 2fda6ba1f8..d58b2c3dd9 100644 --- a/src/meson.build +++ b/src/meson.build @@ -875,6 +875,13 @@ dbus_input_mapping_built_sources = gnome.gdbus_codegen('meta-dbus-input-mapping' ) mutter_built_sources += dbus_input_mapping_built_sources +dbus_x11_built_sources = gnome.gdbus_codegen('meta-dbus-x11', + join_paths(dbus_interfaces_dir, 'org.gnome.Mutter.X11.xml'), + interface_prefix: 'org.gnome.Mutter.', + namespace: 'MetaDBus', + ) +mutter_built_sources += dbus_x11_built_sources + if have_profiler mutter_sources += [ 'core/meta-profiler.c', diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index 729d8c0f80..6bd5a74fbd 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -71,7 +71,7 @@ #include "wayland/meta-xwayland-private.h" #endif -G_DEFINE_TYPE (MetaX11Display, meta_x11_display, G_TYPE_OBJECT) +#include "meta-dbus-x11.h" static GQuark quark_x11_display_logical_monitor_data = 0; @@ -80,6 +80,14 @@ typedef struct _MetaX11DisplayLogicalMonitorData int xinerama_index; } MetaX11DisplayLogicalMonitorData; +typedef struct _MetaX11DisplayPrivate +{ + MetaDBusX11 *dbus_api; + guint dbus_name_id; +} MetaX11DisplayPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE (MetaX11Display, meta_x11_display, G_TYPE_OBJECT) + static char *get_screen_name (Display *xdisplay, int number); @@ -92,6 +100,15 @@ static void unset_wm_check_hint (MetaX11Display *x11_display); static void prefs_changed_callback (MetaPreference pref, void *data); +static MetaBackend * +backend_from_x11_display (MetaX11Display *x11_display) +{ + MetaDisplay *display = meta_x11_display_get_display (x11_display); + MetaContext *context = meta_display_get_context (display); + + return meta_context_get_backend (context); +} + static void meta_x11_display_unmanage_windows (MetaX11Display *x11_display) { @@ -113,13 +130,72 @@ meta_x11_display_unmanage_windows (MetaX11Display *x11_display) g_list_free_full (windows, g_object_unref); } +static void +on_bus_acquired (GDBusConnection *connection, + const char *name, + gpointer user_data) +{ + g_warning("on_bus_acquired start"); + MetaX11Display *x11_display = user_data; + MetaX11DisplayPrivate *priv = + meta_x11_display_get_instance_private (x11_display); + + g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_api), + connection, + "/org/gnome/Mutter/X11", + NULL); + g_warning("on_bus_acquired end"); +} + +static void +update_ui_scaling_factor (MetaX11Display *x11_display) +{ + g_warning("update_ui_scaling_factor start"); + MetaX11DisplayPrivate *priv = + meta_x11_display_get_instance_private (x11_display); + MetaBackend *backend = backend_from_x11_display (x11_display); + MetaContext *context = meta_backend_get_context (backend); + int ui_scaling_factor = 1; + + switch (meta_context_get_compositor_type (context)) + { + case META_COMPOSITOR_TYPE_WAYLAND: + { +#ifdef HAVE_XWAYLAND + MetaWaylandCompositor *wayland_compositor = + meta_context_get_wayland_compositor (context); + MetaXWaylandManager *xwayland_manager = + &wayland_compositor->xwayland_manager; + + ui_scaling_factor = meta_xwayland_get_effective_scale (xwayland_manager); +#endif + break; + } + case META_COMPOSITOR_TYPE_X11: + { + MetaSettings *settings = meta_backend_get_settings (backend); + + ui_scaling_factor = meta_settings_get_ui_scaling_factor (settings); + break; + } + } + + meta_dbus_x11_set_ui_scaling_factor (priv->dbus_api, ui_scaling_factor); + g_warning("update_ui_scaling_factor emd"); +} + static void meta_x11_display_dispose (GObject *object) { MetaX11Display *x11_display = META_X11_DISPLAY (object); + MetaX11DisplayPrivate *priv = + meta_x11_display_get_instance_private (x11_display); x11_display->closing = TRUE; + g_clear_handle_id (&priv->dbus_name_id, g_bus_unown_name); + g_clear_object (&priv->dbus_api); + g_clear_pointer (&x11_display->alarm_filters, g_ptr_array_unref); if (x11_display->empty_region != None) @@ -1112,6 +1188,25 @@ on_window_visibility_updated (MetaDisplay *display, meta_x11_display_increment_focus_sentinel (x11_display); } +static void +initialize_dbus_interface (MetaX11Display *x11_display) +{ + g_warning("initialize_dbus_interface start"); + MetaX11DisplayPrivate *priv = + meta_x11_display_get_instance_private (x11_display); + + priv->dbus_api = meta_dbus_x11_skeleton_new (); + priv->dbus_name_id = + g_bus_own_name (G_BUS_TYPE_SESSION, + "org.gnome.Mutter.X11", + G_BUS_NAME_OWNER_FLAGS_NONE, + on_bus_acquired, + NULL, NULL, + x11_display, NULL); + update_ui_scaling_factor (x11_display); + g_warning("initialize_dbus_interface end"); +} + /** * meta_x11_display_new: * @@ -1144,7 +1239,9 @@ meta_x11_display_new (MetaDisplay *display, MetaBackend *backend = meta_get_backend (); MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); - + g_warning("aaaaa"); + MetaSettings *settings = meta_backend_get_settings (backend); + g_warning("bbbb"); /* A list of all atom names, so that we can intern them in one go. */ const char *atom_names[] = { #define item(x) #x, @@ -1213,6 +1310,9 @@ meta_x11_display_new (MetaDisplay *display, x11_display = g_object_new (META_TYPE_X11_DISPLAY, NULL); x11_display->gdk_display = gdk_display; x11_display->display = display; + g_warning("1"); + initialize_dbus_interface (x11_display); + g_warning("2"); /* here we use XDisplayName which is what the user * probably put in, vs. DisplayString(display) which is From ab00ad0a8e01fcfecb6dd52c00e4faea800cfffe Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Mon, 23 Sep 2024 19:51:38 +0100 Subject: [PATCH 2/3] Ensure update scaling is done when monitors are notified #32 --- src/x11/meta-x11-display.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index 6bd5a74fbd..e572eef84d 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -1382,7 +1382,7 @@ meta_x11_display_new (MetaDisplay *display, "monitors-changed-internal", G_CALLBACK (on_monitors_changed_internal), x11_display, - 0); + G_CONNECT_AFTER); init_leader_window (x11_display, ×tamp); x11_display->timestamp = timestamp; @@ -1914,6 +1914,8 @@ on_monitors_changed_internal (MetaMonitorManager *monitor_manager, } x11_display->has_xinerama_indices = FALSE; + + update_ui_scaling_factor (x11_display); } void From 675bd389d149e52a1be7bc8911ab810aacf56936 Mon Sep 17 00:00:00 2001 From: David Mohammed Date: Mon, 23 Sep 2024 19:55:35 +0100 Subject: [PATCH 3/3] Cleanup of code #32 --- src/x11/meta-x11-display.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index e572eef84d..4ca33cb9a5 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -135,7 +135,6 @@ on_bus_acquired (GDBusConnection *connection, const char *name, gpointer user_data) { - g_warning("on_bus_acquired start"); MetaX11Display *x11_display = user_data; MetaX11DisplayPrivate *priv = meta_x11_display_get_instance_private (x11_display); @@ -144,13 +143,11 @@ on_bus_acquired (GDBusConnection *connection, connection, "/org/gnome/Mutter/X11", NULL); - g_warning("on_bus_acquired end"); } static void update_ui_scaling_factor (MetaX11Display *x11_display) { - g_warning("update_ui_scaling_factor start"); MetaX11DisplayPrivate *priv = meta_x11_display_get_instance_private (x11_display); MetaBackend *backend = backend_from_x11_display (x11_display); @@ -181,7 +178,6 @@ update_ui_scaling_factor (MetaX11Display *x11_display) } meta_dbus_x11_set_ui_scaling_factor (priv->dbus_api, ui_scaling_factor); - g_warning("update_ui_scaling_factor emd"); } static void @@ -1191,7 +1187,6 @@ on_window_visibility_updated (MetaDisplay *display, static void initialize_dbus_interface (MetaX11Display *x11_display) { - g_warning("initialize_dbus_interface start"); MetaX11DisplayPrivate *priv = meta_x11_display_get_instance_private (x11_display); @@ -1204,7 +1199,6 @@ initialize_dbus_interface (MetaX11Display *x11_display) NULL, NULL, x11_display, NULL); update_ui_scaling_factor (x11_display); - g_warning("initialize_dbus_interface end"); } /** @@ -1239,9 +1233,7 @@ meta_x11_display_new (MetaDisplay *display, MetaBackend *backend = meta_get_backend (); MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); - g_warning("aaaaa"); MetaSettings *settings = meta_backend_get_settings (backend); - g_warning("bbbb"); /* A list of all atom names, so that we can intern them in one go. */ const char *atom_names[] = { #define item(x) #x, @@ -1310,9 +1302,7 @@ meta_x11_display_new (MetaDisplay *display, x11_display = g_object_new (META_TYPE_X11_DISPLAY, NULL); x11_display->gdk_display = gdk_display; x11_display->display = display; - g_warning("1"); initialize_dbus_interface (x11_display); - g_warning("2"); /* here we use XDisplayName which is what the user * probably put in, vs. DisplayString(display) which is