diff options
Diffstat (limited to 'dot_config/i3/scripts')
-rw-r--r-- | dot_config/i3/scripts/executable_battery2 | 1 | ||||
-rw-r--r-- | dot_config/i3/scripts/executable_monitor | 125 |
2 files changed, 126 insertions, 0 deletions
diff --git a/dot_config/i3/scripts/executable_battery2 b/dot_config/i3/scripts/executable_battery2 index 2d55dab..d4b69db 100644 --- a/dot_config/i3/scripts/executable_battery2 +++ b/dot_config/i3/scripts/executable_battery2 | |||
@@ -70,6 +70,7 @@ else: | |||
70 | elif state == "Full": | 70 | elif state == "Full": |
71 | fulltext = FA_PLUG + " " | 71 | fulltext = FA_PLUG + " " |
72 | timeleft = "" | 72 | timeleft = "" |
73 | |||
73 | elif state == "Unknown": | 74 | elif state == "Unknown": |
74 | fulltext = FA_QUESTION + " " + FA_BATTERY + " " | 75 | fulltext = FA_QUESTION + " " + FA_BATTERY + " " |
75 | timeleft = "" | 76 | timeleft = "" |
diff --git a/dot_config/i3/scripts/executable_monitor b/dot_config/i3/scripts/executable_monitor new file mode 100644 index 0000000..9ec2f39 --- /dev/null +++ b/dot_config/i3/scripts/executable_monitor | |||
@@ -0,0 +1,125 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | # | ||
3 | # Use rofi to switch between different screen layouts. | ||
4 | # | ||
5 | # Note: this currently relies on associative array support in the shell. | ||
6 | # | ||
7 | # Inspired from i3pystatus wiki: | ||
8 | # https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu | ||
9 | # | ||
10 | # Copyright 2022 Jinwei Zhao <i at jinwei dot me> | ||
11 | # | ||
12 | # This program is free software: you can redistribute it and/or modify | ||
13 | # it under the terms of the GNU General Public License as published by | ||
14 | # the Free Software Foundation, either version 3 of the License, or | ||
15 | # (at your option) any later version. | ||
16 | |||
17 | # This program is distributed in the hope that it will be useful, | ||
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | # GNU General Public License for more details. | ||
21 | |||
22 | # You should have received a copy of the GNU General Public License | ||
23 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
24 | |||
25 | # modified to work with latest rofi update by joekamprad <[email protected]> | ||
26 | |||
27 | ####################################################################### | ||
28 | # BEGIN CONFIG # | ||
29 | ####################################################################### | ||
30 | |||
31 | # Colors: FG (foreground), BG (background), HL (highlighted) | ||
32 | FG_COLOR="#bbbbbb" | ||
33 | BG_COLOR="#111111" | ||
34 | HLFG_COLOR="#111111" | ||
35 | HLBG_COLOR="#bbbbbb" | ||
36 | BORDER_COLOR="#222222" | ||
37 | |||
38 | # Options not related to colors (most rofi options do not work anymore) | ||
39 | ROFI_OPTIONS=(-theme ~/.config/rofi/monitor.rasi) | ||
40 | |||
41 | ####################################################################### | ||
42 | # END CONFIG # | ||
43 | ####################################################################### | ||
44 | |||
45 | # Preferred launcher if both are available | ||
46 | preferred_launcher="rofi" | ||
47 | |||
48 | # Check whether the user-defined launcher is valid | ||
49 | launcher_list=(rofi) | ||
50 | function check_launcher() { | ||
51 | if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then | ||
52 | echo "Supported launchers: ${launcher_list[*]}" | ||
53 | exit 1 | ||
54 | else | ||
55 | # Get array with unique elements and preferred launcher first | ||
56 | # Note: uniq expects a sorted list, so we cannot use it | ||
57 | i=1 | ||
58 | launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \ | ||
59 | | sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' ')) | ||
60 | fi | ||
61 | } | ||
62 | |||
63 | # Parse CLI arguments | ||
64 | while getopts "hcp:" option; do | ||
65 | case "${option}" in | ||
66 | p) preferred_launcher="${OPTARG}" | ||
67 | check_launcher "${preferred_launcher}" | ||
68 | ;; | ||
69 | *) exit 1 | ||
70 | ;; | ||
71 | esac | ||
72 | done | ||
73 | |||
74 | # Check whether a command exists | ||
75 | function command_exists() { | ||
76 | command -v "$1" &> /dev/null 2>&1 | ||
77 | } | ||
78 | |||
79 | # menu defined as an associative array | ||
80 | typeset -A menu | ||
81 | |||
82 | menu=( | ||
83 | [Home]="xrandr --output eDP-1 --primary --mode 2256x1504 --pos 0x1080 --rotate normal --output DP-1 --off --output DP-2 --off --output DP-3 --mode 1920x1080 --pos 0x0 --rotate normal --output DP-4 --off && nitrogen --restore" | ||
84 | [Lab]="xrandr --output eDP-1 --primary --mode 2256x1504 --pos 0x1200 --rotate normal --output DP-1 --off --output DP-2 --off --output DP-3 --off --output DP-4 --mode 1920x1200 --pos 0x0 --rotate normal && nitrogen --restore" | ||
85 | [Builtin]="xrandr --output eDP-1 --primary --mode 2256x1504 --pos 0x0 --rotate normal --output DP-1 --off --output DP-2 --off --output DP-3 --off --output DP-4 --off && nitrogen --restore" | ||
86 | ) | ||
87 | |||
88 | menu_nrows=${#menu[@]} | ||
89 | |||
90 | launcher_exe="" | ||
91 | launcher_options="" | ||
92 | rofi_colors="" | ||
93 | |||
94 | function prepare_launcher() { | ||
95 | if [[ "$1" == "rofi" ]]; then | ||
96 | rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \ | ||
97 | -hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}") | ||
98 | launcher_exe="rofi" | ||
99 | launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \ | ||
100 | "${rofi_colors}" "${ROFI_OPTIONS[@]}") | ||
101 | elif [[ "$1" == "zenity" ]]; then | ||
102 | launcher_exe="zenity" | ||
103 | launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \ | ||
104 | "${ZENITY_OPTIONS[@]}") | ||
105 | fi | ||
106 | } | ||
107 | |||
108 | for l in "${launcher_list[@]}"; do | ||
109 | if command_exists "${l}" ; then | ||
110 | prepare_launcher "${l}" | ||
111 | break | ||
112 | fi | ||
113 | done | ||
114 | |||
115 | # No launcher available | ||
116 | if [[ -z "${launcher_exe}" ]]; then | ||
117 | exit 1 | ||
118 | fi | ||
119 | |||
120 | launcher=(${launcher_exe} "${launcher_options[@]}") | ||
121 | selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")" | ||
122 | |||
123 | if [[ $? -eq 0 && ! -z ${selection} ]]; then | ||
124 | i3-msg -q "exec --no-startup-id ${menu[${selection}]}" | ||
125 | fi | ||