weisJ / auto-dark-mode

IDEA plugin to automatically apply system theme settings on macOS and Windows.
https://plugins.jetbrains.com/plugin/14076-auto-dark-mode
MIT License
52 stars 13 forks source link

Support for Linux #50

Closed l0drex closed 1 year ago

l0drex commented 2 years ago

There is now a way to detect the active theme variant on many Linux desktops. It's a xdg-desktop key that can be accessed via dbus: https://github.com/flatpak/xdg-desktop-portal/pull/633 (also works outside of Flatpaks)

Service: org.freedesktop.portal.Desktop Method: /org/freedesktop/portal/desktop org.freedesktop.Settings.Read Namespace: org.freedesktop.appearance Key: color-scheme

It returns a uint32: 1 for dark mode and 2 for light mode

It is not implemented everywhere yet (as far as I can tell), so errors would need to be catched.

weisJ commented 2 years ago

I know supporting more desktop environemnts than just Gnome would be very desirable, but sadly I simply do not have the capacity to implement such features at the moment (In particular mantaining the implementation).

It looks like it could be a rather simple implementation that follows a mix of the macOS/Windows and Gnome implementation. If you want to provide an implementation I would be more than happy to give pointers on how to get started with the project (and of course merge it :) )

weisJ commented 2 years ago

There is now a way to detect the active theme variant on many Linux desktops

Would this also entail Gnome i.e. could this replace the current implementation for it?

l0drex commented 2 years ago

I would love to do that, but I need a starting point: where is the current implementation for Gnome, what do I need to change etc

Would this also entail Gnome i.e. could this replace the current implementation for it?

Yes, Gnome has implemented it

weisJ commented 2 years ago

I would love to do that, but I need a starting point: where is the current implementation for Gnome, what do I need to change etc

The Gnome implementation is located at: https://github.com/weisJ/auto-dark-mode/tree/master/linux/gnome I'd suggest to add the new implementation as a separate module as linux/xdg-desktop-portal. Then the old Gnome implementation could be phased out sometime later (I kinda like the idea of simply replacing the guessing mechanism of the gnome implementation with the xdg-desktop mechanism, as this would still allow for manually choosing what Gnome theme corresponds to what Idea theme).

For a starting point you can simply follow the layout of the gnome:

To integrate the native code you can follow the implementation of https://github.com/weisJ/auto-dark-mode/blob/master/linux/gnome/src/main/java/com/github/weisj/darkmode/platform/linux/gnome/GnomeLibrary.java and https://github.com/weisJ/auto-dark-mode/blob/master/linux/gnome/src/main/java/com/github/weisj/darkmode/platform/linux/gnome/GnomeNative.java (this is simply a class to declare the native functions in).

The main work then is to implement ThemeMonitorService (see https://github.com/weisJ/auto-dark-mode/blob/master/linux/gnome/src/main/java/com/github/weisj/darkmode/platform/linux/gnome/GnomeThemeMonitorService.kt for reference) using the native functions.

I hope this helps to get started. If you have any more questions feel free to ask.

weisJ commented 1 year ago

auto-dark-mode-plugin-1.8.0-2023.1.zip

I have prepared a preliminary build incorporating the new Xdg based mechanism. Please check for any issues :)

l0drex commented 1 year ago

Just tested on arch with KDE Plasma, works great! Thank you so much!

lkraav commented 1 year ago

Just tested on arch with KDE Plasma, works great! Thank you so much!

Yes, XDG mechanism also works on Gnome 44, tyvm!

Plugin could ask for a Restart after this settings change, because automatic changes wouldn't trigger before I manually restarted IDE.

weisJ commented 1 year ago

The final version will not need a restart ;)