koekeishiya / yabai

A tiling window manager for macOS based on binary space partitioning
MIT License
23.93k stars 651 forks source link

Suggest options to move the window position more intuitively #1452

Open eomdohyeon opened 2 years ago

eomdohyeon commented 2 years ago

I've been using i3wm on Linux for a long time and have been using yabai a lot since I switched to Mac. (Thank you so much for making the app.)

While using yabai, I felt that the way the windows move was different from the i3.

To move a window, i3 uses the 'move' command and yabai frequently uses the 'swap' and 'warp' commands.

Currently, the window warp and swap commands require another window to exist in the moving position in order to move in that direction.

Here's an example

Current behaviour: No window layout changes

+--------------+                  +--------------+  
|      a       |                  |      a       |
+--------------+   b warp east    +--------------+
|      b       |       -->        |      b       |
+--------------+                  +--------------+ 
|      c       |                  |      c       | 
+--------------+                  +--------------+

The desired behavior is:

+--------------+                  +---------+----+ 
|      a       |                  |    a    |    |
+--------------+   b move east    |         |    |
|      b       |       -->        +---------+  b |
+--------------+                  |    c    |    |
|      c       |                  |         |    |
+--------------+                  +----+----+----+ 

The same goes for below.

Current behaviour : No window layout changes

+--------------+                  +--------------+
|      a       |                  |      a       |
|              |   c warp east    |              |
+ ------+------+       -->        + ------+------+ 
|   b   |   c  |                  |   b   |   c  | 
|       |      |                  |       |      | 
+--------------+                  +--------------+ 

The desired behavior is:

+--------------+                  +---------+----+ 
|      a       |                  |    a    |    |
|              |   c move east    |         |    |
+ ------+------+       -->        |---------|  c |
|   b   |   c  |                  |    b    |    |
|       |      |                  |         |    |
+--------------+                  +---------+----+ 

Even with the current window swap and warp options, you can change from a left layout to a right layout form, but that's more work than expected.

This requires the right combination of commands like swap, warp, rotate, etc, and it's not that simple.

For users familiar with the layout of i3wm, intuitive Add the 'move' option for moving the window, or suggest the "yabai -m config layout i3" option.

neevparikh commented 1 year ago

I got close

#!/bin/bash

get_layout_type() {
  out=$(yabai -m query --spaces --window mouse)
  length=$(echo $out | jq length)
  if [ $length -ne 1 ]; then 
    return -1
  fi
  echo $(echo $out | jq --raw-output ".[0].type")
}

yabai_move() {
  direction=$1
  layout=$(get_layout_type)
  echo $direction $layout
  if [ "$layout" = "stack" ]; then
    case $direction in
    north)
      yabai -m window --warp stack.prev;; 
    south)
      yabai -m window --warp stack.next;; 
    *)
      :;;
    esac
  elif [ "$layout" = "bsp" ]; then
    case $direction in
    north)
      yabai -m window --warp $direction || yabai -m space --rotate 270 && yabai -m space --balance x-axis;;
    south)
      yabai -m window --warp $direction || yabai -m space --rotate 90 && yabai -m space --balance x-axis;;
    east | west)
      yabai -m window --warp $direction || yabai -m window --toggle split && yabai -m space --balance y-axis;;
    *)
      :;;
    esac
  else
    return -1
  fi
} 
neevparikh commented 1 year ago

What still doesn't work is:

+--------------+                  +---------+----+ 
|       a      |                  |    a    |    |
+ ------+------+   c move east    |---------|    |
|   b   |   c  |       -->        |    b    |  c |
+ ------+------+                  |---------|    |
|       d      |                  |    d    |    |
+--------------+                  +---------+----+ 
neevparikh commented 1 year ago

It's harder when you can't really access the internal tree mechanics. @koekeishiya are there any plans/interest in exposing lower-level functions for tree manipulation?

ChrisLahaye commented 8 months ago

Is there a way to work around "Currently, the window warp and swap commands require another window to exist in the moving position in order to move in that direction."?

koekeishiya commented 8 months ago

It's harder when you can't really access the internal tree mechanics. @koekeishiya are there any plans/interest in exposing lower-level functions for tree manipulation?

I am not opposed to this, I just have not been able to come up with an intuitive syntax for accessing the tree from a CLI.

Is there a way to work around "Currently, the window warp and swap commands require another window to exist in the moving position in order to move in that direction."?

No there isn't really a way to do that currently.

neevparikh commented 8 months ago

A subset of what the i3 ipc offers is probably plenty: https://i3ipc-python.readthedocs.io/en/latest/con.html#i3ipc.Con

neevparikh commented 8 months ago

additionally, if we're just given the lower level tree manipulation API, it doesn't need to be super intuitive, and it's a lot easier for the community to build/maintain wrappers around it that end up being more intuitive

neevparikh commented 8 months ago

@koekeishiya takes some of the pressure of your shoulders!