hyprwm / Hyprland

Hyprland is a highly customizable dynamic tiling Wayland compositor that doesn't sacrifice on its looks.
https://hyprland.org
BSD 3-Clause "New" or "Revised" License
18.28k stars 762 forks source link

Cycle through visible windows regardless of workspace #6678

Open offsetcyan opened 3 weeks ago

offsetcyan commented 3 weeks ago

Description

The cyclenext dispatcher gives the user the ability to change focus to another window in the same workspace. A user may however have multiple monitors, with multiple workspaces, each containing visible windows that the user would like to cycle between. Therefore a dispatcher that cycles focus to the next visible window regardless of workspace (cyclenextvisible perhaps) would provide useful functionality, allowing a user to cycle between windows that might otherwise require moving to use the mouse and returning to the keyboard.

Truenya commented 3 weeks ago

looks interesting to try

dpredovic commented 3 weeks ago

I have a script for that:

#!/bin/bash

mapfile -t ARR < <(
    hyprctl clients -j |
          jq -r '
           sort_by(.monitor,.workspace.id) | 
          .[] | 
          select(.hidden==false) | 
          [.address,"\(.class) 󰖲 \(.title)"] | 
          @tsv'
)

size="${#ARR[@]}"
if [ "$size" -le 1 ]; then
    exit 1 # skip everything if we have 0 or 1 windows
fi

case "$1" in
menu)
    index=$(printf "%s\n" "${ARR[@]}" | cut -f2 | fuzzel -d --index)
    if [ -z "$index" ]; then
        exit 1
    fi
    ;;
next)
    activeAddr=$(hyprctl activewindow -j | jq -r .address)
    # grep line number is 1 and not zero based, so we don't need to ++ for the next window index
    index=$(printf "%s\n" "${ARR[@]}" | cut -f1 | grep -n "$activeAddr" | cut -d: -f1)
    if [ "$index" -ge "$size" ]; then
        index=0
    fi
    ;;
*)
    exit 1
    ;;
esac

addr=$(printf "%s" "${ARR[index]}" | cut -f1)
hyprctl dispatch focuswindow address:"$addr"

You can use it with keybindings for simple "next window" motion and in "menu" mode.

You need jq for json parsing and some menu (fuzzel in my case) if you want to use the menu variant.

Otoh, native implementation (at least for the next/prev) would be nice :)

Truenya commented 3 weeks ago

I'm on the road right now and haven't been able to debug multiple monitors for probably a week.

@offsetcyan @dpredovic could you please check if it works as intended? #6695

offsetcyan commented 2 weeks ago

Sorry for the delay. I've tried it and the cyclenextvisible dispatcher cycles between the first two visible windows on a single display. If you have three windows and focus on the third, a single call will switch focus to the second window; then the first; then the second, then the first.