Yabai: Focus follows mouse in autofocus mode interacting with Sublime Text window

Created on 29 May 2020  路  11Comments  路  Source: koekeishiya/yabai

I noticed that when focusing Sublime Text I'm getting this error message in the sublime text console:

Unable to parse command: drag_select {"additive": true, "event": {"button": 1, "x": nan.0, "y": nan.0}}

I turned on debugging logging and found that whenever I click anywhere the drag_select command gets run:

Unable to parse command: drag_select {"additive": true, "event": {"button": 1, "x": nan.0, "y": nan.0}}
>>> sublime.log_commands(True)
command: drag_select {"event": {"button": 1, "x": 302.1015625, "y": 371.296875}}
command: drag_select {"additive": true, "event": {"button": 1, "x": 247.3984375, "y": 310.28515625}}

When I turned off yabai and brought focus to sublime via things like clicking or alt-tabbing to the window there were no error messages.

I'm not sure about the internals of yabai or sublime but did some digging into the window_manager_activate_window function:

https://github.com/koekeishiya/yabai/blob/80273cb69b0e7b6f6e8167084bff3771c9a36405/src/window_manager.c#L804-L814

I have a hunch that the error message might be related to some of the numbers that are in that table. The error seems innocuous but I would like to know what's causing it and fix it if possible.

Do you know what's the root cause?

I've also mentioned this issue on the sublime discussion board:

https://forum.sublimetext.com/t/unable-to-parse-command-drag-select/50438

This is my setup

$ yabai --version
yabai-v2.4.1
$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.4
BuildVersion:   19E287
$ cat ~/.yabairc
#!/usr/bin/env sh
yabai -m config focus_follows_mouse autofocus
help wanted question

All 11 comments

From researching this issue further it's clear there is alot of history to focus follows mouse in autofocus (instead of autoraise), these are some relevant links to check out:

I assume that one of the synthesized events that yabai is generating to emulate the autofocus functionality observed through the WindowServer might actually be some kind of special mouse click event, and not all applications are capable of interpreting this special click event properly, which is why it will only work for some applications.

There is very little information regarding autofocus on macOS out there; I believe yabai is actually the first software to achieve this for any modern version of OSX. The autoraise mode in yabai does not have these same kinds of issues, so maybe autoraise combined with window_topmost on might be more appropriate for you; it is what I personally use anyway.

I assume that one of the synthesized events that yabai is generating to emulate the autofocus functionality observed through the WindowServer might actually be some kind of special mouse click event, and not all applications are capable of interpreting this special click event properly, which is why it will only work for some applications.

This would be my guess as well. Looks like the event is specifically a button1 + super event, with the position being nan, nan. Other than the error message does everything else work? If so I think the best course of action would be to ignore events with a nan position on the Sublime Text side.

@BenjaminSchaaf thank you for the response!

Other than the error message does everything else work?

Yes everything works as expected; however, the console log is filed with error messages and I'd like to fix the problem.

I think the best course of action would be to ignore events with a nan position on the Sublime Text side.

Is this the kind that is implemented with a sublime plugin? Is there a configuration change I can make or is there a patch I can submit to the drag_select sublime command?

The drag_select command is not implemented in a plugin. It will need to be fixed in core. Sublime Text is not open source, so there's no way for you to fix it. I'll be adding an issue to the ST issue tracker for this.

Right on @BenjaminSchaaf thank you creating an issue! There is a slight spelling mistake in the title: s/yabi/yabai/ to aid in searching!

Should I keep this issue open or do you think it can be closed, as it is tracked at sublime?

Not sure. I'd consider sending an input event with nan position a bug, but maybe that's the only way to safely do focus-follows-mouse on macOS.

As far as I know there is actually no information out there on how to do autofocus on macOS except for what I did in yabai to achieve this, and so I don't think I will consider this a bug in yabai. At the very least I won't be looking more into it, because it is actually a pain and huge time sink. I will be closing this issue as I won't make changes here.

If applications are having problems due to the usage of autofocus, switch to autoraise and enable topmost floating windows instead.

Did a small change on master. Does that help?

I upgraded yabai to version yabai-v3.2.1 and the error has disappeared from my sublime text console log! This issue is resolved, thank you very much and sorry this took me so long to get back to you!

$ brew upgrade yabai
$ brew services restart yabai
$ sudo yabai --uninstall-sa
$ sudo yabai --install-sa
$ killall Dock
$ yabai --version
yabai-v3.2.1
# adjust permissions
$ brew services restart yabai
# launch sublime-text console using cmd - `
# focus window, no errors!

This is my config file

$ cat ~/.yabairc
#!/usr/bin/env sh
yabai -m config focus_follows_mouse autofocus
Was this page helpful?
0 / 5 - 0 ratings