Skip to content

Commit

Permalink
Merge pull request #33 from BuddiesOfBudgie/scaling
Browse files Browse the repository at this point in the history
GNOME 47 Scaling
  • Loading branch information
fossfreedom authored Sep 26, 2024
2 parents 022fb54 + 675bd38 commit 263b41a
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 3 deletions.
8 changes: 8 additions & 0 deletions data/dbus-interfaces/org.gnome.Mutter.X11.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE node PUBLIC
'-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'
'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>
<node>
<interface name="org.gnome.Mutter.X11">
<property name="UiScalingFactor" type="i" access="readwrite" />
</interface>
</node>
7 changes: 7 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
98 changes: 95 additions & 3 deletions src/x11/meta-x11-display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand All @@ -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)
{
Expand All @@ -113,13 +130,68 @@ 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)
{
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);
}

static void
update_ui_scaling_factor (MetaX11Display *x11_display)
{
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);
}

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)
Expand Down Expand Up @@ -1112,6 +1184,23 @@ on_window_visibility_updated (MetaDisplay *display,
meta_x11_display_increment_focus_sentinel (x11_display);
}

static void
initialize_dbus_interface (MetaX11Display *x11_display)
{
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);
}

/**
* meta_x11_display_new:
*
Expand Down Expand Up @@ -1144,7 +1233,7 @@ meta_x11_display_new (MetaDisplay *display,
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);

MetaSettings *settings = meta_backend_get_settings (backend);
/* A list of all atom names, so that we can intern them in one go. */
const char *atom_names[] = {
#define item(x) #x,
Expand Down Expand Up @@ -1213,6 +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;
initialize_dbus_interface (x11_display);

/* here we use XDisplayName which is what the user
* probably put in, vs. DisplayString(display) which is
Expand Down Expand Up @@ -1282,7 +1372,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, &timestamp);
x11_display->timestamp = timestamp;
Expand Down Expand Up @@ -1814,6 +1904,8 @@ on_monitors_changed_internal (MetaMonitorManager *monitor_manager,
}

x11_display->has_xinerama_indices = FALSE;

update_ui_scaling_factor (x11_display);
}

void
Expand Down

0 comments on commit 263b41a

Please sign in to comment.