koekeishiya / yabai

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

Resize a floating window around its center #2182

Open dominiklohmann opened 8 months ago

dominiklohmann commented 8 months ago

I've been trying to add an effect to toggling a window into floating mode to make it a bit more obvious, and for that I wanted to resize the window around its center.

I tried this:

yabai -m query --windows id,frame --window |
  jq -er '"yabai -m window \(.id) --toggle float --resize top_left:\(.frame.w/40):\(.frame.h/40) --resize bottom_right:\(.frame.w/-40):\(.frame.h/-40)"' |
  sh -

# This executes something like this:
#   yabai -m window 157365 --toggle float --resize top_left:19.775:25.9 --resize bottom_right:-19.775:-25.9

But then I quickly noticed that it doesn't achieve what I wanted it to, as yabai ignores the first --resize I passed in. Not sure whether that should be considered a bug.

From a user experience perspective, I don't actually want to express this as two resizes anchored at opposite corners. All I wanted to do is shrink my window by 20% around its center. It'd be nice to have a dedicated window command for this, for example:

# x and y are absolute values; positive numbers grow, negative numbers shrink the window
yabai -m window --resize center:x:y

Because then my script could just be this:

yabai -m query --windows id,frame --window |
  jq -er '"yabai -m window \(.id) --toggle float --resize center:\(.frame.w/-20):\(.frame.h/-20)"' |
  sh -
koekeishiya commented 8 months ago

I would consider that a bug. In fact it is caused by using a cached value of the window frame instead of requesting it from the AX API.

I'm not opposed to looking into adding a center "handle" to the resize command, but that will likely come at some other point in time. For now I'll just resolve the bug with your current method.

dominiklohmann commented 8 months ago

Awesome, thanks for the quick fix. I can confirm this works as expected now.

koekeishiya commented 8 months ago

Fixed in v7.0.4. I'll keep this open as a suggestion for a new resize handle which may make this operation built-in in the future.

Pe8er commented 8 months ago

@dominiklohmann does this work for you on 7.0.4?

yabai -m query --windows id,frame --window |
  jq -er '"yabai -m window \(.id) --toggle float --resize center:\(.frame.w/-20):\(.frame.h/-20)"' |
  sh -

Or did you end up with a different syntax? The above doesn't work for me.

dominiklohmann commented 8 months ago

@Pe8er if you read the thread again you'll see that the center anchor was not implemented. Instead, the behavior for providing two resizes with different anchors at once was fixed, allowing you to achieve the same effect that a center anchor would have.

Pe8er commented 8 months ago

@dominiklohmann I see now, sorry for the oversight and thank you for clarification!