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

Query mouse position / Query mouse display #644

Closed
TheNoim opened this issue Aug 23, 2020 · 2 comments
Closed

Query mouse position / Query mouse display #644

TheNoim opened this issue Aug 23, 2020 · 2 comments
Labels
suggestion Request for new feature or some form of enhancement

Comments

@TheNoim
Copy link

TheNoim commented Aug 23, 2020

Yesterday I discovered yabai and I already love it. I now can replace TotalSpaces 2. I just needed a simple way to switch displays without any animation and until yesterday ts2 was my only option.

For my purpose, I implemented this small script: https://raw.githubusercontent.com/TheNoim/MacOS/master/yabai-functions.sh

With this script, I can cycle through my spaces on the current desktop. It works great in combination with keyboard shortcuts. It has just one flaw. With yabai I am only able to query the currently focused display. However, sometimes I trigger my space switch shortcut when I am just hovering over my second monitor. A workaround is to use yabai -m config focus_follows_mouse autoraise. But I don't want to focus, I just want to change spaces. I would need an additional field in the json. Something like this:

[{
	"id":10,
	"label":"",
	"index":8,
	"display":2,
	"windows":[],
	"type":"float",
	"visible":0,
	"focused":0, // Mouse is on display 2, but display is not focused
	"native-fullscreen":0,
	"first-window":0,
	"last-window":0,
        "mouse": 1 // Mouse is on display 2
}]

Then I could update the getCurrentDisplay function to:

function getCurrentDisplay() {
	echo $(yabai -m query --spaces | jq 'map(select(.mouse == 1)) | .[0] | .display')
}

Temporary dirty solution:

Use a small swift cli utility https://github.com/TheNoim/MacOS/blob/master/mousePosition/mousePosition/main.swift in combination with echo $(yabai -m query --displays | jq --argjson display "$displayID" 'map(select(.id == $display)) | .[0].index')

@koekeishiya
Copy link
Owner

koekeishiya commented Aug 26, 2020

On the latest master you can use the mouse selector to query information about displays and/or spaces that currently contain the cursor.

# output list of all spaces that belong to the display that contain the cursor
yabai -m query --spaces --display mouse

# output single space that contain the mouse cursor (focused space of the display that holds the mouse cursor)
yabai -m query --spaces --space mouse

# output the single display that contain the mouse cursor
yabai -m query --displays --display mouse

The above are some examples of what you can do with these.
You can experiment with other permutations if you need more/other info.

@koekeishiya koekeishiya added addressed on master; not released Fixed upstream, but not yet released suggestion Request for new feature or some form of enhancement labels Aug 26, 2020
@TheNoim
Copy link
Author

TheNoim commented Aug 27, 2020

This is exactly what I was searching for. Already excited for the release. Until then, I will use my workaround cli.
#Edit: Until it gets a release, I will keep the issue open.

@koekeishiya koekeishiya removed the addressed on master; not released Fixed upstream, but not yet released label Sep 3, 2020
Amar1729 added a commit to Amar1729/yabai-zsh-completions that referenced this issue Dec 31, 2021
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
suggestion Request for new feature or some form of enhancement
Projects
None yet
Development

No branches or pull requests

2 participants