Compare commits

...

10 commits

Author SHA1 Message Date
bimlas
9cdbb08f85 Remove GitLab repo 2024-02-05 18:52:59 +01:00
bimlas
6bd5b9b8fd Add option to execute user script on mode change
Let the user execute custom commands on mode change, for example change
wallpaper, terminal theme, etc.
2023-09-28 23:51:46 +02:00
frithrah
4c6ae90598 Set GTK theme
Some apps don't react to automatic theme changes via xfconf-query
because they instead monitor the gtk-theme setting - Sublime Text is a
good example. This quick fix additionally sets the gtk-theme gsetting
to the target theme so these kind of apps will respond to theme
changes.
2022-05-20 12:29:11 +02:00
bimlas
04f1427ae9 Documentation update 2022-03-29 21:10:33 +02:00
bimlas
25d6bb10d3 Documentation update 2022-03-29 21:06:42 +02:00
bimlas
c167d7e764 Documentation update 2022-03-29 20:30:30 +02:00
Harm te Molder
3d28e9ebbf
Read themes from Settings Editor 2021-12-28 11:07:11 +01:00
Harm te Molder
eb3345b21f
Add .editorconfig 2021-12-28 10:09:34 +01:00
bimlas
6c8fbe773e Fix flickering of Redshift controlled night time
When we queried Redshift for the current time of day, the screen became
even redder for a short time because it wasn’t using the right switches.
2020-04-15 07:15:06 +02:00
bimlas
343f208cd8 Use Redshift's "Night" period instead of "Daytime"
Daytime -> Transition -> Night
2020-04-14 20:54:06 +02:00
4 changed files with 177 additions and 69 deletions

11
.editorconfig Executable file
View file

@ -0,0 +1,11 @@
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = true

View file

