Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Resize a floating window around its center #2182

Open
dominiklohmann opened this issue Mar 22, 2024 · 6 comments
Open

Resize a floating window around its center #2182

dominiklohmann opened this issue Mar 22, 2024 · 6 comments
Labels
suggestion Request for new feature or some form of enhancement

Comments

@dominiklohmann
Copy link
Collaborator

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
Copy link
Owner

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.

@koekeishiya koekeishiya added the bug Something isn't working label Mar 22, 2024
koekeishiya added a commit that referenced this issue Mar 22, 2024
@koekeishiya koekeishiya added the addressed on master; not released Fixed upstream, but not yet released label Mar 22, 2024
@dominiklohmann
Copy link
Collaborator Author

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

@koekeishiya
Copy link
Owner

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.

@koekeishiya koekeishiya added suggestion Request for new feature or some form of enhancement and removed bug Something isn't working addressed on master; not released Fixed upstream, but not yet released labels Mar 30, 2024
@Pe8er
Copy link

Pe8er commented Mar 30, 2024

@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
Copy link
Collaborator Author

@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
Copy link

Pe8er commented Apr 1, 2024

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
suggestion Request for new feature or some form of enhancement
Projects
None yet
Development

No branches or pull requests

3 participants