blob: 22f12920ec0da4e1641ea75383745c12a46b68a7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#!/usr/bin/env bash
# ==================================================
# KoolDots (2026)
# Project URL: https://github.com/LinuxBeginnings
# License: GNU GPLv3
# SPDX-License-Identifier: GPL-3.0-or-later
# ==================================================
# Waybar module for Hyprland layouts
IFS=$'\n\t'
SCRIPTSDIR="$HOME/.config/hypr/scripts"
rofi_config="$HOME/.config/rofi/config-waybar-layout.rasi"
change_layout="${SCRIPTSDIR}/ChangeLayout.sh"
layouts=(dwindle scrolling monocle master)
layout_icon() {
case "$1" in
dwindle) echo "š³" ;;
scrolling) echo "š
" ;;
monocle) echo "š¼" ;;
master) echo "ā" ;;
*) echo "ó°¹" ;;
esac
}
layout_name() {
case "$1" in
dwindle) echo "Dwindle" ;;
scrolling) echo "Scrolling" ;;
monocle) echo "Monocle" ;;
master) echo "Master" ;;
*) echo "Unknown" ;;
esac
}
get_layout() {
hyprctl -j getoption general:layout 2>/dev/null | jq -r '.str // "unknown"' 2>/dev/null
}
next_layout() {
local current="$1"
local i
for i in "${!layouts[@]}"; do
if [[ "${layouts[i]}" == "$current" ]]; then
echo "${layouts[((i + 1) % ${#layouts[@]})]}"
return
fi
done
echo "${layouts[0]}"
}
refresh_waybar() {
pkill -RTMIN+8 waybar 2>/dev/null || true
}
set_layout() {
local target="$1"
"$change_layout" "$target" && refresh_waybar
}
show_status() {
local current icon name tooltip
current="$(get_layout)"
icon="$(layout_icon "$current")"
name="$(layout_name "$current")"
tooltip="Hyprland layout: ${name} (${icon})\n\nLeft click: Select layout\nRight click: Cycle layout\n\nOptions:\nš³ Dwindle\nš
Scrolling\nš¼ Monocle\nā Master"
printf '{"text":"%s","tooltip":"%s","class":"%s"}\n' "$icon" "$tooltip" "$current"
}
show_menu() {
local current default_row choice target i
local options=()
current="$(get_layout)"
default_row=0
for i in "${!layouts[@]}"; do
local layout="${layouts[i]}"
local prefix=" "
if [[ "$layout" == "$current" ]]; then
prefix="ā "
default_row="$i"
fi
options+=("${prefix}$(layout_icon "$layout") $(layout_name "$layout")")
done
if pgrep -x rofi >/dev/null; then
pkill rofi
return 0
fi
choice="$(printf '%s\n' "${options[@]}" | rofi -i -dmenu -p "Layout" -mesg "Left click selects ⢠Right click cycles" -selected-row "$default_row" -config "$rofi_config")"
[[ -z "$choice" ]] && exit 0
case "$choice" in
*Dwindle*) target="dwindle" ;;
*Scrolling*) target="scrolling" ;;
*Monocle*) target="monocle" ;;
*Master*) target="master" ;;
*) exit 1 ;;
esac
set_layout "$target"
}
case "${1:-status}" in
status)
show_status
;;
menu)
show_menu
;;
next|toggle)
set_layout "$(next_layout "$(get_layout)")"
;;
dwindle|scrolling|monocle|master)
set_layout "$1"
;;
*)
echo "Usage: $(basename "$0") [status|menu|next|dwindle|scrolling|monocle|master]" >&2
exit 1
;;
esac
|