@ -7,12 +7,9 @@ https://docs.xfce.org/panel-plugins/xfce4-genmon-plugin[Generic Monitor
image::https://i.imgur.com/UVSz6QB.gif[] image::https://i.imgur.com/UVSz6QB.gif[]
It is *important that both the color scheme and the icon theme have both light *It is important to set the desired color schemes before use* (see Settings).
and dark variants*. For example, the Adwaita and Adwaita-dark GTK style and
the Elementary and Elementary-dark icon theme are such.
* https://gitlab.com/bimlas/xfce4-night-mode (main repository) * https://github.com/bimlas/xfce4-night-mode (*please star if you like the plugin*)
* https://github.com/bimlas/xfce4-night-mode (mirror, *please star if you like the plugin*)
== Command line usage == Command line usage
@ -46,9 +43,65 @@ to the settings (see later).
For settings, open the XFCE Settings Editor -> `night-mode` channel. For settings, open the XFCE Settings Editor -> `night-mode` channel.
To find out what values to enter, set the color schemes you want and copy them
from the appropriate location:
* GTK theme
** `xsettings/Net/ThemeName`
* Icon theme
** `xsettings/Net/IconThemeName`
* Cursor theme
** `xsettings/Gtk/CursorThemeName`
* Window manager theme
** `xfwm4/general/theme`
The specified `UserScript` will be executed when switching the mode, you can use
this for example to change the theme of the terminal, set desktop wallpaper,
etc. You can use the variable `XFCE_NIGHT_MODE` in your script if you want to
use the same script in both cases, for example:
....
#!/bin/bash
notify-send --icon "dialog-info" "Mode: $XFCE_NIGHT_MODE"
....
=== Example `UserScript`
==== Change wallpaper
First you have to find the property of the wallpaper (this could be different on
multi-monitor setup) by executing the command below then changing the wallpaper
in _Desktop_ setting.
```
xfconf-query --channel xfce4-desktop --monitor
```
You have to execute the command below to set up the wallpaper for this desktop.
```
xfconf-query --channel xfce4-desktop --property <property> --set </path/to/image.jpg>
```
==== Change panel dark mode
You have to execute the command below to change the panel mode opposite to the
windows mode (light windows, dark panel).
```
xfconf-query --channel xfce4-panel --property /panels/dark-mode --set "$([ "$XFCE_NIGHT_MODE" = "day" ] && echo true || echo false)"
```
=== Switch at a time specified by antoher program === Switch at a time specified by antoher program
For example, to use http://jonls.dk/redshift/[Redshift] or another program to For example, to use http://jonls.dk/redshift/[Redshift] or another program to
determine when it is night, use `xfce4-night-mode-redshift.sh` (or a modified determine when it is night, use `xfce4-night-mode-redshift.sh` (or a modified
version of it) instad of `xfce4-night-mode.sh` in "Generic Monitor plugin version of it) instad of `xfce4-night-mode.sh` in "Generic Monitor plugin
usage". usage".
== Changes
=== https://github.com/bimlas/xfce4-night-mode/-/compare/v1.0.0\...v2.0.0[2.0.0]
* Add options to change GTK, mouse, icon, and window manager theme
** *Breaking change*: You must set these before use

View file

@ -1,17 +1,16 @@
#!/bin/bash #!/bin/bash
# XFCE Night Mode controlled by Redshift # XFCE Night Mode controlled by Redshift
# #
# https://gitlab.com/bimlas/xfce4-night-mode (main repository) # https://github.com/bimlas/xfce4-night-mode (please star if you like the plugin)
# https://github.com/bimlas/xfce4-night-mode (mirror, please star if you like the plugin)
if ( LC_ALL='C' redshift -vo 2> /dev/null | grep "Period: Daytime" > /dev/null ); then if ( LC_ALL='C' redshift -p 2> /dev/null | grep 'Period: Night' > /dev/null ); then
mode='day'
else
mode='night' mode='night'
else
mode='day'
fi fi
"$(dirname "$0")/xfce4-night-mode.sh" $mode | sed '/<tool>/,/<\/tool>/ d' "$(dirname "$0")/xfce4-night-mode.sh" "$mode" | sed '/<tool>/,/<\/tool>/ d'
echo "<tool> echo '<tool>
Night mode defined by RedShift Night mode defined by RedShift
Click to toggle mode for a while Click to toggle mode for a while
</tool>" </tool>'

View file

@ -1,12 +1,11 @@
#!/bin/bash #!/bin/bash
# XFCE Night Mode: Switch between light and dark variants of a theme # XFCE Night Mode: Switch between light and dark variants of a theme
# #
# https://gitlab.com/bimlas/xfce4-night-mode (main repository) # https://github.com/bimlas/xfce4-night-mode (please star if you like the plugin)
# https://github.com/bimlas/xfce4-night-mode (mirror, please star if you like the plugin)
function show_usage() function show_usage()
{ {
progname=`basename "$0"` progname="$(basename $0)"
echo "$progname [night|day|toggle]" echo "$progname [night|day|toggle]"
echo "Without parameters it will set dark theme from $SUNSET to $SUNRISE" echo "Without parameters it will set dark theme from $SUNSET to $SUNRISE"
echo 'Use `xfce4-settings-editor` -> `night-mode` to modify settings' echo 'Use `xfce4-settings-editor` -> `night-mode` to modify settings'
@ -28,7 +27,7 @@ function parse_args()
function _get_mode_by_time() function _get_mode_by_time()
{ {
now=`date +"%H%M"` now="$(date '+%H%M')"
if [ $now -ge "${SUNRISE/:/}" -a $now -le "${SUNSET/:/}" ]; then if [ $now -ge "${SUNRISE/:/}" -a $now -le "${SUNSET/:/}" ]; then
echo 'day' echo 'day'
@ -37,64 +36,50 @@ function _get_mode_by_time()
fi fi
} }
function set_night_mode()
#######################################
# Set theme to requested theme if it is not already set
# Globals:
# GTK_LIGHT
# GTK_DARK
# ICON_LIGHT
# ICON_DARK
# CURSOR_LIGHT
# CURSOR_DARK
# WM_LIGHT
# WM_DARK
# Arguments:
# Channel: xfconf channel to change
# Property: property of that xfconf channel to change
# Variable name: global that contains the name of the requested theme
# Outputs:
# None
#######################################
function set_theme()
{ {
current_theme=`xfconf-query --channel $2 --property $3` current_theme="$(xfconf-query --channel $1 --property $2)"
if ( _is_mode_already_set "$current_theme" "$1" ); then declare -n target_theme="$3"
if [ "$current_theme" = "$target_theme" ]; then
return return
fi fi
new_theme=`_set_$1 "$current_theme" 2> /dev/null` xfconf-query --channel "$1" --property "$2" --set "$target_theme"
if [ $? != 0 ]; then if [ $? != 0 ]; then
show_usage show_usage
exit 1 exit 1
fi fi
xfconf-query --channel $2 --property $3 --set "$new_theme" if [ "$2" = "/Net/ThemeName" ]
} then
gsettings set org.gnome.desktop.interface gtk-theme "$target_theme"
function _is_mode_already_set()
{
if ( _is_dark "$1" ) && [ "$2" = "night" ]; then
exit 0
fi
if ! ( _is_dark "$1" ) && [ "$2" = "day" ]; then
exit 0
fi
exit 1
}
function _set_toggle()
{
if ( _is_dark "$1" ); then
_set_day "$1"
else
_set_night "$1"
fi
}
function _is_dark()
{
echo "$1" | grep '\-dark$' > /dev/null
}
function _set_day()
{
echo "${1%-dark}"
}
function _set_night()
{
if ( _is_dark "$1" ); then
echo "$1"
else
echo "$1-dark"
fi fi
} }
function get_config() function get_config()
{ {
result=`xfconf-query --channel 'night-mode' --property "/$1" 2> /dev/null` result="$(xfconf-query --channel 'night-mode' --property /$1 2> /dev/null)"
if ! [ "$result" ]; then if ! [ "$result" ]; then
result="$3" result="$3"
xfconf-query --channel 'night-mode' --property "/$1" --set "$result" --create --type "$2" xfconf-query --channel 'night-mode' --property "/$1" --set "$result" --create --type "$2"
@ -103,24 +88,76 @@ function get_config()
echo "$result" echo "$result"
} }
TEXT=`get_config 'text' 'string' '<span size="xx-large">&#x262F;</span>'` function set_config()
SUNRISE=`get_config 'sunrise' 'string' '7:30'` {
SUNSET=`get_config 'sunset' 'string' '18:00'` xfconf-query --channel 'night-mode' --property "/$1" --set "$3" --create --type "$2"
}
TEXT="$(get_config 'text' 'string' '<span size="xx-large">&#x262F;</span>')"
SUNRISE="$(get_config 'sunrise' 'string' '7:30')"
SUNSET="$(get_config 'sunset' 'string' '18:00')"
GTK_LIGHT="$(get_config 'Light/GtkTheme' 'string' $(xfconf-query --channel xsettings --property /Net/ThemeName))"
GTK_DARK="$(get_config 'Dark/GtkTheme' 'string' $(xfconf-query --channel xsettings --property /Net/ThemeName))"
ICON_LIGHT="$(get_config 'Light/IconTheme' 'string' $(xfconf-query --channel xsettings --property /Net/IconThemeName))"
ICON_DARK="$(get_config 'Dark/IconTheme' 'string' $(xfconf-query --channel xsettings --property /Net/IconThemeName))"
CURSOR_LIGHT="$(get_config 'Light/CursorTheme' 'string' $(xfconf-query --channel xsettings --property /Gtk/CursorThemeName))"
CURSOR_DARK="$(get_config 'Dark/CursorTheme' 'string' $(xfconf-query --channel xsettings --property /Gtk/CursorThemeName))"
WM_LIGHT="$(get_config 'Light/WindowManagerTheme' 'string' $(xfconf-query --channel xfwm4 --property /general/theme))"
WM_DARK="$(get_config 'Dark/WindowManagerTheme' 'string' $(xfconf-query --channel xfwm4 --property /general/theme))"
USERSCRIPT_LIGHT="$(get_config 'Light/UserScript' 'string')"
USERSCRIPT_DARK="$(get_config 'Dark/UserScript' 'string')"
mode="$(parse_args $@)"
mode=`parse_args $@`
if [ $? != 0 ]; then if [ $? != 0 ]; then
show_usage show_usage
exit 1 exit 1
fi fi
if [ "$mode" = "toggle" ]; then
current="$(get_config 'active' 'string' 'day')"
case "$current" in
day)
mode='night'
;;
night)
mode='day'
;;
*)
exit 1
esac
fi
case "$mode" in
day)
suffix='LIGHT'
;;
night)
suffix='DARK'
;;
*)
exit 1
esac
# GTK theme # GTK theme
set_night_mode $mode xsettings /Net/ThemeName set_theme 'xsettings' '/Net/ThemeName' "GTK_$suffix"
# Icon theme # Icon theme
set_night_mode $mode xsettings /Net/IconThemeName set_theme 'xsettings' '/Net/IconThemeName' "ICON_$suffix"
# Cursor theme
set_theme 'xsettings' '/Gtk/CursorThemeName' "CURSOR_$suffix"
# Window manager theme # Window manager theme
# set_night_mode $mode xfwm4 /general/theme set_theme 'xfwm4' '/general/theme' "WM_$suffix"
set_config 'active' 'string' "$mode"
# Execute user script to change wallpaper, terminal theme, etc.
userscript="USERSCRIPT_$suffix"
if [ ! -z "${!userscript}" ]; then
XFCE_NIGHT_MODE="$mode" eval "${!userscript}" 2>&1 > /dev/null
fi
echo "<txt>$TEXT</txt>" echo "<txt>$TEXT</txt>"
echo "<txtclick>$0 toggle</txtclick>" echo "<txtclick>$0 toggle</txtclick>"
@ -128,4 +165,12 @@ echo "<tool>
Night mode: $SUNSET - $SUNRISE Night mode: $SUNSET - $SUNRISE
Click to toggle mode for a while Click to toggle mode for a while
Use \`xfce4-settings-editor\` -> \`night-mode\` to modify settings Use \`xfce4-settings-editor\` -> \`night-mode\` to modify settings
</tool>"
To find out what values to enter, set the color schemes you want and copy
them from the appropriate location:
* GTK theme: \`xsettings/Net/ThemeName\`
* Icon theme: \`xsettings/Net/IconThemeName\`
* Cursor theme: \`xsettings/Gtk/CursorThemeName\`
* Window manager theme: \`xfwm4/general/theme\`
</tool>"