Skip to content

Conversation

OXDBXKXO
Copy link

Add an IPC command to Sway that allows swaymsg to request information about the cursor:

Cursor over container:

{
	"x": 1024,
	"y": 768,
	"surface_x": 24,
	"surface_y": 48,
	"node_type": "con",
	"window_title": "Terminal",
	"app_id": "termite",
	"workspace_name": "1",
	"pid": 25370
}

Cursor over workspace:

{
	"x": 1024,
	"y": 768,
	"node_type": "workspace",
	"workspace_name": "1"
}

@emersion
Copy link
Member

Could you describe your use-case for this?

@OXDBXKXO
Copy link
Author

Hi,
Some tools need to be able to retrieve the cursor position.

For example, Kando, for which I plan to add Sway support (got it working on my forked Sway).

@emersion
Copy link
Member

I don't think Kando needs access to the global cursor position via the Sway IPC. Kando can open a full-screen layer-shell surface, receive the wl_pointer.enter event to get the position relative to the surface, and show the menu there.

@OXDBXKXO
Copy link
Author

Kando is just an example of a tool that would benefit from swaymsg being able to return information about the cursor position and the element under it.
It enables broader scripting/automation use-cases that relies on this information.

@OXDBXKXO
Copy link
Author

OXDBXKXO commented Jul 2, 2025

🥺 👉 👈

@jirassimok
Copy link

I think emersion's point is correct; while adding this to Sway's IPC would be convenient, it isn't the proper way to get this information. It would be better to use the wlr-layer-protocol (or some other Wayland protocol), which would also be more portable to other WMs.

@OXDBXKXO
Copy link
Author

OXDBXKXO commented Jul 3, 2025

A pull-request was accepted today on the Kando project, which adds support for Niri. The contributor used the full-screen layer-shell trick.

I tried to use his work for the Sway backend, but the result is unsatisfactory: the trick does indeed allow Kando to receive the cursor position, but as no pointer-enter event is sent at surface creation, the capture of the cursor position hangs until the mouse moves.
The contributor claims that this is also the case on Hyprland, but as it provides a method for retrieving the cursor position through hyprctl, this is not problematic.

But then again, this new IPC command would have other uses than simply Kando compatibility: it would enable conditional actions based on cursor position.

@emersion
Copy link
Member

emersion commented Jul 3, 2025

no pointer-enter event is sent at surface creation

That's a Sway bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants