frames: Add basic color-scheme support

Use the dark variant for decorations if the color-scheme preference
indicates that it's preferred, and the client didn't explicitly
pick a variant via the _GTK_THEME_VARIANT hint.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2541>
This commit is contained in:
Florian Müllner 2022-07-28 15:52:34 +02:00 committed by Marge Bot
parent 7c8ffe7efe
commit 9d4aa4488a
2 changed files with 33 additions and 3 deletions

View File

@ -26,6 +26,7 @@
#include <cairo-xlib.h>
#include <math.h>
#include <string.h>
#include <gdesktop-enums.h>
#include "core/frame.h"
#include "core/window-private.h"
@ -61,6 +62,7 @@ static void meta_ui_frame_update_prelit_control (MetaUIFrame *frame,
static void meta_frames_font_changed (MetaFrames *frames);
static void meta_frames_button_layout_changed (MetaFrames *frames);
static void meta_frames_reattach_all_styles (MetaFrames *frames);
static GdkRectangle* control_rect (MetaFrameControl control,
@ -207,6 +209,12 @@ update_style_contexts (MetaFrames *frames)
static void
meta_frames_init (MetaFrames *frames)
{
frames->interface_settings = g_settings_new ("org.gnome.desktop.interface");
g_signal_connect_swapped (frames->interface_settings,
"changed::color-scheme",
G_CALLBACK (meta_frames_reattach_all_styles),
frames);
frames->text_heights = g_hash_table_new (NULL, NULL);
frames->frames = g_hash_table_new (unsigned_long_hash, unsigned_long_equal);
@ -260,6 +268,8 @@ meta_frames_destroy (GtkWidget *object)
frames->style_variants = NULL;
}
g_clear_object (&frames->interface_settings);
GTK_WIDGET_CLASS (meta_frames_parent_class)->destroy (object);
}
@ -331,6 +341,13 @@ reattach_style_func (gpointer key, gpointer value, gpointer data)
meta_ui_frame_attach_style (frame);
}
static void
meta_frames_reattach_all_styles (MetaFrames *frames)
{
g_hash_table_foreach (frames->frames, reattach_style_func, NULL);
meta_display_queue_retheme_all_windows (meta_get_display ());
}
static void
meta_frames_style_updated (GtkWidget *widget)
{
@ -342,9 +359,7 @@ meta_frames_style_updated (GtkWidget *widget)
update_style_contexts (frames);
g_hash_table_foreach (frames->frames, reattach_style_func, NULL);
meta_display_queue_retheme_all_windows (meta_get_display ());
meta_frames_reattach_all_styles (frames);
GTK_WIDGET_CLASS (meta_frames_parent_class)->style_updated (widget);
}
@ -478,6 +493,17 @@ get_global_theme_variant (MetaFrames *frames)
return NULL;
}
static const char *
get_color_scheme_variant (MetaFrames *frames)
{
int color_scheme = g_settings_get_enum (frames->interface_settings, "color-scheme");
if (color_scheme == G_DESKTOP_COLOR_SCHEME_PREFER_DARK)
return "dark";
return NULL;
}
/* In order to use a style with a window it has to be attached to that
* window. Actually, the colormaps just have to match, but since GTK+
* already takes care of making sure that its cheap to attach a style
@ -496,6 +522,8 @@ meta_ui_frame_attach_style (MetaUIFrame *frame)
variant = frame->meta_window->gtk_theme_variant;
if (variant == NULL)
variant = get_global_theme_variant (frame->frames);
if (variant == NULL)
variant = get_color_scheme_variant (frame->frames);
if (variant == NULL || *variant == '\0')
frame->style_info = meta_style_info_ref (frames->normal_style);

View File

@ -98,6 +98,8 @@ struct _MetaFrames
MetaStyleInfo *normal_style;
GHashTable *style_variants;
GSettings *interface_settings;
MetaGrabOp current_grab_op;
MetaUIFrame *grab_frame;
guint grab_button;