Skip to content

[Feature Requests] Behaviors related to focusing windows underneath other windows #6

Description

@SturgeonInc

I have a script meant for using a trackpad gesture to cycle windows that are stacked on top of each other (using the window cursor location rather than the active window as the target), kind of like a regional alt-tab.

This is kind of how I expected the "Activate Window Above" / "Activate Window Below" / "Activate window under" options to work like, but it is different, although I can't really explain the difference because I'm not very sure what the intended behavior for those actions actually is, so below is the script (it requires xdotool and wmctrl).

So my first request is clearer documentation on what those three actions do, especially "window below" vs "window under."

My second request is if the feature seen in the script could be ported, if you find it intuitive and useful.

My third request, related to that second request: in exploring the EndeavourOS iso installer preview (I say this as I'm unsure if it's a KDE feature or a sway feature), Super+left/right arrow changes the focus, just like the extension currently does. But, when there are no windows to the left/right of the focused window to give focus to, it will attempt to give focus to the window under the focused window, kind of like my script does. I find this to be very intuitive and useful behavior, and was hoping that maybe this also could be added, although maybe with a checkbox to enable it.

#!/usr/bin/env sh
# focus window under cursor and behind visible window.
# if there are multiple, then the order is determined by
# window IDs

# Usage: cyclewin-gesture.sh [-r]
#   -r  Reverse order of cycling

# gives X, Y, and WINDOW
eval "$(xdotool getmouselocation --shell)"
cursorY=$Y
cursorX=$X
visibleWin="$WINDOW"
DESKTOP="$(xdotool get_desktop)"

# get all windows in current desktop, and sort by ID
if [ "$1" = -r ]; then
    windows="$(xdotool search --all --desktop "$DESKTOP" --name '.*' | sort -r)"
else
    windows="$(xdotool search --all --desktop "$DESKTOP" --name '.*' | sort)"
fi

# cut and pastes the part of the list *after* the top (visible) window to the front,
# ensuring that cycling actually happens
# (instead of the lowest/highest ID windows always winning)
# also removes the already visible window from the listing, 
# so it isn't "switched" to it
windows="${windows#*"$visibleWin"} ${windows%%"$visibleWin"*}"

for win in $windows; do
    # gives WINDOW, WIDTH, and HEIGHT
    eval "$(xdotool getwindowgeometry --shell "$win")"

    # window in question is not under cursor, then ignore
    if [ "$cursorY" -lt "$Y" ] || [ "$cursorY" -gt $((Y + HEIGHT)) ] ||
        [ "$cursorX" -lt "$X" ] || [ "$cursorX" -gt $((X + WIDTH)) ]; then
        continue
    fi

    # if window in question is minimized, then ignore
    if xprop -id "$WINDOW" _NET_WM_STATE | grep -q _NET_WM_STATE_HIDDEN; then
        continue
    fi

    xdotool windowactivate "$win"
    return

done

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions