diff options
author | lukefromdc <[email protected]> | 2024-03-27 19:40:18 -0400 |
---|---|---|
committer | lukefromdc <[email protected]> | 2024-05-26 14:00:01 -0400 |
commit | 1e8c08e51ea38d5faec5f352ea5d00c565a0a63d (patch) | |
tree | fc966c761e2a4c78bf42dc24103aaca73ff2c02c /capplets/appearance/appearance-font.c | |
parent | cf67b6a462ceeaddea84130789fa5e73fe598fdd (diff) | |
download | mate-control-center-1e8c08e51ea38d5faec5f352ea5d00c565a0a63d.tar.bz2 mate-control-center-1e8c08e51ea38d5faec5f352ea5d00c565a0a63d.tar.xz |
appearance in wayland: Support changing theme, icon theme, and fonts
*If we are in a wayland session, write the gtk theme and icon theme to both org.mate and org.gnome
*This changes wayland and xwayland themes simultaniously
*Under wayland, set the application and document fonts for both MATE and GNOME
*Otherwise some applications will ignore font changes set from the appearance capplet
*Only load GNOME interface gsettings when running under wayland
*fail gracefully if the gnome interface schema is not present
*Do not depend on it but use it if it is present to allow setting themes in compositors such as wayfire that use the GNOME gsettings values
Diffstat (limited to 'capplets/appearance/appearance-font.c')
-rw-r--r-- | capplets/appearance/appearance-font.c | 62 |
1 files changed, 57 insertions, 5 deletions
diff --git a/capplets/appearance/appearance-font.c b/capplets/appearance/appearance-font.c index 1c1d96d5..8e157676 100644 --- a/capplets/appearance/appearance-font.c +++ b/capplets/appearance/appearance-font.c @@ -421,20 +421,40 @@ dpi_from_pixels_and_mm (int pixels, int mm) } static double -get_dpi_from_x_server (void) +get_dpi_from_x_server_or_monitor (void) { GdkScreen *screen; + GdkDisplay *display; double dpi; screen = gdk_screen_get_default (); + display = gdk_display_get_default(); if (screen) { double width_dpi, height_dpi; - Screen *xscreen = gdk_x11_screen_get_xscreen (screen); + if (GDK_IS_X11_DISPLAY (display)) + { + Screen *xscreen = gdk_x11_screen_get_xscreen (screen); - width_dpi = dpi_from_pixels_and_mm (WidthOfScreen (xscreen), WidthMMOfScreen (xscreen)); - height_dpi = dpi_from_pixels_and_mm (HeightOfScreen (xscreen), HeightMMOfScreen (xscreen)); + width_dpi = dpi_from_pixels_and_mm (WidthOfScreen (xscreen), WidthMMOfScreen (xscreen)); + height_dpi = dpi_from_pixels_and_mm (HeightOfScreen (xscreen), HeightMMOfScreen (xscreen)); + } + else + { + GdkMonitor *monitor; + GdkRectangle geometry = {0}; + + /*FIXME: we have to use the main monitor for this + *which may not always be the leftmost monitor + *Separate per-monitor settings for this would be ideal + */ + monitor = gdk_display_get_monitor (display, 0); + gdk_monitor_get_geometry (monitor, &geometry); + + width_dpi = dpi_from_pixels_and_mm (geometry.width, gdk_monitor_get_width_mm(monitor)); + height_dpi = dpi_from_pixels_and_mm (geometry.height, gdk_monitor_get_height_mm(monitor)); + } if (width_dpi < DPI_LOW_REASONABLE_VALUE || width_dpi > DPI_HIGH_REASONABLE_VALUE || height_dpi < DPI_LOW_REASONABLE_VALUE || height_dpi > DPI_HIGH_REASONABLE_VALUE) @@ -465,7 +485,7 @@ dpi_load (GSettings *settings, dpi = g_settings_get_double (settings, FONT_DPI_KEY); if (dpi == 0) - dpi = get_dpi_from_x_server (); + dpi = get_dpi_from_x_server_or_monitor (); dpi *= (double)scale; dpi = CLAMP(dpi, DPI_LOW_REASONABLE_VALUE, DPI_HIGH_REASONABLE_VALUE); @@ -781,6 +801,38 @@ void font_init(AppearanceData* data) G_CALLBACK (marco_changed), data); + /*In a wayland session we must manage MATE font settings for xwayland + *and also manage GNOME font settings for native wayland applications + *so if not running under x11, set the GNOME interface keys too + *Ignore this if for any reason the GNOME schema was not found, + *As we can only set this for compositors using either the MATE or the GNOME gsettings + */ + if (data->interface_gnome_settings) + { + widget = appearance_capplet_get_widget(data, "application_font"); + g_settings_bind (data->interface_gnome_settings, + GTK_FONT_KEY, + G_OBJECT (widget), + "font-name", + G_SETTINGS_BIND_DEFAULT); + + widget = appearance_capplet_get_widget (data, "document_font"); + g_settings_bind (data->interface_gnome_settings, + DOCUMENT_FONT_KEY, + G_OBJECT (widget), + "font-name", + G_SETTINGS_BIND_DEFAULT); + +/* The monospace font seems to apply properly if and only if set only for MATE + widget = appearance_capplet_get_widget (data, "monospace_font"); + g_settings_bind (data->interface_gnome_settings, + MONOSPACE_FONT_KEY, + G_OBJECT (widget), + "font-name", + G_SETTINGS_BIND_DEFAULT); +*/ + } + g_signal_connect (appearance_capplet_get_widget (data, "add_new_font"), "clicked", G_CALLBACK (cb_add_new_font), data); marco_titlebar_load_sensitivity(data); |