Created
April 10, 2025 03:28
-
-
Save mengwong/2e5168e6440f10545916073553236198 to your computer and use it in GitHub Desktop.
Hyprland “global hotkey” app switcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mengwong 20250405 | |
exec-once = ~/.config/hypr/manage-workspace.sh # Set up workspace on startup | |
# Direct application keybindings that launch or focus | |
bind = SUPER , E, exec, ~/.config/hypr/manage-workspace.sh emacs | |
bind = SUPER , F, exec, ~/.config/hypr/manage-workspace.sh firefox | |
bind = SUPER, 1, exec, ~/.config/hypr/manage-workspace.sh terminal1 | |
bind = SUPER SHIFT, 1, exec, ~/.config/hypr/manage-workspace.sh terminal1 | |
bind = SUPER, 2, exec, ~/.config/hypr/manage-workspace.sh terminal2 | |
bind = SUPER SHIFT, 2, exec, ~/.config/hypr/manage-workspace.sh terminal2 | |
bind = SUPER, 3, exec, ~/.config/hypr/manage-workspace.sh terminal3 | |
bind = SUPER SHIFT, 3, exec, ~/.config/hypr/manage-workspace.sh terminal3 | |
# command-T switches to firefox and opens a new tab. | |
bind = SUPER, T, exec, ~/.config/hypr/manage-workspace.sh firefox | |
bind = SUPER, T, sendshortcut, CTRL, T, firefox |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Save as ~/.config/hypr/manage-workspace.sh | |
# Function to check if a window exists in Hyprland | |
is_window_open() { | |
case "$1" in | |
"firefox") | |
hyprctl clients | grep -q "class: firefox" > /dev/null | |
;; | |
"emacs") | |
hyprctl clients | grep -q "class: Emacs" > /dev/null | |
;; | |
"terminal1") | |
hyprctl clients | grep -q "title: Terminal 1" > /dev/null | |
;; | |
"terminal2") | |
hyprctl clients | grep -q "title: Terminal 2" > /dev/null | |
;; | |
"terminal3") | |
hyprctl clients | grep -q "title: Terminal 3" > /dev/null | |
;; | |
esac | |
return $? | |
} | |
# Function to launch or focus applications | |
launch_or_focus() { | |
if ! is_window_open "$1" > /dev/null; then | |
# Launch the application if not running | |
case "$1" in | |
"firefox") | |
firefox & | |
;; | |
"emacs") | |
emacs & | |
;; | |
"terminal1") | |
kitty --title "Terminal 1" & | |
;; | |
"terminal2") | |
kitty --title "Terminal 2" & | |
;; | |
"terminal3") | |
kitty --title "Terminal 3" & | |
;; | |
esac | |
# Wait for launch | |
sleep 0.5 | |
fi | |
# Focus the window | |
case "$1" in | |
"firefox") | |
hyprctl dispatch focuswindow "firefox" | |
;; | |
"emacs") | |
hyprctl dispatch focuswindow "Emacs" | |
;; | |
"terminal1") | |
hyprctl dispatch focuswindow "title:(Terminal 1)" | |
;; | |
"terminal2") | |
hyprctl dispatch focuswindow "title:(Terminal 2)" | |
;; | |
"terminal3") | |
hyprctl dispatch focuswindow "title:(Terminal 3)" | |
;; | |
esac | |
} | |
# If no argument, launch all applications and arrange them | |
if [ -z "$1" ]; then | |
launch_or_focus "terminal1" | |
# TODO figure out how to movewindows around to get the desired result | |
else | |
# Launch or focus specific application | |
launch_or_focus "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment