koekeishiya / yabai

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

Unable to make windows from Litter Arc float #2271

Open patrick91 opened 4 months ago

patrick91 commented 4 months ago

This might more be an issue with Arc, but I wonder if there's any working workaround.

The issue comes from the Little Arc feature, it basically allows to open links in a "temporary" floating window. Unfortunately when using yabai the window is not floating, and I haven't found a way to tell yabai to not manage those windows, here's what I get from querying the windows:

  1. Little arc:
{
    "id":11848,
    "pid":1220,
    "app":"Arc",
    "title":"[yabai] Now my Mac looks hecking cool but I am still very unproductive : unixporn",
    "scratchpad":"",
    "frame":{
        "x":756.0000,
        "y":510.0000,
        "w":756.0000,
        "h":472.0000
    },
    "role":"AXWindow",
    "subrole":"AXStandardWindow",
    "root-window":true,
    "display":1,
    "space":2,
    "level":0,
    "sub-level":-20,
    "layer":"normal",
    "sub-layer":"below",
    "opacity":0.9800,
    "split-type":"horizontal",
    "split-child":"second_child",
    "stack-index":0,
    "can-move":true,
    "can-resize":true,
    "has-focus":false,
    "has-shadow":true,
    "has-parent-zoom":false,
    "has-fullscreen-zoom":false,
    "has-ax-reference":true,
    "is-native-fullscreen":false,
    "is-visible":true,
    "is-minimized":false,
    "is-hidden":false,
    "is-floating":false,
    "is-sticky":false,
    "is-grabbed":false
}

Standard window

{
    "id":11819,
    "pid":1220,
    "app":"Arc",
    "title":"yabai is cool",
    "scratchpad":"",
    "frame":{
        "x":756.0000,
        "y":38.0000,
        "w":756.0000,
        "h":472.0000
    },
    "role":"AXWindow",
    "subrole":"AXStandardWindow",
    "root-window":true,
    "display":1,
    "space":2,
    "level":0,
    "sub-level":-20,
    "layer":"normal",
    "sub-layer":"below",
    "opacity":0.9800,
    "split-type":"horizontal",
    "split-child":"first_child",
    "stack-index":0,
    "can-move":true,
    "can-resize":true,
    "has-focus":false,
    "has-shadow":true,
    "has-parent-zoom":false,
    "has-fullscreen-zoom":false,
    "has-ax-reference":true,
    "is-native-fullscreen":false,
    "is-visible":true,
    "is-minimized":false,
    "is-hidden":false,
    "is-floating":false,
    "is-sticky":false,
    "is-grabbed":false
}

as you can see the windows appear to be the same, so not sure if we can target either 🤔

I've tried workarounds described in #1622 but none of them work

LucasLundJensen commented 4 months ago

I'm also in the same situation.

ognistik commented 4 months ago

I commented on #1622 before, but my setup has changed a bit because of updates with how Yabai was handling layers and sub-layers. I have it all working perfectly on my side, but this is definitely not for the faint of heart. You do not have to follow everything I do, but if you can understand the behavior of Little Arc (and the reason behind my rules or signals) then you can probably come up with something that works for you.

https://github.com/koekeishiya/yabai/assets/124819548/0ff8b2e2-ab03-440a-b980-dd2e2c02b946

Options

Three ways to open Little Arc:

  1. Links outside of Arc
  2. Triggering Little Arc alone with default Shortcut (in my case is CMD + CTRL + OPT + N)
  3. Within Arc, while pressing down modifiers (set in Arc Settings)

With Yabai we can Float or Tile new windows… so those 3 actions give us 6 possible results.

For my setup I use:

Some links all the way to the bottom.

Yabairc Setup

I like all my apps to open in a normal sub-layer, so I have this rule… which is important for my entire Little Arc Setup.

yabai -m rule --add app=".*" sub-layer=normal

Specific to Arc I have:

yabai -m rule --add app="^Arc$" title="^Space [0-9]+$|ybf$" manage=off

As I mention, Little Arc windows triggered by the default shortcut will start with Space… in their title or if a link is clicked externally the window will have the URL (which can have an identifier I added with OpenIn). But then… once they open a website, the title of the window will change to the title of the website. By knowing this you could create a signal activated by name change, but my process is simpler. By default all my Arc windows are managed, so I only need to identify the ones I want to float. With this Yabairc rule alone you should be able to open Little Arc windows using Option 2 mentioned above and float them.

For option 1:

In my case, all links outside of Arc are handled by OpenIn. In OpenIn I have added Arc twice, as if it were two separate browsers, but one is for a Floating Little Arc, and the other one is for a Tiled Little Arc. In the Floating one I do a regex replacement of expression https://(.*) which is replaced by https://$1#ybf and for the tiled Little Arc I don't change anything.

In OpenIn you can setup rules, so you can click links by holding SHIFT and they will open as Float or CMD and they will open as tiled, for example. The window title will change half a second later but by then, if you insert the #ybf it has already been identified by the rule we set up in Yabairc.

For option 2:

If you don't care about ever having any Little Arc tiled, then you don't need to follow this step. I use Karabiner to control Yabai, so you will most likely need to modify this for your own setup.

I have this assigned to a Keyboard shortcut for when I want my Little Arc floating. In this case not only do I want these floating but also centered.

[:right_shift [[:yabai "signal --add label=littlearccmd event=window_title_changed action=\"~/Dropbox/2-Areas/SystemAndApps/Yabai/LittleArcCMD.sh floatcenter\""] :!TOCn]]

If you want ALL your floating Little Arcs centered, you can simply modify the Yabairc rule, or add a signal to your Yabairc and run the script that way.

When I want to create a tiled Little Arc I have:

[:!Cright_shift [[:yabai -m signal --add label=littlearccmd event=window_title_changed action=\"~/Dropbox/2-Areas/SystemAndApps/Yabai/LittleArcCMD.sh tile\""] :!TOCn]]

In my setup a script will be run when the window name change I mentioned above happens. If it's a floating window, the script will just center it. If it's supposed to be tiled, and since Little Arc windows (starting with Space... will be floating by default), the script will toggle the float making it tiled.

For option 3:

I disabled the keyboard shortcut in Arc and I did two Keyboard maestro macros that trigger the right mouse click menu, copies the url, and then opens the URL from my clipboard in Arc with either ybf or as normal depending on whether I want the window floating or tiled. No longer do I need OpenIn for this step. I do suggest you do disable the default keyboard shortcut in Arc and do it like this because windows opened with the default keyboard shortcut do not go through the same window title rename by Arc… making it virtually impossible to identify.

Conclusion

This is much more complicated than it should be, but until Arc decides to do things differently I don’t think we have many more options.

Links

My Yabairc File LittleArcCMD.sh Keyboard Maestro Macros for links within Arc

zcag commented 3 months ago

Here's how I ended up solving it:

# .yabairc
yabai -m rule --add app="^Arc$" manage=off
yabai -m signal --add event=window_created app="^Arc$" action="~/.scripts/yabai_apply_arc_rules.sh"
# yabai_apply_arc_rules.sh
[[ $(yabai -m query --windows | grep '"app":"Arc"' | wc -l) -eq 1 ]] &&
  yabai -m window $YABAI_WINDOW_ID --space web --toggle float

When an Arc window is created, it assumes that it's the main window if there's only one, and applies the actual arc rule, otherwise it's manage=off by default so it floats.

devnoname120 commented 3 months ago

@cagdassalur This breaks additional Arc windows that you open with FileNew Window though no?

devnoname120 commented 3 months ago

@patrick91 IMO it's more a problem of Arc rather than yabai. If there is nothing to distinguish the windows, yabai can't do much.

zcag commented 3 months ago

@cagdassalur This breaks additional Arc windows that you open with File → New Window though no?

Yeah, for my usecase arc splits are better for side-to-side (2 windows have 2 sidebars), combined with little Arc i don't really see the usecase for seperate main Arc windows

devnoname120 commented 3 months ago

@cagdassalur Makes sense. For me separate Arc windows are useful so that in a given macOS space I have one Arc space open and other relevant things on the side (e.g. a terminal, an IDE, etc.). And then I can have several macOS spaces each using a different Arc space (like for example an extra macOS space for taxes that contains an Arc space + Excel). This is very convenient.

Useful also when I'm sharing my secondary screen and I only want to show a specific Arc space while on my main screen I can still do stuff in my main Arc space without sharing it.

Note that your solution also breaks if Arc is not open at the time you open Little Arc, and even further if you open Arc before you close Little Arc (that last one will stay floating).

zcag commented 3 months ago

Note that your solution also breaks if Arc is not open at the time you open Little Arc, and even further if you open Arc before you close Little Arc (that last one will stay floating).

I assumed was my use case was the norm, never even thought of opening little arc when arc is not running :), for me i always have a browser open in the background.

And then I can have several macOS spaces each using a different Arc space (like for example an extra macOS space for taxes that contains an Arc space + Excel). This is very convenient.

I guess you can modify it to not check for first window, but first window on the current space. But other issues will still be there. Also this will break arc being able to open little arc when i'm on some other space and my main arc is on a different one

zcag commented 3 months ago

You can also use the window frame coordinates to figure out if the window is little arc or not, bit hacky but it'll work if you use your main Arc windows on some fixed or predictible sizes

ognistik commented 3 months ago

Ultimately, this will depend on the particular way everyone uses Little Arc. I mostly keep Arc open in the background without any windows. When I need something quick, I'll trigger the Little Arc shortcut for a floating temporary window. Sometimes I do want this one tiled so I like to have a separate shortcut that will create a tiled Little Arc. If I click a link (outside of Arc) I usually want it on a floating Little Arc but it's also nice to have the option of tiling them right away. And sometimes, for more dedicated browsing, I'll go to the main window, which is always tiled. This morning I was trying to think of another approach. I still need to do some testing but seems to work. It may still be more convoluted than necessary:

  1. Manage off all Arc windows
  2. Add a signal for new Arc windows created, which will toggle the float of new Arc windows—tiling them—when there's windows that DO NOT start with Space. Let’s say, title!="^Space [0-9]+$" This will take care of tiling my Main Arc window, or if I ever open a “New Window” it will also be tiled. This will allow me to selectively Tile or Float Little Arc windows.
  3. Links clicked outside our Little Arc will be tiled by default because they do not create a window with “Space…” in their title. If I want them to float by default, then I need to intercept them by:
    1. Removing the signal from Yabairc before opening the link in Arc.
    2. Opening the link with Arc.
    3. Restoring the signal. This can easily be done with Openin, sending my links through a Keyboard Maestro macro.
  4. When triggering my Little Arc keyboard shortcut all Little Arc windows will float by default because the newly created window title (the Little Arc “bar”) starts with “Space…”
  5. Knowing that windows created by the Little Arc keyboard shortcut always start with “Space” and will go through a name-change when I enter a URL or search term, then, if I want to open them as tiled I can also do that. I can simply create another Keyboard Maestro macro that will be run by a different hotkey. This will:
    1. Trigger the keyboard shortcut for a new little Arc (floating by default).
    2. At the same time, add a signal for an action that will be triggered by a window title change. The action is: toggle the float (tile my Little Arc window) AND remove this signal so that Little Arc windows going forward (those created with the keyboard shortcut) continue to float by default.