-
-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support auto-setting dark mode on Linux with org.freedesktop.appearance.color-scheme
#2525
Comments
This only works for Gnome, right? |
It should also work for KDE. See the Telegram issue. It's also an official freedesktop spec. |
But is there a way to include this without getting GTK (or KDE) dependencies? |
It seems that a D-Bus library is intergrated into Qt? https://doc.qt.io/qt-5/qtdbus-index.html I can take look at some point. For myself I found the following solution, that might be helpful to other people that want to toggle dark mode automatically. My solution is GNOME specific but can probably be adapted for KDE. There is a very nice GNOME extension called Night Theme Switcher. You can run custom commands on toggle: I run this script to modify the config and to restart QOwnNotes: #!/usr/bin/bash
if [[ $1 = "on" ]]; then
dark=true
elif [[ $1 = "off" ]]; then
light=true
else
echo "Usage: dark-mode on|off"
exit 1
fi
replace() {
sed -ie --follow-symlinks 's/'$1'=.*/'$1'='$2'/' "$3"
}
qon=~/.config/PBE/QOwnNotes.conf
if [[ $dark ]]; then
replace darkMode true $qon
replace darkModeColors true $qon
replace darkModeIconTheme true $qon
replace CurrentSchemaKey EditorColorSchema-cdbf28fc-1ddc-4d13-bb21-6a4043316a2f $qon
elif [[ $light ]]; then
replace darkMode false $qon
replace darkModeColors false $qon
replace darkModeIconTheme false $qon
replace CurrentSchemaKey EditorColorSchema-6033d61b-cb96-46d5-a3a8-20d5172017eb $qon
fi
killall QOwnNotes
if [[ $? == 0 ]]; then
QOwnNotes &
fi |
hm, which also adds another Qt library dependency just for this small feature... |
@pbek The following command line argument would avoid that dependency:
to indicate a dark-mode preference (see here) for both KDE and GNOME (and other DEs that support this spec). |
Sounds like a nice alternative, thank you. I wonder if you are able to execute that from a flatpak or snap... 🤔 |
All I got so far when running with QProcess under Linux natively with... auto parameters = QStringList() <<
QStringLiteral("--session") << QStringLiteral("--print-reply=literal") << QStringLiteral("--reply-timeout=1000") <<
QStringLiteral("--dest=org.freedesktop.portal.Desktop") << QStringLiteral("/org/freedesktop/portal/desktop") <<
QStringLiteral("org.freedesktop.portal.Settings.Read") << QStringLiteral("string:'org.freedesktop.appearance' string:'color-scheme'");
QProcess process;
process.start(QStringLiteral("dbus-send"), parameters); is
Other permutations of input arguments (e.g. every part is a different argument item) got me: |
Running it with |
@pbek I think you have to separate those two strings, otherwise it is interpreting it as one string.
⬇️
I am not a D-Bus expert, but this method requires two strings as input. I used an app called D-Feet to figure it out: |
22.6.1
|
I had them all separate in the beginning... |
There now is a new release, could you please test it and report if it works for you? |
Turns out there is a GNOME bug that sets the preference to 'default' when setting light as a preference! However, the QOwnNotes feature works as advertised. 👍 |
Great, thank you for testing! |
There should be an option to use the system wide dark mode setting on startup on Linux.
org.freedesktop.appearance.color-scheme
can be used, see:Watching the dark mode preference and updating it real-time would be even cooler, but this is a good fist step.
Example apps that use it:
The text was updated successfully, but these errors were encountered: