diff options
| author | srdusr <trevorgray@srdusr.com> | 2023-08-09 23:55:19 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2023-08-09 23:55:19 +0200 |
| commit | 944c46c53c9d35c6dfbf50e01672f97377d3f37a (patch) | |
| tree | 471e1762b8d58e56919016b088945038e7b1633a | |
| parent | 692db3d7b9b80c1849b283738f6a2fe61ea0cdd2 (diff) | |
| download | dotfiles-944c46c53c9d35c6dfbf50e01672f97377d3f37a.tar.gz dotfiles-944c46c53c9d35c6dfbf50e01672f97377d3f37a.zip | |
Allowed kitty/alacritty to also work in wayland
| -rwxr-xr-x | scratchpad | 86 |
1 files changed, 47 insertions, 39 deletions
@@ -4,50 +4,58 @@ # Created On: Tue 07 Mar 2023 15:06:47 PM CAT # Project: Agnostic scratchpad/dropdown terminal that works on most window managers +# Dependencies: wmctrl, xprop, xdo, xdotool +# NOTE: Ensure script is included in system's path and can therefore be invoked with the command 'scratchpad'. +# Furthermore make sure the terminal is using x11 as a backend in wayland to allow this to work. +# example: wezterm.lua: enable_wayland = false, +# kitty.conf: linux_display_server x11 + # Set the GDK_BACKEND and QT_QPA_PLATFORM environment variables to x11 to allow working in Wayland export GDK_BACKEND=x11 export QT_QPA_PLATFORM=xcb +export WAYLAND_DISPLAY="" +export WINIT_UNIX_BACKEND=x11 # List of supported terminals with dropdown class supported_terminals=( - "wezterm" - "kitty" - "alacritty" + "wezterm" + "kitty" + "alacritty" ) # Check if any of the supported terminals with scratchpad class are running for term in "${supported_terminals[@]}"; do - if pgrep -f "$term.*--class scratchpad" >/dev/null; then - my_term="$term" - break - fi + if pgrep -f "$term.*--class scratchpad" >/dev/null; then + my_term="$term" + break + fi done # If none of the supported terminals are running, start the first available one if [ "$my_term" = "" ]; then - for term in "${supported_terminals[@]}"; do - if command -v "$term" >/dev/null 2>&1; then - my_term="$term" - break - fi - done - if [ "$my_term" = "" ]; then - echo "No supported terminal found." - exit 1 - fi + for term in "${supported_terminals[@]}"; do + if command -v "$term" >/dev/null 2>&1; then + my_term="$term" + break + fi + done + if [ "$my_term" = "" ]; then + echo "No supported terminal found." + exit 1 + fi - # Start the terminal with scratchpad class - case "$my_term" in - "wezterm") - wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & - ;; - "kitty") - kitty --class scratchpad tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & - ;; - "alacritty") - alacritty --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & - ;; - esac + # Start the terminal with scratchpad class + case "$my_term" in + "wezterm") + wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + "kitty") + kitty --class scratchpad tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + "alacritty") + alacritty --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + esac fi # Get the window ID of the scratchpad terminal @@ -55,14 +63,14 @@ id="$(xdo id -N scratchpad)" # Toggle the visibility of the scratchpad terminal if [ "$id" != "" ]; then - if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then - # The scratchpad window is visible, so hide it - dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" - xdo hide "$id" 2>/dev/null - else - # The scratchpad window is hidden, so show it - xdo show "$id" - # Restore the dimensions of the window - xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null - fi + if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then + # The scratchpad window is visible, so hide it + dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" + xdo hide "$id" 2>/dev/null + else + # The scratchpad window is hidden, so show it + xdo show "$id" + # Restore the dimensions of the window + xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null + fi fi |
