-
Notifications
You must be signed in to change notification settings - Fork 0
/
wm-float-toggle
executable file
·61 lines (52 loc) · 2.03 KB
/
wm-float-toggle
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
#!/usr/bin/env bash
# SCRIPT_DIR is set to the directory where this script is localed. It it was
# run by a symlink, it will be resolved to the directory of the target script
# (that is, the actual script directory).
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [[ -L "${BASH_SOURCE[0]}" ]]; then
SCRIPT_DIR="$(readlink "${BASH_SOURCE[0]}")"
SCRIPT_DIR="$( cd "$( dirname "${SCRIPT_DIR}" )" >/dev/null 2>&1 && pwd )"
fi
# wm-float-toggle
# - This is a window manager function (currently configured only for sway)
# - Toggle the current focus between tiling and floating mode
# - If becoming floating, add a border
# - If becoming tiling, remove the border
# - This command is meant to be bound to the "float toggle" keybinding in the
# window manager, therefore there is no need to run it directly from a
# terminal.
# get platform info, populates 'platform' and 'apple_silicon' variables
source "${SCRIPT_DIR}"/lib/platform.sh
# print usage on -h/--help
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo "Usage: wm-float-toggle"
echo " - Toggle the current focus between tiling and floating mode"
echo " - If becoming floating, add a border"
echo " - If becoming tiling, remove the border"
exit
fi
if [[ "$platform" == "macos" ]]; then
# for yabai, just toggle float and center on screen
# unfortunally borders are not supported
yabai -m window --toggle float --grid 4:4:1:1:2:2
exit
fi
# check is the focus is floating by checking "get_tree"
# - if the focused node has "type" == "floating_con", it is floating
floating=$(swaymsg -t get_tree | jq -r '.. | select(.focused?) | .type')
if [[ "$floating" == "floating_con" ]]; then
floating="true"
else
floating="false"
fi
if [[ "$floating" == "true" ]]; then
# if floating, make it tiling
command="floating disable, border none"
else
# if tiling, make it floating
command="floating enable, border pixel 1"
fi
# print message to window manager log
echo "wm-float-toggle: ${command}"
# send command to sway
swaymsg "${command}"