Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Focus follows mouse in autofocus mode interacting with Sublime Text window #545

Closed
mbigras opened this issue May 29, 2020 · 11 comments
Closed
Labels
help wanted Community help appreciated question Request for information or help, not an issue

Comments

@mbigras
Copy link

mbigras commented May 29, 2020

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:

yabai/src/window_manager.c

Lines 804 to 814 in 80273cb

static void window_manager_activate_window(ProcessSerialNumber *window_psn, uint32_t window_id)
{
uint8_t bytes[0xf8] = {
[0x04] = 0xf8,
[0x08] = 0x0d,
[0x8a] = 0x01
};
memcpy(bytes + 0x3c, &window_id, sizeof(uint32_t));
SLPSPostEventRecordTo(window_psn, bytes);
}

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

mbigras commented May 29, 2020

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:

@mbigras mbigras changed the title Focus Follows Mouse without raise for Sublime Text Focus follows mouse in autofocus mode interacting with Sublime Text window May 29, 2020
@koekeishiya
Copy link
Owner

koekeishiya commented May 29, 2020

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.

@koekeishiya koekeishiya added help wanted Community help appreciated question Request for information or help, not an issue labels May 30, 2020
@BenjaminSchaaf
Copy link

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.

@mbigras
Copy link
Author

mbigras commented Jun 5, 2020

@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?

@BenjaminSchaaf
Copy link

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.

@mbigras
Copy link
Author

mbigras commented Jun 5, 2020

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

@koekeishiya
Copy link
Owner

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

@BenjaminSchaaf
Copy link

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.

@koekeishiya
Copy link
Owner

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.

@koekeishiya
Copy link
Owner

Did a small change on master. Does that help?

@mbigras
Copy link
Author

mbigras commented Jul 8, 2020

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

@koekeishiya koekeishiya removed the won't fix This will not be worked on label Aug 11, 2020
unrevre pushed a commit to unrevre/yabai that referenced this issue Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Community help appreciated question Request for information or help, not an issue
Projects
None yet
Development

No branches or pull requests

3 participants