diff --git a/gajim/common/app.py b/gajim/common/app.py
index 5ca859046..90d060a75 100644
--- a/gajim/common/app.py
+++ b/gajim/common/app.py
@@ -46,7 +46,6 @@ from gajim.common import configpaths
from gajim.common import ged as ged_module
from gajim.common.contacts import LegacyContactsAPI
from gajim.common.events import Events
-from gajim.common.css_config import CSSConfig
from gajim.common.types import NetworkEventsControllerT # pylint: disable=unused-import
from gajim.common.types import InterfaceT # pylint: disable=unused-import
from gajim.common.types import LoggerT # pylint: disable=unused-import
@@ -645,6 +644,7 @@ def get_app_window(cls, account=None):
def load_css_config():
global css_config
+ from gajim.gtk.css_config import CSSConfig
css_config = CSSConfig()
def set_win_debug_mode(enable: bool) -> None:
diff --git a/gajim/common/config.py b/gajim/common/config.py
index e17c769c2..263220d95 100644
--- a/gajim/common/config.py
+++ b/gajim/common/config.py
@@ -292,6 +292,7 @@ class Config:
'use_keyring': [opt_bool, True, _('If true, Gajim will use the Systems Keyring to store account passwords.')],
'pgp_encoding': [opt_str, '', _('Sets the encoding used by python-gnupg'), True],
'remote_commands': [opt_bool, False, _('If true, Gajim will execute XEP-0146 Commands.')],
+ 'dark_theme': [opt_int, 2, _('2: System, 1: Enabled, 0: Disabled')],
}, {}) # type: Tuple[Dict[str, List[Any]], Dict[Any, Any]]
__options_per_key = {
diff --git a/gajim/data/gui/preferences_window.ui b/gajim/data/gui/preferences_window.ui
index fe4bb8ba9..1c5f6a9fc 100644
--- a/gajim/data/gui/preferences_window.ui
+++ b/gajim/data/gui/preferences_window.ui
@@ -1540,41 +1540,6 @@ $T will be replaced by auto-not-available timeout
0
-
-
-
- 0
- 1
-
-
-
-
-
- 1
- 2
- 2
-
-
-
+
+
+ True
+ False
+ end
+ Status _iconset
+ True
+ right
+
+
+
+ 0
+ 1
+
+
+
+
+ True
+ False
+ end
+ Dark Theme
+ True
+ right
+
+
+
+ 0
+ 2
+
+
+
+
+ True
+ False
+
+ - System
+ - Enabled
+ - Disabled
+
+
+
+
+ 1
+ 2
+
+
diff --git a/gajim/gtk/const.py b/gajim/gtk/const.py
index de9499184..4678c502b 100644
--- a/gajim/gtk/const.py
+++ b/gajim/gtk/const.py
@@ -15,5 +15,12 @@
# Constants for the gtk module
from collections import namedtuple
+from enum import IntEnum, unique
Filter = namedtuple('Filter', 'name pattern default')
+
+@unique
+class Theme(IntEnum):
+ NOT_DARK = 0
+ DARK = 1
+ SYSTEM = 2
diff --git a/gajim/common/css_config.py b/gajim/gtk/css_config.py
similarity index 94%
rename from gajim/common/css_config.py
rename to gajim/gtk/css_config.py
index 940ccc17e..7047a6b8c 100644
--- a/gajim/common/css_config.py
+++ b/gajim/gtk/css_config.py
@@ -28,12 +28,10 @@ from gajim.common import app
from gajim.common import configpaths
from gajim.common.const import StyleAttr, CSSPriority
-log = logging.getLogger('gajim.c.css')
+from gajim.gtk.const import Theme
-_settings = Gtk.Settings.get_default()
-PREFER_DARK = False
-if _settings is not None:
- PREFER_DARK = _settings.get_property('gtk-application-prefer-dark-theme')
+log = logging.getLogger('gajim.gtk.css')
+settings = Gtk.Settings.get_default()
class CSSConfig():
@@ -92,6 +90,7 @@ class CSSConfig():
# Holds all currently available themes
self.themes = []
+ self.set_dark_theme()
self._load_css()
self._gather_available_themes()
self._load_default()
@@ -102,14 +101,37 @@ class CSSConfig():
self._provider,
CSSPriority.USER_THEME)
+ @property
+ def prefer_dark(self):
+ setting = app.config.get('dark_theme')
+ if setting == Theme.SYSTEM:
+ if settings is None:
+ return False
+ return settings.get_property('gtk-application-prefer-dark-theme')
+ return setting == Theme.DARK
+
+ @staticmethod
+ def set_dark_theme(value=None):
+ if value is None:
+ value = app.config.get('dark_theme')
+ else:
+ app.config.set('dark_theme', value)
+
+ if settings is None:
+ return
+ if value == Theme.SYSTEM:
+ settings.reset_property('gtk-application-prefer-dark-theme')
+ return
+ settings.set_property('gtk-application-prefer-dark-theme', bool(value))
+
def _load_css(self):
self._load_css_from_file('gajim.css', CSSPriority.APPLICATION)
- if PREFER_DARK:
+ if self.prefer_dark:
self._load_css_from_file('gajim-dark.css',
CSSPriority.APPLICATION_DARK)
self._load_css_from_file('default.css', CSSPriority.DEFAULT_THEME)
- if PREFER_DARK:
+ if self.prefer_dark:
self._load_css_from_file('default-dark.css',
CSSPriority.DEFAULT_THEME_DARK)
@@ -151,9 +173,8 @@ class CSSConfig():
# Ignore user created themes that are named 'default'
self.themes.remove('default')
- @classmethod
- def get_theme_path(cls, theme, user=True):
- if theme == 'default' and PREFER_DARK:
+ def get_theme_path(self, theme, user=True):
+ if theme == 'default' and self.prefer_dark:
theme = 'default-dark'
if user:
diff --git a/gajim/gtk/preferences.py b/gajim/gtk/preferences.py
index 01ab79b16..a3912d339 100644
--- a/gajim/gtk/preferences.py
+++ b/gajim/gtk/preferences.py
@@ -24,11 +24,7 @@ from gajim.common import helpers
from gajim.common import configpaths
from gajim.common import config as c_config
from gajim.common import idle
-from gajim.gtk.util import get_dark_theme
-from gajim.gtk.util import set_dark_theme
-from gajim.gtk.util import get_builder
-from gajim.gtk.dialogs import AspellDictError
-from gajim.gtk.themes import Themes
+
from gajim.advanced_configuration_window import AdvancedConfigurationWindow
from gajim.chat_control_base import ChatControlBase
from gajim.config import ManageProxiesWindow, ManageSoundsWindow
@@ -36,6 +32,10 @@ from gajim import message_control
from gajim import cell_renderer_image
from gajim import gtkgui_helpers
+from gajim.gtk.util import get_builder
+from gajim.gtk.dialogs import AspellDictError
+from gajim.gtk.themes import Themes
+
try:
from gajim.common.multimedia_helpers import AudioInputManager, AudioOutputManager
from gajim.common.multimedia_helpers import VideoInputManager, VideoOutputManager
@@ -210,7 +210,8 @@ class Preferences(Gtk.ApplicationWindow):
self.xml.get_object('transports_iconsets_checkbutton').set_active(st)
# Dark theme
- self.xml.get_object('enable_dark_theme').set_active(get_dark_theme())
+ dark_theme_combo = self.xml.get_object('dark_theme_combobox')
+ dark_theme_combo.set_active_id(str(app.config.get('dark_theme')))
### Personal Events tab ###
# outgoing send chat state notifications
@@ -660,8 +661,8 @@ class Preferences(Gtk.ApplicationWindow):
self.on_checkbutton_toggled(widget, 'use_transports_iconsets')
gtkgui_helpers.reload_jabber_state_images()
- def on_enable_dark_theme_toggled(self, widget):
- set_dark_theme(widget.get_active())
+ def on_dark_theme_changed(self, widget):
+ app.css_config.set_dark_theme(int(widget.get_active_id()))
def on_outgoing_chat_states_combobox_changed(self, widget):
active = widget.get_active()
diff --git a/gajim/gtk/util.py b/gajim/gtk/util.py
index ca0250587..b0b974c35 100644
--- a/gajim/gtk/util.py
+++ b/gajim/gtk/util.py
@@ -233,13 +233,3 @@ def convert_rgb_to_hex(rgb_string: str) -> str:
green = int(rgb.green * 255)
blue = int(rgb.blue * 255)
return '#%02x%02x%02x' % (red, green, blue)
-
-
-def set_dark_theme(enable: bool) -> None:
- settings = Gtk.Settings.get_default()
- settings.set_property('gtk-application-prefer-dark-theme', enable)
-
-
-def get_dark_theme() -> bool:
- settings = Gtk.Settings.get_default()
- return settings.get_property('gtk-application-prefer-dark-theme')