Hyprland icon indicating copy to clipboard operation
Hyprland copied to clipboard

Using `movefocus` to navigate inside group

Open sant0s12 opened this issue 2 years ago • 3 comments

Hi,

Coming from i3, I am used to using the normal focus keybindings for moving inside the "tabs" or (groups in hyperland). I was wondering if the same thing can be done in hyperland (I know inside a group you can use changegroupactive but I have not found a way to use the same key bindings for changing focus both inside and outside groups).

In case this is not possible as of now, could you consider adding this feature?

Thanks!

sant0s12 avatar Nov 23 '22 13:11 sant0s12

how would you move outside the group then?

vaxerski avatar Nov 23 '22 13:11 vaxerski

When you are at the right/leftmost of the group and move right/left. Basically the way it works in i3 (I know hyprland is not supposed to be an i3 replacement but I do think this way of doing it is nice).

sant0s12 avatar Nov 23 '22 14:11 sant0s12

The same for me, it would be really cool to have the possibility to configure the same behavior for tab group. Using different hotkey is frustrating, can't find any comfortable key binding for that...

selfuryon avatar Dec 12 '22 16:12 selfuryon

I worked around this with a simple script:

#!/bin/bash

groupSize=$(hyprctl activewindow -j | jq -r '.grouped | length')

if [[ "$groupSize" > 0 ]]; then
    IN_GROUP=1
else
    IN_GROUP=0
fi

if [[ "$1" == "left" ]]; then
    if [[ "$IN_GROUP == 1 ]]; then
        hyprctl dispatch changegroupactive b
    else
        hyprctl dispatch movefocus l
    fi
else
    if [[ "$IN_GROUP" == 1 ]]; then
        hyprctl dispatch changegroupactive f
    else
        hyprctl dispatch movefocus r
    fi
fi

then I bind it to my focus keys:

bind=SUPER,h,exec,~/.config/hypr/focus.sh left
bind=SUPER,l,exec,~/.config/hypr/focus.sh right
bind=SUPER,k,movefocus,u
bind=SUPER,j,movefocus,d

Yeah, you cannot leave the group, but I still have a mouse that can focus other things. Seems like an OK compromise. It'd be cool to be able to click on the group indicator to move focus within the group.

raidzero avatar Apr 14 '23 13:04 raidzero

how would you move outside the group then?

@vaxerski: the way sway (and I believe i3) does it is using window trees. A group contains multiple windows, so to move out of it, (assuming you're currently in a window inside a group) you go a "level" up and now you're at the same level as the group (not its windows), allowing you to treat the group as a window and move anywhere from there.

Diegovsky avatar May 11 '23 13:05 Diegovsky

pretty easily scriptable/pluginable

vaxerski avatar May 12 '23 00:05 vaxerski

Not exactly scriptable. AFAIK, you can't have splits inside hypr groups. They're their own thing. You should try Sway for yourself to see what I'm talking about. The tree navigation feature can only be done inside hypr (or a plugin). This would unify all of the movements, making the movegroup command family pointless.

I'm short on time to look into a script and/or plugin and I'm sure you have more important issues than this to work on, so if anyone develops anything like what I'm describing, please ping me! I'm interested :)

Btw loving hyprland

Diegovsky avatar May 18 '23 11:05 Diegovsky

With #3683 this behavior is scriptable. See my comment for an example

topisani avatar Oct 28 '23 22:10 topisani

Looks promising, thank you

Diegovsky avatar Nov 02 '23 14:11 Diegovsky

For anyone that stumbles upon this issue, I have been using https://github.com/outfoxxed/hy3 and it solves this issue completely.

sant0s12 avatar Jan 02 '24 11:01 sant0s12

Thank you very much for this!

Diegovsky avatar Jan 09 '24 06:01 Diegovsky

For posterity, I updated the shared bash script above to properly support leaving a group as well. Here's my updated bash script:

#!/bin/bash

data=$(hyprctl activewindow -j)
groupSize=$(echo "$data" | jq -r '.grouped | length')
address=$(echo "$data" | jq -r '.address')
groupIndex=$(echo $data | jq --arg address "$address" -r '.grouped | index($address)')

IN_GROUP=0
if [[ "$groupSize" > 0 ]]; then
    IN_GROUP=1
fi

if [[ "$1" == "left" || "$1" == "l" ]]; then
    if [[ "$IN_GROUP" == 1 && "$groupIndex" > 0  ]]; then
        hyprctl dispatch changegroupactive b
    else
        hyprctl dispatch movefocus l
    fi
else
    if [[ "$IN_GROUP" == 1 && "$((groupIndex + 1))" < "$groupSize" ]]; then
        hyprctl dispatch changegroupactive f
    else
        hyprctl dispatch movefocus r
    fi
fi

hhhapz avatar Jul 27 '24 11:07 hhhapz

For posterity, I updated the shared bash script above to properly support leaving a group as well. Here's my updated bash script:

#!/bin/bash

data=$(hyprctl activewindow -j)
groupSize=$(echo "$data" | jq -r '.grouped | length')
address=$(echo "$data" | jq -r '.address')
groupIndex=$(echo $data | jq --arg address "$address" -r '.grouped | index($address)')

IN_GROUP=0
if [[ "$groupSize" > 0 ]]; then
    IN_GROUP=1
fi

if [[ "$1" == "left" || "$1" == "l" ]]; then
    if [[ "$IN_GROUP" == 1 && "$groupIndex" > 0  ]]; then
        hyprctl dispatch changegroupactive b
    else
        hyprctl dispatch movefocus l
    fi
else
    if [[ "$IN_GROUP" == 1 && "$((groupIndex + 1))" < "$groupSize" ]]; then
        hyprctl dispatch changegroupactive f
    else
        hyprctl dispatch movefocus r
    fi
fi

Similarly you can replace changegroupactive with movegroupwindow and movefocus with movewindoworgroup for i3-like window moving/reordering in and out of groups. Though moving a window from the left into a group from the right doesn't insert it into the beginning of the group.

dandy-is-lion avatar Aug 09 '24 08:08 dandy-is-lion