From c80f34f4ab51e7bbd5f5561b91cafb35809587ab Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Mon, 7 Dec 2020 15:25:10 +0100 Subject: [PATCH] Fix compatibility with dark themes. Fixes #23 --- clapper_src/app.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/clapper_src/app.js b/clapper_src/app.js index 2b2d3798..c7d38900 100644 --- a/clapper_src/app.js +++ b/clapper_src/app.js @@ -94,9 +94,11 @@ class ClapperApp extends Gtk.Application let gtkSettings = Gtk.Settings.get_default(); settings.bind( 'dark-theme', gtkSettings, - 'gtk_application_prefer_dark_theme', + 'gtk-application-prefer-dark-theme', Gio.SettingsBindFlags.GET ); + this._onThemeChanged(gtkSettings); + gtkSettings.connect('notify::gtk-theme-name', this._onThemeChanged.bind(this)); this.windowShowSignal = this.active_window.connect( 'show', this._onWindowShow.bind(this) @@ -107,12 +109,28 @@ class ClapperApp extends Gtk.Application _onWindowShow(window) { - window.disconnect(this.windowShowSignal); - this.windowShowSignal = null; + window.disconnect(this.windowShowSignal); + this.windowShowSignal = null; - if(this.playlist.length) { + if(this.playlist.length) { let { player } = window.get_child(); player.set_playlist(this.playlist); - } + } + } + + _onThemeChanged(gtkSettings) + { + const theme = gtkSettings.gtk_theme_name; + debug(`user selected theme: ${theme}`); + + if(!theme.endsWith('-dark')) + return; + + /* We need to request a default theme with optional dark variant + to make the "gtk_application_prefer_dark_theme" setting work */ + const parsedTheme = theme.substring(0, theme.lastIndexOf('-')); + + gtkSettings.gtk_theme_name = parsedTheme; + debug(`set theme: ${parsedTheme}`); } });