Skip to content

Commit

Permalink
frames: Don't set prefer-dark-theme if adwaita is loaded
Browse files Browse the repository at this point in the history
Avoids the following warning in the logs
mutter-x11-frame[4003]: Using
GtkSettings:gtk-application-prefer-dark-theme with libadwaita is
unsupported. Please use AdwStyleManager:color-scheme instead.

When initializing libadwaita, the AdwStyleManager default instance is
initialized taking care of loading the appropriate stylesheet.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4276>
  • Loading branch information
bilelmoussaoui committed Feb 18, 2025
1 parent 45f60a2 commit 8223f58
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/frames/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@

#include "config.h"

#include "meta-frames-client.h"
#include "meta-window-tracker.h"

#include <gdk/x11/gdkx.h>
#include <glib-unix.h>
#include <gmodule.h>
#include <X11/extensions/Xfixes.h>

static gboolean should_monitor_color_scheme = TRUE;

typedef void (* InitFunc) (void);

static gboolean
Expand Down Expand Up @@ -63,6 +66,7 @@ load_libadwaita (void)
if (!g_module_symbol (libadwaita, "adw_init", (gpointer *) &adw_init))
return;

should_monitor_color_scheme = FALSE;
adw_init ();
}

Expand All @@ -74,6 +78,12 @@ on_sigterm (gpointer user_data)
return G_SOURCE_REMOVE;
}

gboolean
meta_frames_client_should_monitor_color_scheme (void)
{
return should_monitor_color_scheme;
}

int
main (int argc,
char *argv[])
Expand Down
22 changes: 22 additions & 0 deletions src/frames/meta-frames-client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2025 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <glib.h>

gboolean meta_frames_client_should_monitor_color_scheme (void);
18 changes: 12 additions & 6 deletions src/frames/meta-window-tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "meta-window-tracker.h"

#include "meta-frame.h"
#include "meta-frames-client.h"

#include <gdesktop-enums.h>
#include <gdk/x11/gdkx.h>
Expand Down Expand Up @@ -94,6 +95,8 @@ update_color_scheme (MetaWindowTracker *window_tracker)
GDesktopColorScheme color_scheme;
gboolean is_dark;

g_assert (window_tracker->interface_settings != NULL);

color_scheme = g_settings_get_enum (window_tracker->interface_settings,
"color-scheme");
is_dark = color_scheme == G_DESKTOP_COLOR_SCHEME_PREFER_DARK;
Expand Down Expand Up @@ -422,12 +425,15 @@ meta_window_tracker_class_init (MetaWindowTrackerClass *klass)
static void
meta_window_tracker_init (MetaWindowTracker *window_tracker)
{
window_tracker->interface_settings = g_settings_new ("org.gnome.desktop.interface");
g_signal_connect (window_tracker->interface_settings,
"changed::color-scheme",
G_CALLBACK (on_color_scheme_changed_cb),
window_tracker);
update_color_scheme (window_tracker);
if (meta_frames_client_should_monitor_color_scheme ())
{
window_tracker->interface_settings = g_settings_new ("org.gnome.desktop.interface");
g_signal_connect (window_tracker->interface_settings,
"changed::color-scheme",
G_CALLBACK (on_color_scheme_changed_cb),
window_tracker);
update_color_scheme (window_tracker);
}

window_tracker->frames =
g_hash_table_new_full (NULL, NULL, NULL,
Expand Down

0 comments on commit 8223f58

Please sign in to comment.