mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-15 06:32:40 +00:00
fix: Fixes windowctl not properly focusing windows on special workspaces, adds the ability to call windowctl with an address to perform certain actions without going through the pickers, should likely call from the launch script so code is shared / not duplicated in two spots.
This commit is contained in:
45
env/.local/scripts/hypr/windowctl
vendored
45
env/.local/scripts/hypr/windowctl
vendored
@@ -18,12 +18,12 @@ OPTIONS:
|
|||||||
|
|
||||||
--launch: Launch in a new terminal window, user will be prompted what to do with selected window.
|
--launch: Launch in a new terminal window, user will be prompted what to do with selected window.
|
||||||
-c | --clip: Copy selected window's address to the system clipboard.
|
-c | --clip: Copy selected window's address to the system clipboard.
|
||||||
-x | --close: Close the selected window.
|
-x | --close <address>: Close the selected window.
|
||||||
-f | --focus: Focus the selected window.
|
-f | --focus <address>: Focus the selected window, if optional address is supplied then we focus it.
|
||||||
-i | --ignore: Ignore the selected window.
|
-i | --ignore: Ignore the selected window.
|
||||||
-m | --move: Move the selected window to another workspace and switch to that workspace.
|
-m | --move <address>: Move the selected window to another workspace and switch to that workspace.
|
||||||
-s | --silent-move: Move the selected window to another workspace and remain on current workspace.
|
-s | --silent-move <address>: Move the selected window to another workspace and remain on current workspace.
|
||||||
-t | --to-workspace: Used with one of the move options to set which workspace to move to. If not supplied
|
-t | --to-workspace <id>: Used with one of the move options to set which workspace to move to. If not supplied
|
||||||
then we will prompt for a workspace to move to.
|
then we will prompt for a workspace to move to.
|
||||||
-h | --help: Show this page.
|
-h | --help: Show this page.
|
||||||
|
|
||||||
@@ -61,17 +61,25 @@ while [[ $# -gt 0 ]]; do
|
|||||||
clipboard_flag="1"
|
clipboard_flag="1"
|
||||||
elif [[ $1 =~ ^-x ]] || [[ $1 =~ ^--close ]]; then
|
elif [[ $1 =~ ^-x ]] || [[ $1 =~ ^--close ]]; then
|
||||||
close_flag="1"
|
close_flag="1"
|
||||||
|
selected_value=$2
|
||||||
|
shift
|
||||||
elif [[ $1 =~ ^-f ]] || [[ $1 =~ ^--focus ]]; then
|
elif [[ $1 =~ ^-f ]] || [[ $1 =~ ^--focus ]]; then
|
||||||
focus_flag="1"
|
focus_flag="1"
|
||||||
|
selected_value=$2
|
||||||
|
shift
|
||||||
elif [[ $1 =~ ^-h ]] || [[ $1 =~ ^--help ]]; then
|
elif [[ $1 =~ ^-h ]] || [[ $1 =~ ^--help ]]; then
|
||||||
usage && exit 0
|
usage && exit 0
|
||||||
elif [[ $1 =~ ^-i ]] || [[ $1 =~ ^--ignore ]]; then
|
elif [[ $1 =~ ^-i ]] || [[ $1 =~ ^--ignore ]]; then
|
||||||
ignore_flag="1"
|
ignore_flag="1"
|
||||||
elif [[ $1 =~ ^-m ]] || [[ $1 =~ ^--move ]]; then
|
elif [[ $1 =~ ^-m ]] || [[ $1 =~ ^--move ]]; then
|
||||||
move_flag="1"
|
move_flag="1"
|
||||||
|
selected_value=$2
|
||||||
|
shift
|
||||||
elif [[ $1 =~ ^-s ]] || [[ $1 =~ ^--silent-move ]]; then
|
elif [[ $1 =~ ^-s ]] || [[ $1 =~ ^--silent-move ]]; then
|
||||||
move_flag="1"
|
move_flag="1"
|
||||||
move_silent_flag="1"
|
move_silent_flag="1"
|
||||||
|
selected_value=$2
|
||||||
|
shift
|
||||||
elif [[ $1 =~ ^-t ]] || [[ $1 =~ ^--to-workspace ]]; then
|
elif [[ $1 =~ ^-t ]] || [[ $1 =~ ^--to-workspace ]]; then
|
||||||
shift
|
shift
|
||||||
move_to_workspace_name=$1
|
move_to_workspace_name=$1
|
||||||
@@ -114,6 +122,8 @@ ask_what_to_do_with_selection() {
|
|||||||
--preview-label="[ Description ]" \
|
--preview-label="[ Description ]" \
|
||||||
--preview='echo -e {1}'
|
--preview='echo -e {1}'
|
||||||
)
|
)
|
||||||
|
# Set choice to just the action portion.
|
||||||
|
choice="${choice#*:}"
|
||||||
log "Choice: $choice"
|
log "Choice: $choice"
|
||||||
if [[ $choice == "Quit" ]]; then
|
if [[ $choice == "Quit" ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
@@ -176,6 +186,20 @@ move_to_workspace() {
|
|||||||
hypr_dispatch $action "$workspace_id,address:$selected_value"
|
hypr_dispatch $action "$workspace_id,address:$selected_value"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
focus_window() {
|
||||||
|
log "Focusing window, selection: $selected_value"
|
||||||
|
local address="$selected_value"
|
||||||
|
local name=$(hyprctl clients -j | jq -r ".[] | select(.address == \"$address\") | .workspace.name")
|
||||||
|
local active_workspace=$(hyprctl activewindow -j | jq -r ".workspace.name")
|
||||||
|
log "Window workspace: '$name', active workspace: '$active_workspace'"
|
||||||
|
if [[ $name =~ ^special ]] && [[ ! $active_workspace == $name ]]; then
|
||||||
|
log "Toggling special workspace prior to focusing window."
|
||||||
|
name="${name#special:*}"
|
||||||
|
hypr_dispatch togglespecialworkspace $name
|
||||||
|
fi
|
||||||
|
hypr_dispatch focuswindow "address:$address"
|
||||||
|
}
|
||||||
|
|
||||||
handle_selected_value() {
|
handle_selected_value() {
|
||||||
if [[ $ignore_flag == "1" ]]; then
|
if [[ $ignore_flag == "1" ]]; then
|
||||||
log "Ignore flag set, selection: '$selected_value'"
|
log "Ignore flag set, selection: '$selected_value'"
|
||||||
@@ -185,9 +209,9 @@ handle_selected_value() {
|
|||||||
wl-copy $selected_value
|
wl-copy $selected_value
|
||||||
exit 0
|
exit 0
|
||||||
elif [[ $focus_flag == "1" ]]; then
|
elif [[ $focus_flag == "1" ]]; then
|
||||||
log "Focusing window, selection: $selected_value"
|
# log "Focusing window, selection: $selected_value"
|
||||||
hypr_dispatch focuswindow "address:$selected_value"
|
# hypr_dispatch focuswindow "address:$selected_value"
|
||||||
exit 0
|
focus_window && exit 0
|
||||||
elif [[ $close_flag == "1" ]]; then
|
elif [[ $close_flag == "1" ]]; then
|
||||||
log "Closing window, selection: $selected_value"
|
log "Closing window, selection: $selected_value"
|
||||||
hypr_dispatch closewindow "address:$selected_value"
|
hypr_dispatch closewindow "address:$selected_value"
|
||||||
@@ -207,6 +231,8 @@ handle_selected_value() {
|
|||||||
source "$SCRIPTS/hypr/logging"
|
source "$SCRIPTS/hypr/logging"
|
||||||
setup-logging "/tmp/$THIS.log" "$THIS"
|
setup-logging "/tmp/$THIS.log" "$THIS"
|
||||||
|
|
||||||
|
log "Starting with selected value: '$selected_value'"
|
||||||
|
|
||||||
if [[ $launch_flag == "1" ]]; then
|
if [[ $launch_flag == "1" ]]; then
|
||||||
ghostty --class="$window_class" --window-padding-x="$window_padding_x" \
|
ghostty --class="$window_class" --window-padding-x="$window_padding_x" \
|
||||||
--keybind="ctrl+c=quit" \
|
--keybind="ctrl+c=quit" \
|
||||||
@@ -218,7 +244,10 @@ else
|
|||||||
[[ -f $SCRIPTS/catppuccin-colors ]] &&
|
[[ -f $SCRIPTS/catppuccin-colors ]] &&
|
||||||
source $SCRIPTS/catppuccin-colors
|
source $SCRIPTS/catppuccin-colors
|
||||||
|
|
||||||
|
if [[ -z $selected_value ]]; then
|
||||||
selected_value=$("$SCRIPTS/hypr/window-picker")
|
selected_value=$("$SCRIPTS/hypr/window-picker")
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -n $selected_value ]]; then
|
if [[ -n $selected_value ]]; then
|
||||||
handle_selected_value
|
handle_selected_value
|
||||||
# If we got here then no flag was passed in initially on how to handle the
|
# If we got here then no flag was passed in initially on how to handle the
|
||||||
|
|||||||
Reference in New Issue
Block a user