Compare commits

..

No commits in common. "9cdbb08f85335657c81938eba2ac3c1329632678" and "5499170badba703f8eab19ee0a41da1349ad3930" have entirely different histories.

4 changed files with 69 additions and 177 deletions

View file

@ -1,11 +0,0 @@
[*]
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,9 +7,12 @@ 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 to set the desired color schemes before use* (see Settings). It is *important that both the color scheme and the icon theme have both light
and dark variants*. For example, the Adwaita and Adwaita-dark GTK style and
the Elementary and Elementary-dark icon theme are such.
* https://github.com/bimlas/xfce4-night-mode (*please star if you like the plugin*) * https://gitlab.com/bimlas/xfce4-night-mode (main repository)
* https://github.com/bimlas/xfce4-night-mode (mirror, *please star if you like the plugin*)
== Command line usage == Command line usage
@ -43,65 +46,9 @@ 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,16 +1,17 @@
#!/bin/bash #!/bin/bash
# XFCE Night Mode controlled by Redshift # XFCE Night Mode controlled by Redshift
# #
# https://github.com/bimlas/xfce4-night-mode (please star if you like the plugin) # https://gitlab.com/bimlas/xfce4-night-mode (main repository)
# https://github.com/bimlas/xfce4-night-mode (mirror, please star if you like the plugin)
if ( LC_ALL='C' redshift -p 2> /dev/null | grep 'Period: Night' > /dev/null ); then if ( LC_ALL='C' redshift -vo 2> /dev/null | grep "Period: Daytime" > /dev/null ); then
mode='night'
else
mode='day' mode='day'
else
mode='night'
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,11 +1,12 @@
#!/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://github.com/bimlas/xfce4-night-mode (please star if you like the plugin) # https://gitlab.com/bimlas/xfce4-night-mode (main repository)
# 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'
@ -27,7 +28,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'
@ -36,50 +37,64 @@ 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 $1 --property $2)" current_theme=`xfconf-query --channel $2 --property $3`
declare -n target_theme="$3" if ( _is_mode_already_set "$current_theme" "$1" ); then
if [ "$current_theme" = "$target_theme" ]; then
return return
fi fi
xfconf-query --channel "$1" --property "$2" --set "$target_theme" new_theme=`_set_$1 "$current_theme" 2> /dev/null`
if [ $? != 0 ]; then if [ $? != 0 ]; then
show_usage show_usage
exit 1 exit 1
fi fi
if [ "$2" = "/Net/ThemeName" ] xfconf-query --channel $2 --property $3 --set "$new_theme"
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"
@ -88,76 +103,24 @@ function get_config()
echo "$result" echo "$result"
} }
function set_config() TEXT=`get_config 'text' 'string' '<span size="xx-large">&#x262F;</span>'`
{ SUNRISE=`get_config 'sunrise' 'string' '7:30'`
xfconf-query --channel 'night-mode' --property "/$1" --set "$3" --create --type "$2" SUNSET=`get_config 'sunset' 'string' '18:00'`
}
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_theme 'xsettings' '/Net/ThemeName' "GTK_$suffix" set_night_mode $mode xsettings /Net/ThemeName
# Icon theme # Icon theme
set_theme 'xsettings' '/Net/IconThemeName' "ICON_$suffix" set_night_mode $mode xsettings /Net/IconThemeName
# Cursor theme
set_theme 'xsettings' '/Gtk/CursorThemeName' "CURSOR_$suffix"
# Window manager theme # Window manager theme
set_theme 'xfwm4' '/general/theme' "WM_$suffix" # set_night_mode $mode xfwm4 /general/theme
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>"
@ -165,12 +128,4 @@ 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
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>" </tool>"