Skip to content
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

Merged
merged 2 commits into from
May 9, 2022

Conversation

zliuva
Copy link
Contributor

@zliuva zliuva commented Apr 28, 2022

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)

@zliuva
Copy link
Contributor Author

zliuva commented Apr 28, 2022

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.

Copy link
Owner

@weisJ weisJ left a 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.

Comment on lines 41 to 42
// really any GTK would do (`isGnome` named for historical reasons)
public static final boolean isGnome = SystemInfo.isGNOME || SystemInfo.isXfce || SystemInfo.isI3;
Copy link
Owner

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()
Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Owner

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 :)

@zliuva
Copy link
Contributor Author

zliuva commented Apr 28, 2022

I think it would be good to rename all Gnome** classes/files to read GTK**

I'm ok with that. Hopefully the diff is still obvious of the actual functional change.

@weisJ
Copy link
Owner

weisJ commented Apr 28, 2022

I think it would be good to rename all Gnome** classes/files to read GTK**

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.

@weisJ
Copy link
Owner

weisJ commented Apr 28, 2022

Looks like the CI is failing because the build actions need to be updated

@zliuva
Copy link
Contributor Author

zliuva commented Apr 29, 2022

Looks like the CI is failing because the build actions need to be updated

lol I used ripgrep to find Gnome references but I just learned it ignores dot directories by default!

Copy link
Owner

@weisJ weisJ left a 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!

Comment on lines +24 to +27
v1.7.0
<ul>
<li>Generic GTK desktops support. (XSettings based)</li>
</ul>
Copy link
Owner

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
Copy link
Owner

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") {
Copy link
Owner

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

Copy link
Contributor Author

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()
Copy link
Owner

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.
Copy link
Owner

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."

Copy link
Contributor Author

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:

  1. 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;
  2. 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)
  3. 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)

Copy link
Owner

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

zliuva added 2 commits May 8, 2022 17:39
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)
@zliuva
Copy link
Contributor Author

zliuva commented May 9, 2022

hi @weisJ thanks for your comments. I've rebased the PR and:

  • reverted the settings' identifier
  • squashed implementations into a single commit
  • left version bumps into its own commit

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).

@weisJ
Copy link
Owner

weisJ commented May 9, 2022

Thanks a lot for tackling this 👍🏼

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.

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 :)

@weisJ weisJ merged commit 5ac4662 into weisJ:master May 9, 2022
@zliuva
Copy link
Contributor Author

zliuva commented May 9, 2022

Thank you for your feedback :)

Thanks a lot for tackling this 👍🏼

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.

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 :)

Yeah that's what I'm thinking as a potential future improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants