Class PointerConstraint
An app's request to lock the pointer in place or keep it inside an area, as games and remote desktop viewers ask for. It arrives with the pointer_constraint request.
- Inactive until a handler calls
activate. - An active constraint only acts while the pointer is over the surface that asked.
Granting constraints only to the window with keyboard focus:
lua
wm.input:on("pointer_constraint", function(constraint)
local asking = constraint:window()
if asking and #asking.focused_seats > 0 then constraint:activate() end
end)Methods
constraint:alive() -> booleanalive
False once the app has destroyed the constraint.
constraint:kind() -> "locked" | "confined" | nilkind
"locked" keeps the pointer where it is. "confined" keeps it inside an area.
- nil once the app has destroyed the constraint.
constraint:is_active() -> booleanis_active
Whether the constraint is in effect.
- false once the app has destroyed the constraint.
constraint:activate() -> nilactivate
Puts the constraint in effect and tells the app. While the pointer is over the surface:
- A lock stops the pointer moving. The app still gets relative motion, which a game uses to turn the camera.
- A confinement keeps the pointer inside the area the app gave, or the whole surface when it gave none. An area of several rectangles counts as the smallest rectangle around them all.
Does nothing when already active or destroyed.
constraint:deactivate() -> nildeactivate
Takes the constraint out of effect and tells the app, for example when its window loses focus.
- Does nothing when not active or destroyed.
lua
wm.input:on("pointer_constraint", function(constraint)
local asking = constraint:window()
if not asking then return end
constraint:activate()
asking:on("focus", function(_, focused)
if focused then constraint:activate() else constraint:deactivate() end
end)
end)constraint:pointer() -> Pointerpointer
The pointer the app wants to constrain.
constraint:window() -> Window?window
The window that asked, also when one of its popups asked.
- nil for a layer, and once the window has closed.