mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 22:22:40 +00:00
fix: Fixes windowctl to handle when ctrl-c is hit from the window-picker, when not launched in a new terminal window. Adds a few more options to that allow to return to the window picker after performing certain actions on a selected window.
This commit is contained in:
2
env/.config/utils-launcher/config.json
vendored
2
env/.config/utils-launcher/config.json
vendored
@@ -12,7 +12,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Clipboard - clear history",
|
"name": "Clipboard - clear history",
|
||||||
"description": "Clear the clipboard history file.",
|
"description": "Clear the clipboard history file.",
|
||||||
"exec": "$SCRIPTS/hypr/clear-clipboard-history && echo Done"
|
"exec": "$SCRIPTS/hypr/clear-clipboard-history --notify-complete"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Monitors - stats / picker",
|
"name": "Monitors - stats / picker",
|
||||||
|
|||||||
19
env/.local/scripts/hypr/clear-clipboard-history
vendored
19
env/.local/scripts/hypr/clear-clipboard-history
vendored
@@ -1,8 +1,21 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#wl-copy --clear >/dev/null 2>&1 && \
|
notify_flag="0"
|
||||||
if [ -n "$WAYLAND_DISPLAY" ]; then
|
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
if [[ $1 == "-n" ]] || [[ $1 == "--notify-complete" ]]; then
|
||||||
|
notify_flag="1"
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -n "$WAYLAND_DISPLAY" ]]; then
|
||||||
wl-copy --clear
|
wl-copy --clear
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm ~/.local/share/clipse/clipboard_history.json >/dev/null 2>&1
|
rm $XDG_DATA_HOME/clipse/clipboard_history.json >/dev/null 2>&1
|
||||||
|
|
||||||
|
if [[ $notify_flag == "1" ]] && [[ -n "$WAYLAND_DISPLAY" ]]; then
|
||||||
|
notify-send --urgency=low --expire-time=3000 --app-name="Clipboard History" "✅ Cleared clipboard history"
|
||||||
|
fi
|
||||||
|
|||||||
2
env/.local/scripts/hypr/window-picker
vendored
2
env/.local/scripts/hypr/window-picker
vendored
@@ -76,9 +76,11 @@ sel=$(
|
|||||||
--preview-label='[ Window Stats ]' --delimiter='|' --with-nth=2 \
|
--preview-label='[ Window Stats ]' --delimiter='|' --with-nth=2 \
|
||||||
--preview="$SCRIPTS/hypr/preview-stats window {1}"
|
--preview="$SCRIPTS/hypr/preview-stats window {1}"
|
||||||
)
|
)
|
||||||
|
status=$?
|
||||||
|
|
||||||
[[ -z $sel ]] && exit 1
|
[[ -z $sel ]] && exit 1
|
||||||
|
|
||||||
# revove everything but the address portion.
|
# revove everything but the address portion.
|
||||||
sel=${sel%%|*}
|
sel=${sel%%|*}
|
||||||
echo "$sel"
|
echo "$sel"
|
||||||
|
exit $status
|
||||||
|
|||||||
99
env/.local/scripts/hypr/windowctl
vendored
99
env/.local/scripts/hypr/windowctl
vendored
@@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
THIS_FILE=${BASH_SOURCE[0]}
|
THIS_FILE=${BASH_SOURCE[0]}
|
||||||
THIS=$(basename $THIS_FILE)
|
THIS=$(basename $THIS_FILE)
|
||||||
|
|
||||||
@@ -47,6 +46,8 @@ launch_flag="0"
|
|||||||
move_flag="0"
|
move_flag="0"
|
||||||
move_silent_flag="0"
|
move_silent_flag="0"
|
||||||
move_to_workspace_name=""
|
move_to_workspace_name=""
|
||||||
|
refresh_flag="0"
|
||||||
|
should_quit="0"
|
||||||
|
|
||||||
launch_args=()
|
launch_args=()
|
||||||
selected_value=""
|
selected_value=""
|
||||||
@@ -104,10 +105,26 @@ log() {
|
|||||||
logging log --source "$THIS_FILE" "$@"
|
logging log --source "$THIS_FILE" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Reset flags and selection.
|
||||||
|
reset_flags() {
|
||||||
|
selected_value=""
|
||||||
|
clipboard_flag="0"
|
||||||
|
close_flag="0"
|
||||||
|
focus_flag="0"
|
||||||
|
ignore_flag="0"
|
||||||
|
launch_flag="0"
|
||||||
|
move_flag="0"
|
||||||
|
move_silent_flag="0"
|
||||||
|
move_to_workspace_name=""
|
||||||
|
refresh_flag="0"
|
||||||
|
should_quit="0"
|
||||||
|
}
|
||||||
|
|
||||||
ask_what_to_do_with_selection() {
|
ask_what_to_do_with_selection() {
|
||||||
local choices=(
|
local choices=(
|
||||||
"Focus the selected window.:Focus window"
|
"Focus the selected window.:Focus window"
|
||||||
"Close the selected window.:Close window"
|
"Close the selected window.:Close window"
|
||||||
|
"Close the selected window and go back to the window list.:Close window and back"
|
||||||
"Move the selected window to another workspace, focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace"
|
"Move the selected window to another workspace, focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace"
|
||||||
"Move the selected window to another workspace, without focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace - silent"
|
"Move the selected window to another workspace, without focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace - silent"
|
||||||
"Copy the window address to the system clipboard:Copy to clipboard"
|
"Copy the window address to the system clipboard:Copy to clipboard"
|
||||||
@@ -120,27 +137,38 @@ ask_what_to_do_with_selection() {
|
|||||||
--delimiter=':' --with-nth=2 \
|
--delimiter=':' --with-nth=2 \
|
||||||
--header="What should we do with the selected window?" \
|
--header="What should we do with the selected window?" \
|
||||||
--preview-label="[ Description ]" \
|
--preview-label="[ Description ]" \
|
||||||
--preview='echo -e {1}'
|
--preview="echo -e {1}; echo -e '\n\n\e[35mSelected Window:\e[0m'; $SCRIPTS/hypr/preview-stats window $selected_value;"
|
||||||
)
|
)
|
||||||
# Set choice to just the action portion.
|
# Set choice to just the action portion.
|
||||||
choice="${choice#*:}"
|
choice="${choice#*:}"
|
||||||
log "Choice: $choice"
|
log "Choice: $choice"
|
||||||
|
|
||||||
|
# Set appropriate flags based on the choice.
|
||||||
if [[ $choice == "Quit" ]]; then
|
if [[ $choice == "Quit" ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
elif [[ $choice == "Close window" ]]; then
|
elif [[ $choice == "Close window" ]]; then
|
||||||
|
should_quit="1"
|
||||||
close_flag="1"
|
close_flag="1"
|
||||||
|
elif [[ $choice == "Close window and back" ]]; then
|
||||||
|
close_flag="1"
|
||||||
|
refresh_flag="1"
|
||||||
|
should_quit="0"
|
||||||
elif [[ $choice == "Copy to clipboard" ]]; then
|
elif [[ $choice == "Copy to clipboard" ]]; then
|
||||||
|
should_quit="1"
|
||||||
clipboard_flag="1"
|
clipboard_flag="1"
|
||||||
elif [[ $choice == "Focus window" ]]; then
|
elif [[ $choice == "Focus window" ]]; then
|
||||||
|
should_quit="1"
|
||||||
focus_flag="1"
|
focus_flag="1"
|
||||||
elif [[ $choice == "Move to workspace" ]]; then
|
elif [[ $choice == "Move to workspace" ]]; then
|
||||||
|
should_quit="1"
|
||||||
move_flag="1"
|
move_flag="1"
|
||||||
elif [[ $choice == "Move to workspace - silent" ]]; then
|
elif [[ $choice == "Move to workspace - silent" ]]; then
|
||||||
|
should_quit="1"
|
||||||
move_silent_flag="1"
|
move_silent_flag="1"
|
||||||
move_flag="1"
|
move_flag="1"
|
||||||
elif [[ $choice == "Refresh window list" ]]; then
|
elif [[ $choice == "Refresh window list" ]]; then
|
||||||
eval exec ${BASH_SOURCE[0]}
|
refresh_flag="1"
|
||||||
exit 0
|
should_quit="0"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,20 +235,23 @@ handle_selected_value() {
|
|||||||
elif [[ $clipboard_flag == "1" ]]; then
|
elif [[ $clipboard_flag == "1" ]]; then
|
||||||
log "Copying to clipboard, selection: $selected_value"
|
log "Copying to clipboard, selection: $selected_value"
|
||||||
wl-copy $selected_value
|
wl-copy $selected_value
|
||||||
exit 0
|
|
||||||
elif [[ $focus_flag == "1" ]]; then
|
elif [[ $focus_flag == "1" ]]; then
|
||||||
# log "Focusing window, selection: $selected_value"
|
focus_window
|
||||||
# hypr_dispatch focuswindow "address:$selected_value"
|
|
||||||
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"
|
||||||
exit 0
|
if [[ $refresh_flag == "1" ]]; then
|
||||||
|
log "Refreshing windows..."
|
||||||
|
# Need to sleep here breifly otherwise recently closed windows will still show
|
||||||
|
# in the window picker.
|
||||||
|
reset_flags && sleep 0.3
|
||||||
|
fi
|
||||||
elif [[ $move_flag == "1" ]] || [[ $move_silent_flag == "1" ]]; then
|
elif [[ $move_flag == "1" ]] || [[ $move_silent_flag == "1" ]]; then
|
||||||
move_to_workspace && exit 0
|
move_to_workspace
|
||||||
|
# && exit 0
|
||||||
|
else
|
||||||
|
log "No flag set, selection: '$selected_value'"
|
||||||
fi
|
fi
|
||||||
# TODO: Choose from list of what to do with the selected_value.
|
|
||||||
log "No flag set, selection: '$selected_value'"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
@@ -244,19 +275,39 @@ 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")
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n $selected_value ]]; then
|
if [[ -n $selected_value ]]; then
|
||||||
handle_selected_value
|
# Handle value if it was passed in.
|
||||||
# If we got here then no flag was passed in initially on how to handle the
|
# TODO: This should probably ensure that flags were set.
|
||||||
# selected window, so ask what they'd like to do. Then handle it.
|
handle_selected_value && exit 0
|
||||||
log "Asking what to do with selction."
|
else
|
||||||
ask_what_to_do_with_selection
|
|
||||||
|
|
||||||
[[ -n $selected_value ]] && handle_selected_value
|
trap 'log "Stoping..."; should_quit="1"' SIGINT
|
||||||
# If you make it here, We just give up... Don't start an endless loop.
|
|
||||||
log "Giving up without a selection."
|
while [[ $should_quit == "0" ]]; do
|
||||||
|
|
||||||
|
# not sure if this should be here or somewhere else, as it will
|
||||||
|
# cause any passed in flags to be ignored, but they're generally empty
|
||||||
|
# when using this interactive mode anyway.
|
||||||
|
reset_flags
|
||||||
|
|
||||||
|
selected_value=$("$SCRIPTS/hypr/window-picker")
|
||||||
|
status=$?
|
||||||
|
|
||||||
|
if [[ $status -ne 0 ]]; then
|
||||||
|
should_quit="1"
|
||||||
|
else
|
||||||
|
if [[ -n $selected_value ]]; then
|
||||||
|
handle_selected_value
|
||||||
|
# If we got here then no flag was passed in initially on how to handle the
|
||||||
|
# selected window, so ask what they'd like to do. Then handle it.
|
||||||
|
log "Asking what to do with selction."
|
||||||
|
ask_what_to_do_with_selection
|
||||||
|
|
||||||
|
[[ -n $selected_value ]] && handle_selected_value
|
||||||
|
# If you make it here, We just give up... Don't start an endless loop.
|
||||||
|
# log "Giving up without a selection."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user