User Tools

Site Tools


sway:dark-mode

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
sway [2020/10/12 19:26] adminsway:dark-mode [2021/01/07 23:54] (current) admin
Line 1: Line 1:
 ==== On themes, sway, emacs and kitty - the dark-mode script ==== ==== On themes, sway, emacs and kitty - the dark-mode script ====
 +
  
 Unlike Desktop Environments like Gnome and KDE, Window Managers like Unlike Desktop Environments like Gnome and KDE, Window Managers like
-sway do not come with all the tools you might need or want. It's up to+**sway** do not come with all the tools you might need or want. It's up to
 the user to perceive a need, do the research and then install, the user to perceive a need, do the research and then install,
 configure and use the appropriate tools for the job. Notwithstanding configure and use the appropriate tools for the job. Notwithstanding
Line 10: Line 11:
 satisfaction of knowing what's going on. satisfaction of knowing what's going on.
  
-In my own history through fvwm, fluxbox, i3wm and now sway I've never+In my own history through **fvwm****fluxbox****i3wm** and now **sway** I've never
 really wanted to bother with themes. I just made terminals and emacs really wanted to bother with themes. I just made terminals and emacs
 have a black background and other programs could do what ever they have a black background and other programs could do what ever they
Line 28: Line 29:
 customising and a script that I use to do the flick. customising and a script that I use to do the flick.
  
-All of this is on Fedora-31.+All of this is on Fedora-31 but should be similar for other Linux distros.
  
 Apologies if this is all obvious and well documented elsewhere. It was a journey for me and non-trivial. Apologies if this is all obvious and well documented elsewhere. It was a journey for me and non-trivial.
Line 44: Line 45:
  
 The hard part was understanding how to get running programs to notice The hard part was understanding how to get running programs to notice
-the change. **lxappearance**(1) is a program from the LXDE desktop+the change. ''**lxappearance**(1)'' is a program from the LXDE desktop
 environment that does both jobs. Unfortunately, it lacks a CLI environment that does both jobs. Unfortunately, it lacks a CLI
 interface so it can only be used in the pointy-clicky mode and not in interface so it can only be used in the pointy-clicky mode and not in
 a script. a script.
  
-By using **strace**(1) on the different components, I was able to track this +By using ''**strace**(1)'' on the different components, I was able to track this 
-down to a new (for me) system call **eventfd**(2) which GTK2 uses as a+down to a new (for me) system call ''**eventfd**(2)'' which GTK2 uses as a
 signalling mechanism. With a bit more research I found this script signalling mechanism. With a bit more research I found this script
 fragment at [[https://crunchbang.org/forums/viewtopic.php?id=39646]] which fragment at [[https://crunchbang.org/forums/viewtopic.php?id=39646]] which
Line 85: Line 86:
  
 I just wonder if this could be replaced by a simple script like the I just wonder if this could be replaced by a simple script like the
-GK2 one?+GTK2 one?
  
 But that appears to be not the entire story. But that appears to be not the entire story.
Line 114: Line 115:
 ===emacs=== ===emacs===
  
-emacs. Hmmm. I've grown up with that program and am unlikely to+''**emacs**(1)''. Hmmm. I've grown up with that program and am unlikely to
 wean myself off it. There are 'PureGTK' versions floating around as wean myself off it. There are 'PureGTK' versions floating around as
 experiments but they are yet to hit the Fedora repositories outside experiments but they are yet to hit the Fedora repositories outside
Line 120: Line 121:
 GTK signals. GTK signals.
  
-In any case, for emacs I need to also modify the internal text areas +In any case, for ''**emacs**(1)'' I need to also modify the internal text areas 
-and emacs has its own themes spelled out in elisp. I decided on a+and ''**emacs**(1)'' has its own themes spelled out in elisp. I decided on a
 couple of good themes and added some code to my script to flip from couple of good themes and added some code to my script to flip from
 one theme to another. The script should be self explanatory. The one theme to another. The script should be self explanatory. The
Line 130: Line 131:
 ===kitty=== ===kitty===
  
-Now for my favorite wayland terminal emulator, Kitty. It has it's+Now for my favorite wayland terminal emulator, ''**kitty**(1)''. It has it's
 own unique configuration language and can have its colour changed on own unique configuration language and can have its colour changed on
 the fly like this: the fly like this:
Line 140: Line 141:
 ===bash=== ===bash===
  
-My bash prompt contains colours and I have a separate script+My ''**bash**(1)'' prompt contains colours and I have a separate script
 (actually a function in ''~/.bashrc'') that responds appropriately to the (actually a function in ''~/.bashrc'') that responds appropriately to the
 setting of ''TERM_BACKGROUND'' in {dark,light} so my script outputs that setting of ''TERM_BACKGROUND'' in {dark,light} so my script outputs that
Line 150: Line 151:
  
  
-... 'dark-mode on' outputs ''TERM_BACKGROUND=dark; setup-prompt'' and+... 'dark-mode on' outputs ''TERM_BACKGROUND=dark; setup_prompt'' and
 that's what gets eval'd. that's what gets eval'd.
  
-These final 2 steps are the reason I don't put dark-mode into a cron +These final 2 steps are the reason I don't put ''**dark-mode**(1)'' into a cron 
-job - it needs to run in my stack of kitty terminal tabs.+job - it needs to run in my stack of ''**kitty**(1)'' terminal tabs.
  
 ===KDE=== ===KDE===
Line 160: Line 161:
 KDE/Qt5/Plasma/whatcha-ma-call-it KDE/Qt5/Plasma/whatcha-ma-call-it
  
-Here be dragons. I have NO IDEA how to script this. If you know how to +Thanks to redditor r/progandy for this:
-script a theme change, please let me know!+
  
-===dark-mode=== +''**qt5ct**(1)'' is the key - install it (Fedora) with:
- +
-Here is the result of all this rambling+
  
 <code> <code>
-#!/usr/bin/env bash+sudo dnf install qt5ct 
 +</code>
  
-# dark-mode [on|off] +This needs to be in the session environment:
-# sets dark mode on or off+
  
-# best to run as: +<code> 
-# eval $( dark-mode on )+export QT_QPA_PLATFORMTHEME=qt5ct 
 +</code>
  
-# for emacs, these themes can be chosen from the standard ones (in +After running ''**qt5ct**(1)'' I now have a ''~/.config/qt5ct/qt5ct.conf'' file that contains line:
-# custom-theme-load-pathor they can be installed in +
-# custom-theme-directory (usually ~/.emacs.d) +
-# They must have filename of $THEMENAME-theme.el+
  
-light_emacs_theme="dichromacy-bh" +<code> 
-light_emacs_modeline_theme="smart-mode-line-light" +style=Adwaita 
-#dark_emacs_theme="manoj-dark-bh" +</code>
-dark_emacs_theme="dichromacy-dark-bh" +
-dark_emacs_modeline_theme="smart-mode-line-dark" +
-case "$1" in +
-    off|stop|reset|end|light) +
-        # light mode +
-        new_emacs_theme="$light_emacs_theme" +
-        prev_emacs_theme="$dark_emacs_theme" +
-        new_emacs_modeline_theme="$light_emacs_modeline_theme" +
-        prev_emacs_modeline_theme="$dark_emacs_modeline_theme"+
  
-        new_gtk_theme='Adwaita' +... I can hit that with my script and the qt5 programs automatically change their appearance!
-        new_fg='black' +
-        new_bg='white' +
-        BRIGHTNESS=100 +
-        TERM_BACKGROUND=light +
-        ;; +
-    *) +
-        # dark mode +
-        new_emacs_theme="$dark_emacs_theme" +
-        prev_emacs_theme="$light_emacs_theme" +
-        new_emacs_modeline_theme="$dark_emacs_modeline_theme" +
-        prev_emacs_modeline_theme="$light_emacs_modeline_theme"+
  
