-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Using a more generic Gtk detection method. #54
Conversation
Hi there! I understand there is a pending PR #50 using the FreeDesktop dark mode preference. However, as a LTS user on stable distros, I do not see myself able to use this on my work computer any time soon. However, I did discover a more generic way that should work with many GTK desktops that implements the XSettings protocol. Thought this'd be useful for other folks stuck in the same situation. |
plugin/src/test/kotlin/com/github/weisj/darkmode/platform/linux/gnome/GnomeNativeTest.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to rename all Gnome**
classes/files to read GTK**
. Same goes for the subproject.
// really any GTK would do (`isGnome` named for historical reasons) | ||
public static final boolean isGnome = SystemInfo.isGNOME || SystemInfo.isXfce || SystemInfo.isI3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to keep the old name. Please rename to isGTK
@@ -43,9 +43,10 @@ class GnomeNativeTest { | |||
|
|||
private fun currentGtkTheme(): String { | |||
val theme = "gsettings get $settingsPath $settingsKey".runCommand() | |||
//val theme = "xfconf-query -c xsettings -p /Net/ThemeName".runCommand() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on my computer I use xfconf-query
from XFCE but I don't see the need to change the default test based on gnome.
I left it as a comment to show that alternative utilities would also work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As these comments are removed in the folowing commit please drop them from this one :)
plugin/src/test/kotlin/com/github/weisj/darkmode/platform/linux/gnome/GnomeNativeTest.kt
Outdated
Show resolved
Hide resolved
I'm ok with that. Hopefully the diff is still obvious of the actual functional change. |
As long as you keep the renaming of files in a separate commit it should be fine. |
Looks like the CI is failing because the build actions need to be updated |
lol I used ripgrep to find |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some last comment. Otherwise this looks good to me. Very good work. Thank for tackling this!
v1.7.0 | ||
<ul> | ||
<li>Generic GTK desktops support. (XSettings based)</li> | ||
</ul> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this its own commit
@@ -11,7 +11,7 @@ systemProp.org.gradle.internal.publish.checksums.insecure = true | |||
org.gradle.jvmargs = -noverify | |||
|
|||
# Version | |||
auto-dark-mode.version = 1.6.2-2022.1 | |||
auto-dark-mode.version = 1.7.0-2022.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also go into the release note commit.
|
||
data class GtkTheme(val name: String) : Comparable<GtkTheme> { | ||
override fun compareTo(other: GtkTheme): Int = name.compareTo(other.name) | ||
} | ||
|
||
object GnomeSettings : DefaultSettingsContainer(identifier = "gnome_settings") { | ||
object GtkSettings : DefaultSettingsContainer(identifier = "gtk_settings") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will invalidate existing stored settings. Either keep the identifier the old one with a comment explaining why or advance the settings version in https://github.com/weisJ/auto-dark-mode/blob/master/plugin/src/main/java/com/github/weisj/darkmode/AutoDarkModeOptions.kt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah i was not aware of this side effect. I think keeping the name with a comment is the least disruptive solution.
@@ -43,9 +43,10 @@ class GnomeNativeTest { | |||
|
|||
private fun currentGtkTheme(): String { | |||
val theme = "gsettings get $settingsPath $settingsKey".runCommand() | |||
//val theme = "xfconf-query -c xsettings -p /Net/ThemeName".runCommand() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As these comments are removed in the folowing commit please drop them from this one :)
README.md
Outdated
@@ -8,7 +8,7 @@ operating system settings. The plugin distinguishes between `Light`, `Dark` and | |||
the theme used for each mode can be customized. | |||
This plugin currently works for Windows and macOS. | |||
|
|||
Linux support is both limited and experimental. At the moment, the only Linux desktop environment supported by this plugin is Gnome. | |||
Linux support is both limited and experimental. At the moment, Linux desktop environments based on Gtk and has an [XSettings](https://www.freedesktop.org/wiki/Specifications/xsettings-spec/) daemon are supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds odd. How about "Linux desktop environments based on Gtk, which have an XSettings daemon are supported."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if I should expand on that:
- An XSettings daemon (e.g.
gsd-xsettings
for Gnome;xfsettingsd
for Xfce; or even standalone ones like https://github.com/derat/xsettingsd) is required because it is the one that actually sends out the notifications when a theme (amont other settings) changes; - Conversely, you can run a desktop environment without XSettings daemon (e.g. to my knowledge LXDE does not have one by default), in which case theme changes are not "real time" (i.e. they usually takes effect only for new apps launched, since running apps do not get notified)
- I haven't verified it, but I think even non-Gtk native environments like KDE should work with this, if it runs such a daemon (e.g. https://github.com/KDE/xsettings-kde)
so really the dominating factor is not Gtk (we just use it to get notified), but rather the XSettings daemon (who actually sends out the notifications)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the clarification. Nonetheless the setence as it is isn't grammatically correct. I also think it would be worth while to elaborate a bit on what is needed to use the plugin. This could also be added to https://github.com/weisJ/auto-dark-mode/blob/master/plugin/src/main/resources/META-INF/plugin.xml
Using Gtk::Settings that reads the `Net/ThemeName` key from XSettings. https://www.freedesktop.org/wiki/Specifications/XSettingsRegistry/ XSettings are respected by most Gtk desktops and this allows us to support a wider range of desktops. Theoretically any desktop with an XSettings daemon should be supported. Tested: * i3 + xfsettingsd (XSettings daemon from Xfce 4) * i3 + gsd-xsettings (Gnome Settings Daemon)
hi @weisJ thanks for your comments. I've rebased the PR and:
while implementing this change I also learned quite a bit about desktop environments (vs window managers) and the XSettings daemon. the main take-away I have is that as long as there is such a daemon running and it's signaling the changes according to the spec, this new method of detecting current theme (and change of themes) should work. I've updated README.md to summarize such learnings in the most technically accurate way possible, while keeping it short (enough). |
Thanks a lot for tackling this 👍🏼
In this case it could be possible to allow users to enable monitoring on their own risk (i.e. they make sure that a compatible daemon is installed). But this is something for another time :) |
Thank you for your feedback :)
Yeah that's what I'm thinking as a potential future improvement. |
Using Gtk::Settings that reads the
Net/ThemeName
key from XSettings.https://www.freedesktop.org/wiki/Specifications/XSettingsRegistry/
XSettings are respected by most Gtk desktops and this allows us to
support a wider range of desktops.
Theoretically any desktop with an XSettings daemon should be supported.
Tested: