Hyprland icon indicating copy to clipboard operation
Hyprland copied to clipboard

Cycle through visible windows regardless of workspace

Open offsetcyan opened this issue 1 year ago • 5 comments
trafficstars

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.

offsetcyan avatar Jun 26 '24 22:06 offsetcyan

looks interesting to try

Truenya avatar Jun 27 '24 06:06 Truenya

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 :)

dpredovic avatar Jun 27 '24 10:06 dpredovic

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

Truenya avatar Jun 28 '24 06:06 Truenya

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.

offsetcyan avatar Jul 01 '24 21:07 offsetcyan

finally done #9045

Truenya avatar Jan 12 '25 14:01 Truenya

Hello there!

This issue has been closed, as we are moving from issues to discussions. More about this can be found here and in #9854.

Firstly, please make sure this issue is still relevant in latest Hyprland. If so, we ask you to open a discussion (please read the discussion guidelines first, in the pinned post)

Thank you for your understanding!

vaxerski avatar Apr 05 '25 20:04 vaxerski