-        new_gtk_theme='Adwaita-dark' +Oddly, there's a 4s delay after changing the style in the file before the new style takes effect. But that's OK.
-        new_fg='white' +
-        new_bg='black' +
-        BRIGHTNESS=0 +
-        TERM_BACKGROUND=dark +
-        ;; +
-esac+
  
-+I also built [[https://gitlab.com/zetaPRIME/qt5ct-refresh|qt5ct-refresh]] but it doesn't seem to speed up the 4s delay or do anything AFAICT.
-    # look for an emacs running as this user: +
-    emacs_pid=$(pgrep -u $USER emacs head -n 1) +
-    [[ "$emacs_pid" ]] && +
-        emacsclient --eval " +
-          (progn +
-            (disable-theme '$prev_emacs_theme) +
-            (disable-theme '$prev_emacs_modeline_theme) +
-            (load-theme '$new_emacs_theme) +
-            (load-theme '$new_emacs_modeline_theme))"+
  
-    f=~/.gtkrc-2.0 +===dark-mode===
-    [[ -w $f ]] && +
-        sed -i "s/^gtk-theme-name=.*/gtk-theme-name=\"$new_gtk_theme\"/" $f +
-    gtkreload # gtk2 only!+
  
-    f=~/.config/gtk-3.0/settings.ini +Here is the result of all this rambling: https://gitlab.com/wef/dotfiles/-/blob/master/bin/dark-mode
-    [[ -w $f ]] && +
-        sed -i "s/^gtk-theme-name=.*/gtk-theme-name=$new_gtk_theme/" $f +
-    # /usr/libexec/gsd-xsettings notifies gtk3 clients start it in sway+
  
-    # these two appear to be comletely equivalent: 
-    dconf write /org/gnome/desktop/interface/gtk-theme "'$new_gtk_theme'" 
-    #gsettings set org.gnome.desktop.interface gtk-theme $new_gtk_theme 
- 
-    [[ "$KITTY_WINDOW_ID" ]] && 
-        kitty @ set_colors --all foreground=$new_fg background=$new_bg 
- 
-    brightness $BRIGHTNESS 
-) >/dev/null 
- 
-echo "TERM_BACKGROUND=$TERM_BACKGROUND; setup_prompt" 
-</code> 
sway/dark-mode.1602552417.txt.gz · Last modified: 2020/10/12 19:26 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki