mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 22:22:40 +00:00
feat: Adds subcommand toggle-floating to windowctl.
This commit is contained in:
@@ -10,65 +10,104 @@ LOG_LABEL=$(basename "$THIS_FILE")
|
|||||||
THIS=${THIS:-$LOG_LABEL}
|
THIS=${THIS:-$LOG_LABEL}
|
||||||
LOG_FILE=${LOG_FILE:-"/tmp/$LOG_LABEL.log"}
|
LOG_FILE=${LOG_FILE:-"/tmp/$LOG_LABEL.log"}
|
||||||
|
|
||||||
|
address=""
|
||||||
|
width=""
|
||||||
|
height=""
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
Utility for toggling a windows floating property.
|
Utility for toggling a windows floating property.
|
||||||
|
|
||||||
|
If no address is supplied and '--active' flag is not set, then we will read address from stdin.
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
|
|
||||||
$ $THIS <flags> <address>
|
$ $THIS <flags> <address>
|
||||||
|
|
||||||
FLAGS:
|
FLAGS:
|
||||||
-a | --active: Toggle floating on the currently active window.
|
-a | --active: Toggles floating of the active window.
|
||||||
-w | --width <n>: Set a width of the floating window.
|
-w | --width <n>: Set a width of the floating window, can be pixels or percent (ex. 80%).
|
||||||
-h | --height <n>: Set a height of the floating window.
|
-h | --height <n>: Set a height of the floating window, can be pixels or percent (ex. 80%).
|
||||||
--help: Show this help page.
|
--help: Show this help page.
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
logging log --source "$THIS_FILE" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
# Suppress output of hyprctl
|
# Suppress output of hyprctl
|
||||||
hypr_dispatch() {
|
hypr_dispatch() {
|
||||||
hyprctl dispatch "$@" >/dev/null 2>&1 && return $?
|
hyprctl dispatch "$@" >/dev/null 2>&1 && return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle_floating() {
|
toggle_floating() {
|
||||||
local address="$1"
|
hypr_dispatch togglefloating "address:$address"
|
||||||
hypr_dispatch togglefloating
|
}
|
||||||
|
|
||||||
|
resize_window() {
|
||||||
|
if [[ -n $width ]] && [[ -n $height ]]; then
|
||||||
|
log "Resizing window: width: $width, height: $height"
|
||||||
|
hypr_dispatch resizewindowpixel exact "$width $height,address:$address"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "$address"
|
echo "$address"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
center_window() {
|
center_window() {
|
||||||
local address=""
|
local address=""
|
||||||
read -r address
|
read -r address
|
||||||
|
local activeaddress=$(hyprctl activewindow -j | jq -r '.address')
|
||||||
|
if [[ $address == $activeaddress ]]; then
|
||||||
|
log "Centering window..."
|
||||||
hypr_dispatch centerwindow
|
hypr_dispatch centerwindow
|
||||||
echo "$address"
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Float's a window, setting it's height and width and centering.
|
################################################################################
|
||||||
|
# MAIN
|
||||||
|
################################################################################
|
||||||
|
|
||||||
# The percentage of the screen size for the floating window.
|
# Setup logging
|
||||||
WIDTH_PERCENT=80
|
source "$SCRIPTS/hypr/logging"
|
||||||
HEIGHT_PERCENT=40
|
setup-logging "$LOG_FILE" "$LOG_LABEL"
|
||||||
|
|
||||||
floating=$(hyprctl activewindow -j | jq '.floating')
|
while [[ $# -gt 0 ]]; do
|
||||||
|
if [[ $1 == "--help" ]]; then
|
||||||
if [ "$floating" = "true" ]; then
|
usage && exit 0
|
||||||
hyprctl dispatch togglefloating
|
elif [[ $1 == "-w" ]] || [[ $1 == "--width" ]]; then
|
||||||
|
shift
|
||||||
|
width=$1
|
||||||
|
elif [[ $1 == "-h" ]] || [[ $1 == "--height" ]]; then
|
||||||
|
shift
|
||||||
|
height=$1
|
||||||
|
elif [[ $1 == "-a" ]] || [[ $1 == "--active" ]]; then
|
||||||
|
address=$(hyprctl activewindow -j | jq -r '.address')
|
||||||
else
|
else
|
||||||
monitor=$(hyprctl monitors -j | jq '.[] | select(.focused == true)')
|
address=$1
|
||||||
mw=$(echo "$monitor" | jq '.width')
|
fi
|
||||||
mh=$(echo "$monitor" | jq '.height')
|
shift
|
||||||
ms=$(echo "$monitor" | jq '.scale')
|
done
|
||||||
|
|
||||||
echo "scale: $ms"
|
if [[ -z $address ]]; then
|
||||||
|
read -p "Window address: " address
|
||||||
neww=$(echo "scale=6; (($mw / $ms) * $WIDTH_PERCENT / 100)" | bc)
|
fi
|
||||||
newh=$(echo "scale=6; (($mh / $ms) * $HEIGHT_PERCENT / 100)" | bc)
|
|
||||||
|
if [[ -z $address ]]; then
|
||||||
hyprctl dispatch togglefloating &&
|
log --error "No address was supplied" && exit 1
|
||||||
hyprctl dispatch resizeactive exact $neww $newh &&
|
fi
|
||||||
hyprctl dispatch centerwindow
|
|
||||||
|
log "Begin toggling floating for: '$address'"
|
||||||
|
|
||||||
|
floating=$(hyprctl clients -j | jq ".[] | select(.address == \"$address\") | .floating")
|
||||||
|
log "Is currently floating: $floating"
|
||||||
|
|
||||||
|
toggle_floating
|
||||||
|
|
||||||
|
if [ ! "$floating" == "true" ]; then
|
||||||
|
resize_window | center_window
|
||||||
fi
|
fi
|
||||||
|
|||||||
8
env/.local/scripts/hypr/windowctl
vendored
8
env/.local/scripts/hypr/windowctl
vendored
@@ -27,6 +27,7 @@ COMMANDS:
|
|||||||
focus: Focuses a window, handling special workspaces properly.
|
focus: Focuses a window, handling special workspaces properly.
|
||||||
launch: Launches an interactive picker in a new terminal.
|
launch: Launches an interactive picker in a new terminal.
|
||||||
picker: Window picker that prompts for an action to perform on the window.
|
picker: Window picker that prompts for an action to perform on the window.
|
||||||
|
toggle-floating: Toggles floating property of a window.
|
||||||
|
|
||||||
Run "$THIS <command> --help" for more information on a command.
|
Run "$THIS <command> --help" for more information on a command.
|
||||||
|
|
||||||
@@ -99,6 +100,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
shift
|
shift
|
||||||
show_picker "$@"
|
show_picker "$@"
|
||||||
exit $?
|
exit $?
|
||||||
|
elif [[ $1 == "toggle-floating" ]]; then
|
||||||
|
shift
|
||||||
|
THIS="$THIS toggle-floating" "$SCRIPTS/hypr/utils/windows/window-toggle-floating" "$@"
|
||||||
|
exit $?
|
||||||
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||||
usage && exit 0
|
usage && exit 0
|
||||||
else
|
else
|
||||||
@@ -107,3 +112,6 @@ while [[ $# -gt 0 ]]; do
|
|||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# If we've reached here then no commands were passed / handled.
|
||||||
|
usage && exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user