Compare commits
10 commits
5499170bad
...
9cdbb08f85
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cdbb08f85 | ||
|
|
6bd5b9b8fd | ||
|
|
4c6ae90598 | ||
|
|
04f1427ae9 | ||
|
|
25d6bb10d3 | ||
|
|
c167d7e764 | ||
|
|
3d28e9ebbf | ||
|
|
eb3345b21f | ||
|
|
6c8fbe773e | ||
|
|
343f208cd8 |
4 changed files with 177 additions and 69 deletions
11
.editorconfig
Executable file
11
.editorconfig
Executable 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
|
||||
63
README.adoc
63
README.adoc
|
|
@ -7,12 +7,9 @@ https://docs.xfce.org/panel-plugins/xfce4-genmon-plugin[Generic Monitor
|
|||
|
||||
image::https://i.imgur.com/UVSz6QB.gif[]
|
||||
|
||||
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.
|
||||
*It is important to set the desired color schemes before use* (see Settings).
|
||||
|
||||
* https://gitlab.com/bimlas/xfce4-night-mode (main repository)
|
||||
* https://github.com/bimlas/xfce4-night-mode (mirror, *please star if you like the plugin*)
|
||||
* https://github.com/bimlas/xfce4-night-mode (*please star if you like the plugin*)
|
||||
|
||||
== Command line usage
|
||||
|
||||
|
|
@ -46,9 +43,65 @@ to the settings (see later).
|
|||
|
||||
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
|
||||
|
||||
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
|
||||
version of it) instad of `xfce4-night-mode.sh` in "Generic Monitor plugin
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
#!/bin/bash
|
||||
# XFCE Night Mode controlled by Redshift
|
||||
#
|
||||
# https://gitlab.com/bimlas/xfce4-night-mode (main repository)
|
||||
# https://github.com/bimlas/xfce4-night-mode (mirror, please star if you like the plugin)
|
||||
# https://github.com/bimlas/xfce4-night-mode (please star if you like the plugin)
|
||||
|
||||
if ( LC_ALL='C' redshift -vo 2> /dev/null | grep "Period: Daytime" > /dev/null ); then
|
||||
mode='day'
|
||||
else
|
||||
if ( LC_ALL='C' redshift -p 2> /dev/null | grep 'Period: Night' > /dev/null ); then
|
||||
mode='night'
|
||||
else
|
||||
mode='day'
|
||||
fi
|
||||
|
||||
"$(dirname "$0")/xfce4-night-mode.sh" $mode | sed '/<tool>/,/<\/tool>/ d'
|
||||
echo "<tool>
|
||||
"$(dirname "$0")/xfce4-night-mode.sh" "$mode" | sed '/<tool>/,/<\/tool>/ d'
|
||||
echo '<tool>
|
||||
Night mode defined by RedShift
|
||||
Click to toggle mode for a while
|
||||
</tool>"
|
||||
</tool>'
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
#!/bin/bash
|
||||
# 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 (mirror, please star if you like the plugin)
|
||||
# https://github.com/bimlas/xfce4-night-mode (please star if you like the plugin)
|
||||
|
||||
function show_usage()
|
||||
{
|
||||
progname=`basename "$0"`
|
||||
progname="$(basename $0)"
|
||||
echo "$progname [night|day|toggle]"
|
||||
echo "Without parameters it will set dark theme from $SUNSET to $SUNRISE"
|
||||
echo 'Use `xfce4-settings-editor` -> `night-mode` to modify settings'
|
||||
|
|
@ -28,7 +27,7 @@ function parse_args()
|
|||
|
||||
function _get_mode_by_time()
|
||||
{
|
||||
now=`date +"%H%M"`
|
||||
now="$(date '+%H%M')"
|
||||
|
||||
if [ $now -ge "${SUNRISE/:/}" -a $now -le "${SUNSET/:/}" ]; then
|
||||
echo 'day'
|
||||
|
|
@ -37,64 +36,50 @@ function _get_mode_by_time()
|
|||
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`
|
||||
if ( _is_mode_already_set "$current_theme" "$1" ); then
|
||||
current_theme="$(xfconf-query --channel $1 --property $2)"
|
||||
declare -n target_theme="$3"
|
||||
|
||||
if [ "$current_theme" = "$target_theme" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
new_theme=`_set_$1 "$current_theme" 2> /dev/null`
|
||||
xfconf-query --channel "$1" --property "$2" --set "$target_theme"
|
||||
|
||||
if [ $? != 0 ]; then
|
||||
show_usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
xfconf-query --channel $2 --property $3 --set "$new_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"
|
||||
if [ "$2" = "/Net/ThemeName" ]
|
||||
then
|
||||
gsettings set org.gnome.desktop.interface gtk-theme "$target_theme"
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
result="$3"
|
||||
xfconf-query --channel 'night-mode' --property "/$1" --set "$result" --create --type "$2"
|
||||
|
|
@ -103,24 +88,76 @@ function get_config()
|
|||
echo "$result"
|
||||
}
|
||||
|
||||
TEXT=`get_config 'text' 'string' '<span size="xx-large">☯</span>'`
|
||||
SUNRISE=`get_config 'sunrise' 'string' '7:30'`
|
||||
SUNSET=`get_config 'sunset' 'string' '18:00'`
|
||||
function set_config()
|
||||
{
|
||||
xfconf-query --channel 'night-mode' --property "/$1" --set "$3" --create --type "$2"
|
||||
}
|
||||
|
||||
TEXT="$(get_config 'text' 'string' '<span size="xx-large">☯</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
|
||||
show_usage
|
||||
exit 1
|
||||
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
|
||||
set_night_mode $mode xsettings /Net/ThemeName
|
||||
set_theme 'xsettings' '/Net/ThemeName' "GTK_$suffix"
|
||||
|
||||
# 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
|
||||
# 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 "<txtclick>$0 toggle</txtclick>"
|
||||
|
|
@ -128,4 +165,12 @@ echo "<tool>
|
|||
Night mode: $SUNSET - $SUNRISE
|
||||
Click to toggle mode for a while
|
||||
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>"
|
||||
|
|
|
|||
Loading…
Reference in a new issue