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

Gtk3 theme reload hack (idea) #112

Closed
jasperro opened this issue Oct 21, 2018 · 17 comments
Closed

Gtk3 theme reload hack (idea) #112

jasperro opened this issue Oct 21, 2018 · 17 comments

Comments

@jasperro
Copy link
Contributor

I don't really know where to put this, but I found a solution/hack to enable Gtk3 on-the-fly theme reloading. It is very simple. This was tested on i3wm. I installed gnome-settings-daemon, and ran/usr/lib/gsd-xsettings. After that, I changed my wpgtk theme and ran gsettings set org.gnome.desktop.interface gtk-theme Adapta && gsettings set org.gnome.desktop.interface gtk-theme FlatColor, and it changed the gtk theme without restarting the application. I hope you can do something with this information.

@deviantfero
Copy link
Owner

could you provide a video? try reproducing with thunar, you could record your screen with simple-screen-recorder, I'd be very interested if this was consistently reproducible.

@jasperro
Copy link
Contributor Author

Sure!
simplescreenrecorder-2018-10-21_18 44 25

@jasperro
Copy link
Contributor Author

And I seem to be able to get the same effect with xsettingsd, which is very lightweight, has less dependencies and allows only changing the gtk theme without messing up your fonts, icons and cursor.

@deviantfero
Copy link
Owner

deviantfero commented Oct 21, 2018

Nice! I will look more into it and see if I can integrate it as an optional dependency, thanks for the tip.

I'll keep this open for when I implement it, in the meantime, you can have auto-reload if you use the:
Run command after colorize option in the Options tab, you can set it to run gsettings set ...

@jasperro
Copy link
Contributor Author

For xsettingsd you need a config file with the following text: Net/ThemeName "FlatColor"
The run after colorize command needs to be timeout 0.5s xsettingsd -c configfilename

@jasperro
Copy link
Contributor Author

I have been tinkering with this some more, and I now have a working python script that can very easily be implemented!

import shutil
import subprocess
import os
import tempfile

"""Runs xsettingsd for a short time to reload gtk3 theme"""
if shutil.which("xsettingsd"):
    fd, path = tempfile.mkstemp()
    try:
        with os.fdopen(fd, 'w+') as tmp:
            tmp.write('Net/ThemeName "FlatColor"\n')
            tmp.close()
            subprocess.Popen.wait(subprocess.Popen(["timeout", "0.2s", "xsettingsd", "-c", path]))
    finally:
            os.remove(path)

@deviantfero
Copy link
Owner

this is great!!, but are you sure we need the timeout? by the time I run this script the GTK theme has been fundamentally changed, could you test without it? I mean, even if it can't be done without a timeout, I think is good enough.

@jasperro
Copy link
Contributor Author

jasperro commented Oct 22, 2018

A timeout is needed, and can be reduced to 0.01s. The reason I did this is because xsettingsd is a daemon that keeps running if you don't interrupt it, and the timeout keeps the daemon running for a short time only and kills it after the timeout. Xsettingsd ignores theme changes for some reason, so using it as a daemon wouldn't work.

@deviantfero
Copy link
Owner

deviantfero commented Oct 22, 2018 via email

@deviantfero
Copy link
Owner

Hey @jasperro, the new 5.8.0 release includes live reloading! check it out!

@jasperro
Copy link
Contributor Author

Hey, I'm using the latest wpgtk-git on Arch, and have xsettingsd installed, but the reload doesn't seem to be working. But my script still seems to work. Do you have the same problem?

@deviantfero
Copy link
Owner

I'm sorry for the late answer, I'm only having this issue with firefox and wpg itself, but just when I do this from the GUI, when doing it from the cli wpg changes color on the fly, while firefox still doesn't

@jasperro
Copy link
Contributor Author

Weird, seems that the live reloading only works in the cli. My firefox and wpg do reload when I use the cli. Do you have any idea why this is? Maybe the subprocess needs to be forced to run as a terminal app?

@deviantfero
Copy link
Owner

nope, no idea, any clues on how to achieve that?

@rahatzamancse
Copy link
Contributor

Hey, Don't know if I should open a new issue or ask it here. I am making my own gtk customized theme with gtk.css and other files making them templates of wpg. I use lxappearance to set my theme which is located at default location: ~/.local/share/themes/ (also symlinked to ~/.themes/ if that is somehow related).
But whenever I apply a wallpaper and theme with wpg (gui or cli), the gtk apps reload and uses the theme of Flatcolor (if Flatcolor is not installed, else changes to Adwaita).
And if I manually restart the app, it shows the theme I made as expected.
Any idea what is happening?

@jasperro
Copy link
Contributor Author

@rahatzamancse The code currently expects FlatColor when it reloads, this is hard-coded in. @deviantfero Maybe the current theme can be queried and set again with gsettings (will require setting theme with gsettings too I think) or maybe the current theme can be read from the gtk config or wpg config. @rahatzamancse what do you think is the best option for you? Is using gsettings commands to set the theme fine for you? That will be the easiest to implement as I don't think lxappearance sets the theme in gsettings (could be wrong)

@rahatzamancse
Copy link
Contributor

@jasperro You're right. lxappearance does not use gsettings or edit dconf. Instead, it writes the theme name and other details in ~/.config/gtk-3.0/settings.ini and ~/.gtkrc-2.0 (Though icon theme is written in both dconf and gtkrc by lxappearance). I am saying this from what I have experimented so far.

But that is not the issue here. The issue is that the code expects the user to use only one theme(Flatcolor). I am sorry if I sound a bit rude, but I do not like the approach of using xsettingsd without knowing if there is a settings daemon running or not (suppose the user is using gnome DE) and forcefully setting theme Flatcolor (which is very pointy and ugly to me, and most of the ricers will use their own gtk theme anyway).

So, I made a PR #202 fixing all these problems. Please check that out.

BTW, thanks a lot for making this awesome program. Really enjoying using it, and thinking to manage all my dots with this gem :)

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

No branches or pull requests

3 participants