-
Notifications
You must be signed in to change notification settings - Fork 0
/
wm-fullscreen-toggle
executable file
·63 lines (52 loc) · 1.97 KB
/
wm-fullscreen-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
62
63
#!/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-fullscreen-toggle
# - Toggle fullscreen mode for the focused window
# get platform info, populates 'platform' and 'apple_silicon' variables
source "${SCRIPT_DIR}"/lib/platform.sh
shopt -s xpg_echo
bold="\033[1m"
green="\033[32m"
reset="\033[0m"
function usage() {
echo "${bold}Usage:${reset} ${green}wm-fullscreen-toggle${reset}"
echo " - Toggle fullscreen mode for the focused window"
}
# print usage message on -h/--help
if [[ "$#" -eq 1 && ($1 == "-h" || $1 == "--help") ]]; then
usage
exit 0
fi
if [[ "$platform" == "macos" ]]; then
source "${SCRIPT_DIR}"/lib/wm-constants.sh
# first we handle the simple case of not being a scratchpad window
if ! wm-scratchpad-is-focused > /dev/null; then
yabai -m window --toggle zoom-fullscreen
else
# for yabai, a scratchpad window won't go fullscreen.
# This is because a scratchpad is a floating windows, and they can't be
# fullscreen. This is by desing:
# - https://github.com/koekeishiya/yabai/issues/317
# So we'll just change the grid to cover the entire screen if it's not
# already.
# And we check that by seeing if 'frame'.'x'. is at 0. Or, more specifically
# if it's value begins with "0" or "-0".
if [[ $(yabai -m query --windows --window | jq '.frame.x') =~ ^-?0 ]]; then
yabai -m window --grid "${YABAI_FLOATING_WINDOW_GRID}"
else
yabai -m window --grid 1:1:0:0:1:1
fi
fi
exit 0
fi
# swaymsg, fallback to i3-msg
source "${SCRIPT_DIR}"/lib/swaymsg.sh
# just call 'fullscreen'
swaymsg fullscreen