hyprwm / Hyprland

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

use movefocus or moveactive depending on the window floating state #2321

Open villamide opened 1 year ago

villamide commented 1 year ago

Hi. I've been playing around a lot with Hyprland and I find it amazing so far.

I am really used to i3wm, and I am not being able to achieve the same result with Hyprland.

In my i3wm config I have this bindings for "moving" windows.

bindsym $mod+Shift+h move left bindsym $mod+Shift+j move down bindsym $mod+Shift+k move up bindsym $mod+Shift+l move right

Whenever the focused window is in tile mode it behaves like "movefocus" Hyprland dispatcher, and when the focused window is floating it behaves like "moveactive" Hyprland dispatcher. I mean, basically, when focused window is in tile mode it switches with the next tile window in the direction you want, and when the focused window is in floating mode, you can move it around your current desktop.

Is there any way to achieve this in Hyprland with the same binding? If not, would it be possible to add a new dispatcher in order to achieve this behavior?

Thanks in advance

ghettoDdOS commented 1 year ago

Move focused window with mainMod SHIFT + arrow keys

bind = $mainMod SHIFT, left, movewindow, l bind = $mainMod SHIFT, right, movewindow, r bind = $mainMod SHIFT, up, movewindow, u bind = $mainMod SHIFT, down, movewindow, d

villamide commented 1 year ago

Move focused window with mainMod SHIFT + arrow keys

bind = $mainMod SHIFT, left, movewindow, l bind = $mainMod SHIFT, right, movewindow, r bind = $mainMod SHIFT, up, movewindow, u bind = $mainMod SHIFT, down, movewindow, d

Currently I have the following bindings:

# move floating window
binde = $mainMod, left, moveactive, -10 0
binde = $mainMod, right, moveactive, 10 0
binde = $mainMod, up, moveactive, 0 -10
binde = $mainMod, down, moveactive, 0 10

# move focused window
bind = $mainMod, h, movefocus, l
bind = $mainMod, l, movefocus, r
bind = $mainMod, k, movefocus, u
bind = $mainMod, j, movefocus, d

# move focused window
bind = $mainMod SHIFT, h, movewindow, l
bind = $mainMod SHIFT, l, movewindow, r
bind = $mainMod SHIFT, k, movewindow, u
bind = $mainMod SHIFT, j, movewindow, d

I was really used to using i3wm, and in i3wm the "movefocus" hyprland dispatcher acted also like my "moveactive" bindings. I mean, when the focused windows is tiled, in i3wm it would switch places with the other tiled windows, but when the focused window is floating, it would just move this floating window around.

I was wondering if this could be possible using the same bindings when the window is floating or not.

staticssleever668 commented 1 year ago

Here is a little ugly script I made up in a few minutes:

```sh #!/bin/sh RESIZE_SIZE=${1:?Missing resize size} RESIZE_PARAMS_X=0 RESIZE_PARAMS_Y=0 DIRECTION=${2:?Missing move direction} case $DIRECTION in l) RESIZE_PARAMS_X=-$RESIZE_SIZE ;; r) RESIZE_PARAMS_X=$RESIZE_SIZE ;; u) RESIZE_PARAMS_Y=-$RESIZE_SIZE ;; d) RESIZE_PARAMS_Y=$RESIZE_SIZE ;; *) echo "kbye" return 1 ;; esac ACTIVE_WINDOW=$(hyprctl activewindow -j) IS_FLOATING=$(echo "$ACTIVE_WINDOW" | jq .floating) if [ "$IS_FLOATING" = "true" ]; then hyprctl dispatch moveactive "$RESIZE_PARAMS_X" "$RESIZE_PARAMS_Y" else hyprctl dispatch movewindow "$DIRECTION" fi ```

usage:

$myMoveSize = 300
$myMove = sh .config/hypr/move-window.sh $myMoveSize
bind = $mainMod SHIFT, h, exec, $myMove l
bind = $mainMod SHIFT, l, exec, $myMove r
bind = $mainMod SHIFT, k, exec, $myMove u
bind = $mainMod SHIFT, j, exec, $myMove d

This allows you to either swap tiling windows or to move floating windows by a specified amount. I come from Awesome WM where I've had a function to snap clients to screen borders, but I was too lazy to implement it here. Anyway, this is usable enough.

villamide commented 1 year ago

Thanks a lot @staticssleever668 .

That's pretty much what I was looking for but I didn't know how to interact with hyprctl or how to retrieve the current focused and active window. This helps me a lot for future scripts.

PD: I changed the last hyprctl dispatch movewindow "$DIRECTION" with hyprctl dispatch movefocus "$DIRECTION"