adding pointer containment and cursor styles

This commit is contained in:
Peterino2 2026-09-27 14:14:00 -07:00
parent 2278d9829a
commit c8180456f0
21 changed files with 1560 additions and 64 deletions

View File

@ -341,6 +341,42 @@ uhdk_status status = uhdk_file_read_all_async(file, 128 * 1024 * 1024, ReadModel
Components sharing a session must coordinate tags; pass a dedicated tag to each Components sharing a session must coordinate tags; pass a dedicated tag to each
component that starts asynchronous work. component that starts asynchronous work.
### Function-key policy
Use `uhdk_window_set_function_key_policy(window, UHDK_FUNCTION_KEYS_APPLICATION)`
to suppress Windows native defaults for unmodified F1–F24, including F10 menu
activation. Key events still reach the application. `UHDK_FUNCTION_KEYS_NATIVE`
restores the default behavior. Set the policy before the relevant press; it is
applied at the next frame boundary, and a held key retains the handling selected
at its initial press through repeats and release.
Shift/Control/Alt/Super combinations, including Alt+F4, keep native handling.
Registered UHDK menu shortcuts retain priority over raw key events. This policy
is accepted on macOS and Wayland without an effect; it does not override global
shortcuts, IME interception, or keyboard media-key settings.
### Cursor confinement
Windows and Wayland compositors with pointer-constraints-v1 support keeping the
cursor inside the window's content area. macOS currently reports this capability
as unavailable. Request confinement while the window is visible and focused and
the pointer is inside:
```c
if (uhdk_has_capability(session, UHDK_CAP_POINTER_CONFINEMENT)) {
uhdk_status status = uhdk_window_set_pointer_mode(window, UHDK_POINTER_CONFINED);
/* Handle submission failure. POINTER_MODE_CHANGED confirms activation. */
(void)status;
}
```
Set `UHDK_POINTER_NORMAL` to release active confinement or cancel a pending
request. Confinement follows the content area as the window moves/resizes and
preserves cursor shape and absolute pointer motion. Wayland activation depends
on compositor policy and may never occur. Focus loss, hiding/minimizing, or native
cancellation restores normal mode without automatic reactivation. Destruction
and session close also release it. Capture and confinement are mutually exclusive.
### Errors and input lifecycles ### Errors and input lifecycles
`uhdk_status_message(status)` returns a static UTF-8 text span, usable without a `uhdk_status_message(status)` returns a static UTF-8 text span, usable without a
@ -349,15 +385,16 @@ Failed async results always contain a nonempty `diagnostic`: native detail when
available, otherwise the status message. Use status codes for decisions and text available, otherwise the status message. Use status codes for decisions and text
for display; successful requests may have an empty diagnostic. for display; successful requests may have an empty diagnostic.
`uhdk_event.cycle_id` associates events within a pointer drag/capture, phased scroll `uhdk_event.cycle_id` associates events within a pointer drag/capture/confinement,
gesture, or IME preedit composition. These library-generated IDs are unique per phased scroll gesture, or IME preedit composition. These library-generated IDs are
session and separate from caller request tags and native edit `input_id` values. unique per session and separate from caller request tags and native edit
`input_id` values.
Hover, discrete wheel events, ordinary typing and unrelated events use zero. Hover, discrete wheel events, ordinary typing and unrelated events use zero.
Track the ID from the first relevant event; ignore updates from other cycles. Track the ID from the first relevant event; ignore updates from other cycles.
`UHDK_EVENT_CYCLE_END` carries the ID, window, and a `uhdk_cycle_end_event` payload. `UHDK_EVENT_CYCLE_END` carries the ID, window, and a `uhdk_cycle_end_event` payload.
Its `reason` distinguishes completion, cancellation, capture release/loss, focus Its `reason` distinguishes completion, cancellation, capture/confinement release
loss, hiding, replacement and shutdown. It reports the first observed ending or loss, focus loss, hiding, replacement and shutdown. It reports the first observed ending
cause and retires the interaction, without deciding whether cause and retires the interaction, without deciding whether
the application should commit or undo its work. Destruction invalidates cycles the application should commit or undo its work. Destruction invalidates cycles
immediately; fatal errors or early close may prevent delivery of queued endings. immediately; fatal errors or early close may prevent delivery of queued endings.

View File

@ -276,7 +276,8 @@ enum {
UHDK_CAP_POINTER_CAPTURE = 12, UHDK_CAP_POINTER_CAPTURE = 12,
UHDK_CAP_TEXT_INPUT = 16, UHDK_CAP_TEXT_INPUT = 16,
UHDK_CAP_OPENGL = 18, UHDK_CAP_OPENGL = 18,
UHDK_CAP_TRAY = 19 UHDK_CAP_TRAY = 19,
UHDK_CAP_POINTER_CONFINEMENT = 20
}; };
typedef struct uhdk_event uhdk_event; typedef struct uhdk_event uhdk_event;
@ -599,6 +600,34 @@ enum {
UHDK_KEY_F24 UHDK_KEY_F24
}; };
typedef uint32_t uhdk_function_key_policy;
enum {
UHDK_FUNCTION_KEYS_NATIVE = 0,
UHDK_FUNCTION_KEYS_APPLICATION = 1
};
/* Select native fallback handling for function keys received by this window.
* NATIVE is the default. On Windows, APPLICATION suppresses native default
* actions for unmodified F1-F24, including F10 menu activation, while continuing
* to deliver KEY events. Shift/Control/Alt/Super combinations retain native
* behavior, including Alt+F4. Caps Lock and Num Lock do not count as modifiers
* for this policy. Registered UHDK menu shortcuts still take precedence.
*
* Queued for the next frame boundary. A press keeps the policy selected on its
* initial key-down through repeats and release, even if the policy or modifiers
* change while held. Focus loss clears this held-key state; the configured
* policy persists. Set this before the relevant press; consuming a KEY event
* cannot retroactively cancel native handling.
*
* Accepted on all backends; currently has an effect only on Windows. This does
* not capture the keyboard or override shortcuts intercepted by the OS,
* compositor, IME, or keyboard firmware before UHDK receives the event.
*/
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_function_key_policy(
uhdk_window *window,
uhdk_function_key_policy policy
);
typedef uint32_t uhdk_pointer_button; typedef uint32_t uhdk_pointer_button;
enum { enum {
UHDK_BUTTON_NONE = 0, UHDK_BUTTON_NONE = 0,
@ -643,14 +672,31 @@ enum {
typedef uint32_t uhdk_pointer_mode; typedef uint32_t uhdk_pointer_mode;
enum { enum {
UHDK_POINTER_NORMAL = 0, UHDK_POINTER_NORMAL = 0,
UHDK_POINTER_CAPTURE = 1 UHDK_POINTER_CAPTURE = 1,
UHDK_POINTER_CONFINED = 2
}; };
/* Capture delivers selection-drag events outside the window. Focus loss or OS
* cancellation restores NORMAL and emits POINTER_MODE_CHANGED. */
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_cursor_shape( UHDK_API uhdk_status UHDK_CALL uhdk_window_set_cursor_shape(
uhdk_window *window, uhdk_window *window,
uhdk_cursor_shape shape uhdk_cursor_shape shape
); );
/* NORMAL releases capture or confinement. CAPTURE delivers selection-drag
* events outside the window. CONFINED keeps the cursor within the window's
* content area as it moves/resizes, preserving cursor shape and absolute motion.
* Confinement requires UHDK_CAP_POINTER_CONFINEMENT (otherwise UNSUPPORTED)
* and a visible, focused window with the pointer inside at native dispatch.
* Requests without the required focus/visibility are ignored.
* Windows and Wayland pointer-constraints-v1 support confinement; macOS currently
* does not.
*
* Changes are queued for the next frame boundary. OK means accepted, not active:
* observe POINTER_MODE_CHANGED for activation. Wayland activation is subject to
* compositor policy and may never occur. A native failure does not activate it.
* Focus loss, hiding/minimizing, or OS cancellation releases the mode (including
* pending confinement), restores NORMAL and emits POINTER_MODE_CHANGED. It does
* not reactivate automatically. Destroying/closing the window also releases it.
* Setting an already requested mode is a no-op. Modes are mutually exclusive;
* confinement does not provide relative motion or pointer locking.
*/
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_pointer_mode( UHDK_API uhdk_status UHDK_CALL uhdk_window_set_pointer_mode(
uhdk_window *window, uhdk_window *window,
uhdk_pointer_mode mode uhdk_pointer_mode mode
@ -1259,8 +1305,8 @@ typedef uint32_t uhdk_cycle_end_reason;
enum { enum {
UHDK_CYCLE_COMPLETED = 0, /* Last button release, scroll end, or committed composition. */ UHDK_CYCLE_COMPLETED = 0, /* Last button release, scroll end, or committed composition. */
UHDK_CYCLE_CANCELLED, /* Native scroll cancellation or composition ended without commit. */ UHDK_CYCLE_CANCELLED, /* Native scroll cancellation or composition ended without commit. */
UHDK_CYCLE_CAPTURE_RELEASED, /* Application explicitly released capture. */ UHDK_CYCLE_CAPTURE_RELEASED, /* Application released capture or confinement. */
UHDK_CYCLE_CAPTURE_LOST, /* Capture was interrupted externally. */ UHDK_CYCLE_CAPTURE_LOST, /* Capture or confinement was interrupted externally. */
UHDK_CYCLE_FOCUS_LOST, /* Window focus or application activation was lost. */ UHDK_CYCLE_FOCUS_LOST, /* Window focus or application activation was lost. */
UHDK_CYCLE_HIDDEN, /* Window was hidden; takes precedence over simultaneous focus loss. */ UHDK_CYCLE_HIDDEN, /* Window was hidden; takes precedence over simultaneous focus loss. */
UHDK_CYCLE_SUPERSEDED, /* A new native gesture replaced an unfinished one. */ UHDK_CYCLE_SUPERSEDED, /* A new native gesture replaced an unfinished one. */
@ -1283,7 +1329,7 @@ typedef struct uhdk_cycle_end_event {
* `window` is NULL for app-wide events. `time_ns` is monotonic time since * `window` is NULL for app-wide events. `time_ns` is monotonic time since
* session creation, not wall time. * session creation, not wall time.
* *
* `cycle_id` groups a pointer drag/capture, phased scroll, or visible IME * `cycle_id` groups a pointer drag/capture/confinement, phased scroll, or visible IME
* preedit. Zero means no cycle. It is not a request tag or `input_id`, and it * preedit. Zero means no cycle. It is not a request tag or `input_id`, and it
* is never reused in a session. See [Input lifetimes](#input-lifetimes). * is never reused in a session. See [Input lifetimes](#input-lifetimes).
* *

View File

@ -59,7 +59,7 @@ pub fn apply(self: *Cycles, next: *u64, event: *c.z_event) !Ended {
}, },
c.UHDK_EVENT_POINTER_ENTER, c.UHDK_EVENT_POINTER_LEAVE, c.UHDK_EVENT_POINTER_MOVE => event.cycle_id = self.pointer, c.UHDK_EVENT_POINTER_ENTER, c.UHDK_EVENT_POINTER_LEAVE, c.UHDK_EVENT_POINTER_MOVE => event.cycle_id = self.pointer,
c.UHDK_EVENT_POINTER_MODE_CHANGED => { c.UHDK_EVENT_POINTER_MODE_CHANGED => {
self.captured = event.data.pointer_mode == c.UHDK_POINTER_CAPTURE; self.captured = event.data.pointer_mode != c.UHDK_POINTER_NORMAL;
if (self.captured) try begin(&self.pointer, next); if (self.captured) try begin(&self.pointer, next);
event.cycle_id = self.pointer; event.cycle_id = self.pointer;
if (!self.captured) { if (!self.captured) {
@ -143,6 +143,37 @@ test "drag and capture share a cycle and late releases cannot revive it" {
try std.testing.expect(event.cycle_id != drag); try std.testing.expect(event.cycle_id != drag);
} }
test "confinement keeps a pointer cycle alive across button releases" {
var state: Cycles = .{};
var next: u64 = 1;
var event = std.mem.zeroes(c.z_event);
event.type = c.UHDK_EVENT_POINTER_MODE_CHANGED;
event.data.pointer_mode = c.UHDK_POINTER_CONFINED;
_ = try state.apply(&next, &event);
const cycle = event.cycle_id;
try std.testing.expect(cycle != 0);
event.type = c.UHDK_EVENT_POINTER_BUTTON;
event.data.pointer = std.mem.zeroes(c.uhdk_pointer_event);
event.data.pointer.button = c.UHDK_BUTTON_PRIMARY;
event.data.pointer.pressed = 1;
_ = try state.apply(&next, &event);
event.data.pointer.pressed = 0;
try std.testing.expectEqual(@as(usize, 0), (try state.apply(&next, &event)).len);
try std.testing.expectEqual(cycle, event.cycle_id);
event.type = c.UHDK_EVENT_POINTER_MODE_CHANGED;
event.data.pointer_mode = c.UHDK_POINTER_NORMAL;
event.cycle_end_reason = c.UHDK_CYCLE_CAPTURE_LOST;
const ended = try state.apply(&next, &event);
try std.testing.expectEqual(@as(usize, 1), ended.len);
try std.testing.expectEqual(cycle, ended.ids[0]);
try std.testing.expectEqual(@as(c.uhdk_cycle_end_reason, c.UHDK_CYCLE_CAPTURE_LOST), ended.reasons[0]);
event.type = c.UHDK_EVENT_POINTER_MOVE;
_ = try state.apply(&next, &event);
try std.testing.expectEqual(@as(u64, 0), event.cycle_id);
}
test "independent windows and kinds get distinct cycles and focus loss ends all" { test "independent windows and kinds get distinct cycles and focus loss ends all" {
var state: Cycles = .{}; var state: Cycles = .{};
var other: Cycles = .{}; var other: Cycles = .{};

View File

@ -283,6 +283,7 @@ pub export fn uhdk_get_backend(handle: ?*c.uhdk_session) c.uhdk_backend {
pub export fn uhdk_has_capability(handle: ?*c.uhdk_session, cap: c.uhdk_capability) c.uhdk_bool { pub export fn uhdk_has_capability(handle: ?*c.uhdk_session, cap: c.uhdk_capability) c.uhdk_bool {
if (@import("builtin").os.tag == .linux) return @import("../linux/native.zig").capability(handle, cap); if (@import("builtin").os.tag == .linux) return @import("../linux/native.zig").capability(handle, cap);
return switch (cap) { return switch (cap) {
c.UHDK_CAP_POINTER_CONFINEMENT => @intFromBool(@import("builtin").os.tag == .windows),
c.UHDK_CAP_FILE_DIALOGS, c.UHDK_CAP_CLIPBOARD, c.UHDK_CAP_DROP_FILES, c.UHDK_CAP_APP_MENU, c.UHDK_CAP_CONTEXT_MENU, c.UHDK_CAP_APP_ICON, c.UHDK_CAP_POINTER_CAPTURE, c.UHDK_CAP_TEXT_INPUT, c.UHDK_CAP_OPENGL, c.UHDK_CAP_TRAY => 1, c.UHDK_CAP_FILE_DIALOGS, c.UHDK_CAP_CLIPBOARD, c.UHDK_CAP_DROP_FILES, c.UHDK_CAP_APP_MENU, c.UHDK_CAP_CONTEXT_MENU, c.UHDK_CAP_APP_ICON, c.UHDK_CAP_POINTER_CAPTURE, c.UHDK_CAP_TEXT_INPUT, c.UHDK_CAP_OPENGL, c.UHDK_CAP_TRAY => 1,
else => 0, else => 0,
}; };

View File

@ -4,14 +4,37 @@ const c = @import("native");
const runtime = @import("../runtime.zig"); const runtime = @import("../runtime.zig");
const abi = @import("../abi.zig"); const abi = @import("../abi.zig");
pub export fn uhdk_window_set_function_key_policy(handle: ?*c.uhdk_window, policy: u32) abi.Status {
if (policy > c.UHDK_FUNCTION_KEYS_APPLICATION) return abi.INVALID;
return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_FUNCTION_KEYS, policy);
}
pub export fn uhdk_window_set_cursor_shape(handle: ?*c.uhdk_window, shape: u32) abi.Status { pub export fn uhdk_window_set_cursor_shape(handle: ?*c.uhdk_window, shape: u32) abi.Status {
if (shape > c.UHDK_CURSOR_HIDDEN) return abi.INVALID; if (shape > c.UHDK_CURSOR_HIDDEN) return abi.INVALID;
return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_CURSOR, shape); return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_CURSOR, shape);
} }
pub export fn uhdk_window_set_pointer_mode(handle: ?*c.uhdk_window, mode: u32) abi.Status { pub export fn uhdk_window_set_pointer_mode(handle: ?*c.uhdk_window, mode: u32) abi.Status {
if (mode > 1) return abi.INVALID; if (mode > c.UHDK_POINTER_CONFINED) return abi.INVALID;
return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_POINTER, mode); const command = runtime.createObjectCommand(
handle,
c.Z_KIND_WINDOW,
c.Z_POINTER,
) catch |err| return runtime.objectError(err);
const application = runtime.fromObjectHandle(handle).app;
if (mode == c.UHDK_POINTER_CONFINED) {
const supported = @import("app.zig").uhdk_has_capability(
runtime.toAppHandle(application),
c.UHDK_CAP_POINTER_CONFINEMENT,
);
if (supported == 0) {
runtime.abandon(command);
return c.UHDK_STATUS_UNSUPPORTED;
}
}
command.data.number = mode;
return runtime.submitCommand(application, command);
} }
pub export fn uhdk_window_set_text_input(handle: ?*c.uhdk_window, enabled: c.uhdk_bool) abi.Status { pub export fn uhdk_window_set_text_input(handle: ?*c.uhdk_window, enabled: c.uhdk_bool) abi.Status {

View File

@ -4,6 +4,56 @@ const Application = @import("Application.zig");
const runtime = @import("runtime.zig"); const runtime = @import("runtime.zig");
const abi = @import("abi.zig"); const abi = @import("abi.zig");
test "function key policy holds through repeats and release in both directions" {
const suppress = c.z_function_key_suppress;
const native = c.UHDK_FUNCTION_KEYS_NATIVE;
const application = c.UHDK_FUNCTION_KEYS_APPLICATION;
var state = std.mem.zeroes(c.z_function_keys);
var key: u32 = c.UHDK_KEY_F1;
while (key <= c.UHDK_KEY_F24) : (key += 1) {
// Switching to native while an application-owned press is held must
// not leak its repeats or release into native menu handling.
try std.testing.expect(suppress(&state, application, key, 0, 1) != 0);
try std.testing.expect(suppress(&state, native, key, 0, 1) != 0);
try std.testing.expect(suppress(&state, native, key, 0, 0) != 0);
// Conversely, a native key-down must retain native key-up handling so
// DefWindowProc can complete its F10 menu state, despite a policy change.
try std.testing.expect(suppress(&state, native, key, 0, 1) == 0);
try std.testing.expect(suppress(&state, application, key, 0, 1) == 0);
try std.testing.expect(suppress(&state, application, key, 0, 0) == 0);
}
try std.testing.expectEqual(@as(u32, 0), state.down);
try std.testing.expectEqual(@as(u32, 0), state.suppress);
}
test "function key policy preserves modified shortcuts and independent held keys" {
const suppress = c.z_function_key_suppress;
const application = c.UHDK_FUNCTION_KEYS_APPLICATION;
var state = std.mem.zeroes(c.z_function_keys);
for ([_]u32{ c.UHDK_MOD_SHIFT, c.UHDK_MOD_CONTROL, c.UHDK_MOD_ALT, c.UHDK_MOD_SUPER }) |mods| {
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F4, mods, 1) == 0);
// Releasing the modifier first must not steal the original shortcut's release.
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F4, 0, 0) == 0);
}
const locks = c.UHDK_MOD_CAPS_LOCK | c.UHDK_MOD_NUM_LOCK;
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F10, locks, 1) != 0);
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F4, c.UHDK_MOD_ALT, 1) == 0);
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F10, c.UHDK_MOD_ALT, 0) != 0);
try std.testing.expect(suppress(&state, application, c.UHDK_KEY_F4, 0, 0) == 0);
for ([_]u32{ c.UHDK_KEY_UNKNOWN, 'a', c.UHDK_KEY_ESCAPE, c.UHDK_KEY_F1 - 1, c.UHDK_KEY_F24 + 1 }) |key| {
try std.testing.expect(suppress(&state, application, key, 0, 1) == 0);
try std.testing.expect(suppress(&state, application, key, 0, 0) == 0);
}
try std.testing.expectEqual(@as(u32, 0), state.down);
}
test "function key policy rejects invalid arguments" {
const setPolicy = @import("api/input.zig").uhdk_window_set_function_key_policy;
try std.testing.expectEqual(@as(abi.Status, abi.INVALID), setPolicy(null, c.UHDK_FUNCTION_KEYS_NATIVE));
try std.testing.expectEqual(@as(abi.Status, abi.INVALID), setPolicy(null, 2));
}
fn destroyApplication(application: *Application) void { fn destroyApplication(application: *Application) void {
runtime.destroyEvents(application.pending_head); runtime.destroyEvents(application.pending_head);
runtime.destroyEvents(application.published); runtime.destroyEvents(application.published);

45
src/function_keys.h Normal file
View File

@ -0,0 +1,45 @@
#ifndef UHDK_PRIVATE_FUNCTION_KEYS_H
#define UHDK_PRIVATE_FUNCTION_KEYS_H
#include "uhdk.h"
/* Windows fallback must see a consistent down/up pair. In particular, changing
* policy between F10 down and up must not leave DefWindowProc's menu flag armed.
* Keep this state independent of the OS so the transition rules can be tested
* without a desktop. Zero initialization and focus loss clear held state. */
typedef struct z_function_keys {
uint32_t down;
uint32_t suppress;
} z_function_keys;
static inline int z_function_key_suppress(
z_function_keys *state,
uhdk_function_key_policy policy,
uhdk_key key,
uhdk_modifier_flags modifiers,
int pressed
) {
if (key < UHDK_KEY_F1 || key > UHDK_KEY_F24)
return 0;
uint32_t bit = 1u << (key - UHDK_KEY_F1);
int suppress;
if (state->down & bit) {
suppress = (state->suppress & bit) != 0;
} else {
suppress =
policy == UHDK_FUNCTION_KEYS_APPLICATION &&
!(modifiers & (UHDK_MOD_SHIFT | UHDK_MOD_CONTROL | UHDK_MOD_ALT | UHDK_MOD_SUPER));
if (pressed) {
state->down |= bit;
if (suppress)
state->suppress |= bit;
else
state->suppress &= ~bit;
}
}
if (!pressed) {
state->down &= ~bit;
state->suppress &= ~bit;
}
return suppress;
}
#endif

View File

@ -29,6 +29,9 @@ pub const State = struct {
pointer: ?*c.struct_wl_pointer = null, pointer: ?*c.struct_wl_pointer = null,
cursor_manager: ?*c.struct_wp_cursor_shape_manager_v1 = null, cursor_manager: ?*c.struct_wp_cursor_shape_manager_v1 = null,
cursor_device: ?*c.struct_wp_cursor_shape_device_v1 = null, cursor_device: ?*c.struct_wp_cursor_shape_device_v1 = null,
constraints: ?*c.struct_zwp_pointer_constraints_v1 = null,
constraints_name: u32 = 0,
confined: ?*c.struct_zwp_confined_pointer_v1 = null,
text_manager: ?*c.struct_zwp_text_input_manager_v3 = null, text_manager: ?*c.struct_zwp_text_input_manager_v3 = null,
text_input: ?*c.struct_zwp_text_input_v3 = null, text_input: ?*c.struct_zwp_text_input_v3 = null,
@ -58,7 +61,8 @@ pub const State = struct {
position: n.uhdk_point = .{ .x = 0, .y = 0 }, position: n.uhdk_point = .{ .x = 0, .y = 0 },
buttons: u32 = 0, buttons: u32 = 0,
captured: bool = false, pointer_mode: u32 = n.UHDK_POINTER_NORMAL,
mode_window: ?*native.Window = null,
last_click_time: u64 = 0, last_click_time: u64 = 0,
last_click_button: u32 = 0, last_click_button: u32 = 0,
@ -131,6 +135,10 @@ pub fn global(registry: ?*c.struct_wl_registry, name: u32, interface: []const u8
if (s.seat != null) _ = c.wl_seat_add_listener(s.seat, &seat_listener, null); if (s.seat != null) _ = c.wl_seat_add_listener(s.seat, &seat_listener, null);
} else if (std.mem.eql(u8, interface, "wp_cursor_shape_manager_v1")) { } else if (std.mem.eql(u8, interface, "wp_cursor_shape_manager_v1")) {
s.cursor_manager = @ptrCast(c.wl_registry_bind(registry, name, &c.z_uhdk_wp_cursor_shape_manager_v1_interface, 1)); s.cursor_manager = @ptrCast(c.wl_registry_bind(registry, name, &c.z_uhdk_wp_cursor_shape_manager_v1_interface, 1));
} else if (std.mem.eql(u8, interface, "zwp_pointer_constraints_v1") and s.constraints == null) {
s.constraints = @ptrCast(c.wl_registry_bind(registry, name, &c.z_uhdk_zwp_pointer_constraints_v1_interface, 1));
s.constraints_name = name;
native.setCapability(n.UHDK_CAP_POINTER_CONFINEMENT, s.pointer != null and s.constraints != null);
} else if (std.mem.eql(u8, interface, "zwp_text_input_manager_v3")) { } else if (std.mem.eql(u8, interface, "zwp_text_input_manager_v3")) {
s.text_manager = @ptrCast(c.wl_registry_bind(registry, name, &c.z_uhdk_zwp_text_input_manager_v3_interface, 1)); s.text_manager = @ptrCast(c.wl_registry_bind(registry, name, &c.z_uhdk_zwp_text_input_manager_v3_interface, 1));
} }
@ -148,6 +156,7 @@ pub fn setup() void {
Data.setup(); Data.setup();
Popup.capability(); Popup.capability();
native.setCapability(n.UHDK_CAP_POINTER_CAPTURE, s.pointer != null); native.setCapability(n.UHDK_CAP_POINTER_CAPTURE, s.pointer != null);
native.setCapability(n.UHDK_CAP_POINTER_CONFINEMENT, s.pointer != null and s.constraints != null);
native.setCapability(n.UHDK_CAP_TEXT_INPUT, s.context != null and s.keyboard != null); native.setCapability(n.UHDK_CAP_TEXT_INPUT, s.context != null and s.keyboard != null);
} }
@ -538,7 +547,7 @@ fn button(_: ?*anyopaque, _: ?*c.struct_wl_pointer, serial: u32, _: u32, code: u
s.last_click_position = s.position; s.last_click_position = s.position;
} else s.buttons &= ~mask; } else s.buttons &= ~mask;
pointerEvent(n.UHDK_EVENT_POINTER_BUTTON, mapped, pressed != 0, .{ .x = 0, .y = 0 }); pointerEvent(n.UHDK_EVENT_POINTER_BUTTON, mapped, pressed != 0, .{ .x = 0, .y = 0 });
if (s.buttons == 0) normal(n.UHDK_CYCLE_COMPLETED); if (s.buttons == 0 and s.pointer_mode == n.UHDK_POINTER_CAPTURE) normal(n.UHDK_CYCLE_COMPLETED);
} }
fn axis(_: ?*anyopaque, _: ?*c.struct_wl_pointer, _: u32, which: u32, value: i32) callconv(.c) void { fn axis(_: ?*anyopaque, _: ?*c.struct_wl_pointer, _: u32, which: u32, value: i32) callconv(.c) void {
@ -655,35 +664,84 @@ pub fn cursor(w: *native.Window, shape: u32) u32 {
return abi.OK; return abi.OK;
} }
pub fn capture(w: *native.Window, enabled: bool) u32 { pub fn pointerMode(w: *native.Window, mode: u32) u32 {
const s = state(); const s = state();
if (enabled and (s.pointer_focus != w or s.buttons == 0)) return abi.UNAVAILABLE; if (mode == n.UHDK_POINTER_NORMAL) {
if (!enabled) { release(w, n.UHDK_CYCLE_CAPTURE_RELEASED);
normal(n.UHDK_CYCLE_CAPTURE_RELEASED);
return abi.OK; return abi.OK;
} }
s.captured = true; if (s.mode_window == w and (s.pointer_mode == mode or (mode == n.UHDK_POINTER_CONFINED and s.confined != null))) {
return abi.OK;
}
if (mode == n.UHDK_POINTER_CAPTURE and (s.pointer_focus != w or s.buttons == 0)) return abi.UNAVAILABLE;
if (mode == n.UHDK_POINTER_CONFINED) {
if (s.constraints == null or s.pointer == null) return n.UHDK_STATUS_UNSUPPORTED;
if (s.key_focus != w or s.pointer_focus != w or !w.want_visible or s.position.x < 0 or s.position.y < 0 or s.position.x >= @as(f32, @floatFromInt(w.width)) or s.position.y >= @as(f32, @floatFromInt(w.height))) {
return abi.UNAVAILABLE;
}
const constraint = c.zwp_pointer_constraints_v1_confine_pointer(
s.constraints,
w.surface,
s.pointer,
null, // The complete surface input region follows content resizes.
c.ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT,
) orelse return abi.OOM;
normal(n.UHDK_CYCLE_CAPTURE_RELEASED);
s.mode_window = w;
s.confined = constraint;
_ = c.zwp_confined_pointer_v1_add_listener(constraint, &confined_listener, null);
return abi.OK; // Only the compositor's confined event confirms activation.
}
normal(n.UHDK_CYCLE_CAPTURE_RELEASED);
s.mode_window = w;
s.pointer_mode = mode;
modeEvent(w, mode, n.UHDK_CYCLE_CAPTURE_RELEASED);
return abi.OK;
}
fn modeEvent(w: *native.Window, mode: u32, reason: n.uhdk_cycle_end_reason) void {
var e = std.mem.zeroes(n.z_event); var e = std.mem.zeroes(n.z_event);
e.type = n.UHDK_EVENT_POINTER_MODE_CHANGED; e.type = n.UHDK_EVENT_POINTER_MODE_CHANGED;
e.data.pointer_mode = n.UHDK_POINTER_CAPTURE; e.data.pointer_mode = mode;
e.cycle_end_reason = reason;
send(w, &e); send(w, &e);
return abi.OK;
} }
fn normal(reason: n.uhdk_cycle_end_reason) void { fn normal(reason: n.uhdk_cycle_end_reason) void {
const s = state(); const s = state();
if (!s.captured) return; const w = s.mode_window orelse return;
s.captured = false; if (s.confined != null) c.zwp_confined_pointer_v1_destroy(s.confined);
if (s.pointer_focus) |w| { s.confined = null;
var e = std.mem.zeroes(n.z_event); s.mode_window = null;
e.type = n.UHDK_EVENT_POINTER_MODE_CHANGED; s.pointer_mode = n.UHDK_POINTER_NORMAL;
e.data.pointer_mode = n.UHDK_POINTER_NORMAL; modeEvent(w, n.UHDK_POINTER_NORMAL, reason);
e.cycle_end_reason = reason;
send(w, &e);
}
} }
pub fn release(w: *native.Window, reason: n.uhdk_cycle_end_reason) void {
if (state().mode_window == w) normal(reason);
}
fn confined(_: ?*anyopaque, object: ?*c.struct_zwp_confined_pointer_v1) callconv(.c) void {
const s = state();
if (object != s.confined) return;
const w = s.mode_window orelse return;
if (s.pointer_mode == n.UHDK_POINTER_CONFINED) return;
s.pointer_mode = n.UHDK_POINTER_CONFINED;
modeEvent(w, n.UHDK_POINTER_CONFINED, n.UHDK_CYCLE_COMPLETED);
}
fn unconfined(_: ?*anyopaque, object: ?*c.struct_zwp_confined_pointer_v1) callconv(.c) void {
if (object == state().confined) normal(n.UHDK_CYCLE_CAPTURE_LOST);
}
const confined_listener: c.struct_zwp_confined_pointer_v1_listener = .{
.confined = confined,
.unconfined = unconfined,
};
fn popupTrigger(w: ?*native.Window, serial: u32) void { fn popupTrigger(w: ?*native.Window, serial: u32) void {
const s = state(); const s = state();
s.popup_window = w; s.popup_window = w;
@ -705,6 +763,7 @@ pub fn clearPopupTrigger(w: *native.Window) void {
} }
pub fn forget(w: *native.Window) void { pub fn forget(w: *native.Window) void {
release(w, n.UHDK_CYCLE_CANCELLED);
clearPopupTrigger(w); clearPopupTrigger(w);
if (state().key_focus == w) leaveKeyboard(); if (state().key_focus == w) leaveKeyboard();
if (state().pointer_focus == w) leavePointer(); if (state().pointer_focus == w) leavePointer();
@ -713,6 +772,13 @@ pub fn forget(w: *native.Window) void {
pub fn remove(name: u32) void { pub fn remove(name: u32) void {
if (name == state().seat_name) releaseSeat(); if (name == state().seat_name) releaseSeat();
if (state().constraints != null and name == state().constraints_name) {
if (state().confined != null) normal(n.UHDK_CYCLE_CAPTURE_LOST);
c.zwp_pointer_constraints_v1_destroy(state().constraints);
state().constraints = null;
state().constraints_name = 0;
setup();
}
} }
fn releaseSeat() void { fn releaseSeat() void {
@ -745,6 +811,7 @@ pub fn deinit() void {
releaseSeat(); releaseSeat();
if (s.text_manager != null) c.zwp_text_input_manager_v3_destroy(s.text_manager); if (s.text_manager != null) c.zwp_text_input_manager_v3_destroy(s.text_manager);
if (s.cursor_manager != null) c.wp_cursor_shape_manager_v1_destroy(s.cursor_manager); if (s.cursor_manager != null) c.wp_cursor_shape_manager_v1_destroy(s.cursor_manager);
if (s.constraints != null) c.zwp_pointer_constraints_v1_destroy(s.constraints);
if (s.compose != null) c.z_xkb_compose_state_unref.?(s.compose); if (s.compose != null) c.z_xkb_compose_state_unref.?(s.compose);
if (s.compose_table != null) c.z_xkb_compose_table_unref.?(s.compose_table); if (s.compose_table != null) c.z_xkb_compose_table_unref.?(s.compose_table);
if (s.state != null) c.z_xkb_state_unref.?(s.state); if (s.state != null) c.z_xkb_state_unref.?(s.state);

View File

@ -137,8 +137,14 @@ NixOS with Plasma 6.5.6 and Mesa 25.2.6; other systems are not runtime-qualified
Escape first cancels composition before becoming an application action. Escape first cancels composition before becoming an application action.
- Pointer motion, buttons, wheel/touchpad frames and cursor-shape-v1 are supported. - Pointer motion, buttons, wheel/touchpad frames and cursor-shape-v1 are supported.
Capture acknowledges Wayland's implicit button grab during a selection drag; Capture acknowledges Wayland's implicit button grab during a selection drag;
requesting it without a held button/focused pointer returns `UNAVAILABLE`. requests without a held button/focused pointer are ignored at native dispatch.
The last button release or focus loss restores normal mode. There is no pointer The last button release or focus loss restores normal mode. Confinement uses
pointer-constraints-v1 when `UHDK_CAP_POINTER_CONFINEMENT` is available. It
requires a visible window with keyboard/pointer focus and uses the complete
content input region, including after resizing. `POINTER_MODE_CHANGED` reports
actual activation; the compositor may defer or decline it. Focus loss, hiding,
minimization, seat loss, or compositor cancellation also cancels pending
confinement. Applications must explicitly request it again. There is no pointer
lock, relative motion, touch, tablet, or themed-cursor fallback yet. lock, relative motion, touch, tablet, or themed-cursor fallback yet.
- Clipboard writes require keyboard focus and a triggering input serial. They - Clipboard writes require keyboard focus and a triggering input serial. They
never wait for an unrelated future key. Reads negotiate UTF-8/plain text, never wait for an unrelated future key. Reads negotiate UTF-8/plain text,

View File

@ -31,6 +31,7 @@
#include "viewporter.h" #include "viewporter.h"
#include "fractional-scale-v1.h" #include "fractional-scale-v1.h"
#include "cursor-shape-v1.h" #include "cursor-shape-v1.h"
#include "pointer-constraints-unstable-v1.h"
#include "text-input-unstable-v3.h" #include "text-input-unstable-v3.h"
#include "xdg-activation-v1.h" #include "xdg-activation-v1.h"
#include "xdg-foreign-unstable-v2.h" #include "xdg-foreign-unstable-v2.h"

View File

@ -13,7 +13,7 @@ pub fn configure(b: *std.Build, module: *std.Build.Module, target: std.Build.Res
module.addImport("linux_c", bindings.createModule()); module.addImport("linux_c", bindings.createModule());
module.addCSourceFile(.{ .file = b.path("src/linux/libraries.c"), .flags = &.{ "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-fvisibility=hidden" } }); module.addCSourceFile(.{ .file = b.path("src/linux/libraries.c"), .flags = &.{ "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-fvisibility=hidden" } });
for ([_][]const u8{ "wayland", "xdg-shell", "xdg-decoration-unstable-v1", "viewporter", "fractional-scale-v1", "cursor-shape-v1", "tablet-v2", "text-input-unstable-v3", "xdg-activation-v1", "xdg-foreign-unstable-v2", "xdg-toplevel-icon-v1", "appmenu" }) |name| { for ([_][]const u8{ "wayland", "xdg-shell", "xdg-decoration-unstable-v1", "viewporter", "fractional-scale-v1", "cursor-shape-v1", "pointer-constraints-unstable-v1", "tablet-v2", "text-input-unstable-v3", "xdg-activation-v1", "xdg-foreign-unstable-v2", "xdg-toplevel-icon-v1", "appmenu" }) |name| {
module.addCSourceFile(.{ module.addCSourceFile(.{
.file = b.path(b.fmt("src/linux/protocols/generated/{s}.c", .{name})), .file = b.path(b.fmt("src/linux/protocols/generated/{s}.c", .{name})),
.flags = &.{ "-std=c99", "-fdata-sections", "-include", b.path("src/linux/protocols/generated/private-symbols.h").getPath(b) }, .flags = &.{ "-std=c99", "-fdata-sections", "-include", b.path("src/linux/protocols/generated/private-symbols.h").getPath(b) },

View File

@ -431,6 +431,7 @@ fn topConfigure(data: ?*anyopaque, _: ?*c.struct_xdg_toplevel, width: i32, heigh
const values: []const u32 = if (states.*.size == 0) &.{} else @as([*]const u32, @ptrCast(@alignCast(states.*.data)))[0 .. states.*.size / @sizeOf(u32)]; const values: []const u32 = if (states.*.size == 0) &.{} else @as([*]const u32, @ptrCast(@alignCast(states.*.data)))[0 .. states.*.size / @sizeOf(u32)];
w.observation = WindowState.observe(c.xdg_toplevel_get_version(w.top), values); w.observation = WindowState.observe(c.xdg_toplevel_get_version(w.top), values);
w.focused = w.observation.focused; w.focused = w.observation.focused;
if (!w.focused) Input.release(w, n.UHDK_CYCLE_FOCUS_LOST);
w.state = w.observation.geometry; w.state = w.observation.geometry;
} }
@ -722,6 +723,7 @@ export fn z_native_execute(_: ?*n.uhdk_session, raw: [*c]const n.z_command, id:
n.UHDK_WINDOW_MINIMIZED => { n.UHDK_WINDOW_MINIMIZED => {
if (!w.wm_caps.minimize) return n.UHDK_STATUS_UNSUPPORTED; if (!w.wm_caps.minimize) return n.UHDK_STATUS_UNSUPPORTED;
Input.release(w, n.UHDK_CYCLE_HIDDEN);
c.xdg_toplevel_set_minimized(w.top); c.xdg_toplevel_set_minimized(w.top);
}, },
n.UHDK_WINDOW_MAXIMIZED => { n.UHDK_WINDOW_MAXIMIZED => {
@ -742,6 +744,7 @@ export fn z_native_execute(_: ?*n.uhdk_session, raw: [*c]const n.z_command, id:
n.Z_VISIBLE => { n.Z_VISIBLE => {
w.want_visible = cmd.number != 0; w.want_visible = cmd.number != 0;
if (!w.want_visible) { if (!w.want_visible) {
Input.release(w, n.UHDK_CYCLE_HIDDEN);
Popup.forget(w); Popup.forget(w);
Input.clearPopupTrigger(w); Input.clearPopupTrigger(w);
} }
@ -752,7 +755,8 @@ export fn z_native_execute(_: ?*n.uhdk_session, raw: [*c]const n.z_command, id:
n.Z_STYLE => return setStyle(b, w, cmd.style), n.Z_STYLE => return setStyle(b, w, cmd.style),
n.Z_DROP => return Data.enable(w, cmd.number != 0), n.Z_DROP => return Data.enable(w, cmd.number != 0),
n.Z_CURSOR => return Input.cursor(w, @intCast(cmd.number)), n.Z_CURSOR => return Input.cursor(w, @intCast(cmd.number)),
n.Z_POINTER => return Input.capture(w, cmd.number != 0), n.Z_POINTER => return Input.pointerMode(w, @intCast(cmd.number)),
n.Z_FUNCTION_KEYS => {}, // No native window fallback for received function keys.
n.Z_TEXT_ENABLE => return Text.enable(w, cmd.number != 0), n.Z_TEXT_ENABLE => return Text.enable(w, cmd.number != 0),
n.Z_TEXT_STATE => return Text.snapshot(w, cmd.text_state), n.Z_TEXT_STATE => return Text.snapshot(w, cmd.text_state),
n.Z_TEXT_CANCEL => Text.cancel(w), n.Z_TEXT_CANCEL => Text.cancel(w),

View File

@ -0,0 +1,109 @@
/* Generated by wayland-scanner 1.24.0 */
/*
* Copyright © 2014 Jonas Ådahl
* Copyright © 2015 Red Hat Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface wl_pointer_interface;
extern const struct wl_interface wl_region_interface;
extern const struct wl_interface wl_surface_interface;
extern const struct wl_interface zwp_confined_pointer_v1_interface;
extern const struct wl_interface zwp_locked_pointer_v1_interface;
static const struct wl_interface *pointer_constraints_unstable_v1_types[] = {
NULL,
NULL,
&zwp_locked_pointer_v1_interface,
&wl_surface_interface,
&wl_pointer_interface,
&wl_region_interface,
NULL,
&zwp_confined_pointer_v1_interface,
&wl_surface_interface,
&wl_pointer_interface,
&wl_region_interface,
NULL,
&wl_region_interface,
&wl_region_interface,
};
static const struct wl_message zwp_pointer_constraints_v1_requests[] = {
{ "destroy", "", pointer_constraints_unstable_v1_types + 0 },
{ "lock_pointer", "noo?ou", pointer_constraints_unstable_v1_types + 2 },
{ "confine_pointer", "noo?ou", pointer_constraints_unstable_v1_types + 7 },
};
WL_PRIVATE const struct wl_interface zwp_pointer_constraints_v1_interface = {
"zwp_pointer_constraints_v1", 1,
3, zwp_pointer_constraints_v1_requests,
0, NULL,
};
static const struct wl_message zwp_locked_pointer_v1_requests[] = {
{ "destroy", "", pointer_constraints_unstable_v1_types + 0 },
{ "set_cursor_position_hint", "ff", pointer_constraints_unstable_v1_types + 0 },
{ "set_region", "?o", pointer_constraints_unstable_v1_types + 12 },
};
static const struct wl_message zwp_locked_pointer_v1_events[] = {
{ "locked", "", pointer_constraints_unstable_v1_types + 0 },
{ "unlocked", "", pointer_constraints_unstable_v1_types + 0 },
};
WL_PRIVATE const struct wl_interface zwp_locked_pointer_v1_interface = {
"zwp_locked_pointer_v1", 1,
3, zwp_locked_pointer_v1_requests,
2, zwp_locked_pointer_v1_events,
};
static const struct wl_message zwp_confined_pointer_v1_requests[] = {
{ "destroy", "", pointer_constraints_unstable_v1_types + 0 },
{ "set_region", "?o", pointer_constraints_unstable_v1_types + 13 },
};
static const struct wl_message zwp_confined_pointer_v1_events[] = {
{ "confined", "", pointer_constraints_unstable_v1_types + 0 },
{ "unconfined", "", pointer_constraints_unstable_v1_types + 0 },
};
WL_PRIVATE const struct wl_interface zwp_confined_pointer_v1_interface = {
"zwp_confined_pointer_v1", 1,
2, zwp_confined_pointer_v1_requests,
2, zwp_confined_pointer_v1_events,
};

View File

@ -0,0 +1,662 @@
/* Generated by wayland-scanner 1.24.0 */
#ifndef POINTER_CONSTRAINTS_UNSTABLE_V1_CLIENT_PROTOCOL_H
#define POINTER_CONSTRAINTS_UNSTABLE_V1_CLIENT_PROTOCOL_H
#include <stdint.h>
#include <stddef.h>
#include "wayland-client.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @page page_pointer_constraints_unstable_v1 The pointer_constraints_unstable_v1 protocol
* protocol for constraining pointer motions
*
* @section page_desc_pointer_constraints_unstable_v1 Description
*
* This protocol specifies a set of interfaces used for adding constraints to
* the motion of a pointer. Possible constraints include confining pointer
* motions to a given region, or locking it to its current position.
*
* In order to constrain the pointer, a client must first bind the global
* interface "wp_pointer_constraints" which, if a compositor supports pointer
* constraints, is exposed by the registry. Using the bound global object, the
* client uses the request that corresponds to the type of constraint it wants
* to make. See wp_pointer_constraints for more details.
*
* Warning! The protocol described in this file is experimental and backward
* incompatible changes may be made. Backward compatible changes may be added
* together with the corresponding interface version bump. Backward
* incompatible changes are done by bumping the version number in the protocol
* and interface names and resetting the interface version. Once the protocol
* is to be declared stable, the 'z' prefix and the version number in the
* protocol and interface names are removed and the interface version number is
* reset.
*
* @section page_ifaces_pointer_constraints_unstable_v1 Interfaces
* - @subpage page_iface_zwp_pointer_constraints_v1 - constrain the movement of a pointer
* - @subpage page_iface_zwp_locked_pointer_v1 - receive relative pointer motion events
* - @subpage page_iface_zwp_confined_pointer_v1 - confined pointer object
* @section page_copyright_pointer_constraints_unstable_v1 Copyright
* <pre>
*
* Copyright © 2014 Jonas Ådahl
* Copyright © 2015 Red Hat Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
* </pre>
*/
struct wl_pointer;
struct wl_region;
struct wl_surface;
struct zwp_confined_pointer_v1;
struct zwp_locked_pointer_v1;
struct zwp_pointer_constraints_v1;
#ifndef ZWP_POINTER_CONSTRAINTS_V1_INTERFACE
#define ZWP_POINTER_CONSTRAINTS_V1_INTERFACE
/**
* @page page_iface_zwp_pointer_constraints_v1 zwp_pointer_constraints_v1
* @section page_iface_zwp_pointer_constraints_v1_desc Description
*
* The global interface exposing pointer constraining functionality. It
* exposes two requests: lock_pointer for locking the pointer to its
* position, and confine_pointer for locking the pointer to a region.
*
* The lock_pointer and confine_pointer requests create the objects
* wp_locked_pointer and wp_confined_pointer respectively, and the client can
* use these objects to interact with the lock.
*
* For any surface, only one lock or confinement may be active across all
* wl_pointer objects of the same seat. If a lock or confinement is requested
* when another lock or confinement is active or requested on the same surface
* and with any of the wl_pointer objects of the same seat, an
* 'already_constrained' error will be raised.
* @section page_iface_zwp_pointer_constraints_v1_api API
* See @ref iface_zwp_pointer_constraints_v1.
*/
/**
* @defgroup iface_zwp_pointer_constraints_v1 The zwp_pointer_constraints_v1 interface
*
* The global interface exposing pointer constraining functionality. It
* exposes two requests: lock_pointer for locking the pointer to its
* position, and confine_pointer for locking the pointer to a region.
*
* The lock_pointer and confine_pointer requests create the objects
* wp_locked_pointer and wp_confined_pointer respectively, and the client can
* use these objects to interact with the lock.
*
* For any surface, only one lock or confinement may be active across all
* wl_pointer objects of the same seat. If a lock or confinement is requested
* when another lock or confinement is active or requested on the same surface
* and with any of the wl_pointer objects of the same seat, an
* 'already_constrained' error will be raised.
*/
extern const struct wl_interface zwp_pointer_constraints_v1_interface;
#endif
#ifndef ZWP_LOCKED_POINTER_V1_INTERFACE
#define ZWP_LOCKED_POINTER_V1_INTERFACE
/**
* @page page_iface_zwp_locked_pointer_v1 zwp_locked_pointer_v1
* @section page_iface_zwp_locked_pointer_v1_desc Description
*
* The wp_locked_pointer interface represents a locked pointer state.
*
* While the lock of this object is active, the wl_pointer objects of the
* associated seat will not emit any wl_pointer.motion events.
*
* This object will send the event 'locked' when the lock is activated.
* Whenever the lock is activated, it is guaranteed that the locked surface
* will already have received pointer focus and that the pointer will be
* within the region passed to the request creating this object.
*
* To unlock the pointer, send the destroy request. This will also destroy
* the wp_locked_pointer object.
*
* If the compositor decides to unlock the pointer the unlocked event is
* sent. See wp_locked_pointer.unlock for details.
*
* When unlocking, the compositor may warp the cursor position to the set
* cursor position hint. If it does, it will not result in any relative
* motion events emitted via wp_relative_pointer.
*
* If the surface the lock was requested on is destroyed and the lock is not
* yet activated, the wp_locked_pointer object is now defunct and must be
* destroyed.
* @section page_iface_zwp_locked_pointer_v1_api API
* See @ref iface_zwp_locked_pointer_v1.
*/
/**
* @defgroup iface_zwp_locked_pointer_v1 The zwp_locked_pointer_v1 interface
*
* The wp_locked_pointer interface represents a locked pointer state.
*
* While the lock of this object is active, the wl_pointer objects of the
* associated seat will not emit any wl_pointer.motion events.
*
* This object will send the event 'locked' when the lock is activated.
* Whenever the lock is activated, it is guaranteed that the locked surface
* will already have received pointer focus and that the pointer will be
* within the region passed to the request creating this object.
*
* To unlock the pointer, send the destroy request. This will also destroy
* the wp_locked_pointer object.
*
* If the compositor decides to unlock the pointer the unlocked event is
* sent. See wp_locked_pointer.unlock for details.
*
* When unlocking, the compositor may warp the cursor position to the set
* cursor position hint. If it does, it will not result in any relative
* motion events emitted via wp_relative_pointer.
*
* If the surface the lock was requested on is destroyed and the lock is not
* yet activated, the wp_locked_pointer object is now defunct and must be
* destroyed.
*/
extern const struct wl_interface zwp_locked_pointer_v1_interface;
#endif
#ifndef ZWP_CONFINED_POINTER_V1_INTERFACE
#define ZWP_CONFINED_POINTER_V1_INTERFACE
/**
* @page page_iface_zwp_confined_pointer_v1 zwp_confined_pointer_v1
* @section page_iface_zwp_confined_pointer_v1_desc Description
*
* The wp_confined_pointer interface represents a confined pointer state.
*
* This object will send the event 'confined' when the confinement is
* activated. Whenever the confinement is activated, it is guaranteed that
* the surface the pointer is confined to will already have received pointer
* focus and that the pointer will be within the region passed to the request
* creating this object. It is up to the compositor to decide whether this
* requires some user interaction and if the pointer will warp to within the
* passed region if outside.
*
* To unconfine the pointer, send the destroy request. This will also destroy
* the wp_confined_pointer object.
*
* If the compositor decides to unconfine the pointer the unconfined event is
* sent. The wp_confined_pointer object is at this point defunct and should
* be destroyed.
* @section page_iface_zwp_confined_pointer_v1_api API
* See @ref iface_zwp_confined_pointer_v1.
*/
/**
* @defgroup iface_zwp_confined_pointer_v1 The zwp_confined_pointer_v1 interface
*
* The wp_confined_pointer interface represents a confined pointer state.
*
* This object will send the event 'confined' when the confinement is
* activated. Whenever the confinement is activated, it is guaranteed that
* the surface the pointer is confined to will already have received pointer
* focus and that the pointer will be within the region passed to the request
* creating this object. It is up to the compositor to decide whether this
* requires some user interaction and if the pointer will warp to within the
* passed region if outside.
*
* To unconfine the pointer, send the destroy request. This will also destroy
* the wp_confined_pointer object.
*
* If the compositor decides to unconfine the pointer the unconfined event is
* sent. The wp_confined_pointer object is at this point defunct and should
* be destroyed.
*/
extern const struct wl_interface zwp_confined_pointer_v1_interface;
#endif
#ifndef ZWP_POINTER_CONSTRAINTS_V1_ERROR_ENUM
#define ZWP_POINTER_CONSTRAINTS_V1_ERROR_ENUM
/**
* @ingroup iface_zwp_pointer_constraints_v1
* wp_pointer_constraints error values
*
* These errors can be emitted in response to wp_pointer_constraints
* requests.
*/
enum zwp_pointer_constraints_v1_error {
/**
* pointer constraint already requested on that surface
*/
ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED = 1,
};
#endif /* ZWP_POINTER_CONSTRAINTS_V1_ERROR_ENUM */
#ifndef ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ENUM
#define ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ENUM
/**
* @ingroup iface_zwp_pointer_constraints_v1
* constraint lifetime
*
* These values represent different lifetime semantics. They are passed
* as arguments to the factory requests to specify how the constraint
* lifetimes should be managed.
*/
enum zwp_pointer_constraints_v1_lifetime {
/**
* the pointer constraint is defunct once deactivated
*
* A oneshot pointer constraint will never reactivate once it has
* been deactivated. See the corresponding deactivation event
* (wp_locked_pointer.unlocked and wp_confined_pointer.unconfined)
* for details.
*/
ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT = 1,
/**
* the pointer constraint may reactivate
*
* A persistent pointer constraint may again reactivate once it
* has been deactivated. See the corresponding deactivation event
* (wp_locked_pointer.unlocked and wp_confined_pointer.unconfined)
* for details.
*/
ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT = 2,
};
#endif /* ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ENUM */
#define ZWP_POINTER_CONSTRAINTS_V1_DESTROY 0
#define ZWP_POINTER_CONSTRAINTS_V1_LOCK_POINTER 1
#define ZWP_POINTER_CONSTRAINTS_V1_CONFINE_POINTER 2
/**
* @ingroup iface_zwp_pointer_constraints_v1
*/
#define ZWP_POINTER_CONSTRAINTS_V1_DESTROY_SINCE_VERSION 1
/**
* @ingroup iface_zwp_pointer_constraints_v1
*/
#define ZWP_POINTER_CONSTRAINTS_V1_LOCK_POINTER_SINCE_VERSION 1
/**
* @ingroup iface_zwp_pointer_constraints_v1
*/
#define ZWP_POINTER_CONSTRAINTS_V1_CONFINE_POINTER_SINCE_VERSION 1
/** @ingroup iface_zwp_pointer_constraints_v1 */
static inline void
zwp_pointer_constraints_v1_set_user_data(struct zwp_pointer_constraints_v1 *zwp_pointer_constraints_v1, void *user_data)
{
wl_proxy_set_user_data((struct wl_proxy *) zwp_pointer_constraints_v1, user_data);
}
/** @ingroup iface_zwp_pointer_constraints_v1 */
static inline void *
zwp_pointer_constraints_v1_get_user_data(struct zwp_pointer_constraints_v1 *zwp_pointer_constraints_v1)
{
return wl_proxy_get_user_data((struct wl_proxy *) zwp_pointer_constraints_v1);
}
static inline uint32_t
zwp_pointer_constraints_v1_get_version(struct zwp_pointer_constraints_v1 *zwp_pointer_constraints_v1)
{
return wl_proxy_get_version((struct wl_proxy *) zwp_pointer_constraints_v1);
}
/**
* @ingroup iface_zwp_pointer_constraints_v1
*
* Used by the client to notify the server that it will no longer use this
* pointer constraints object.
*/
static inline void
zwp_pointer_constraints_v1_destroy(struct zwp_pointer_constraints_v1 *zwp_pointer_constraints_v1)
{
wl_proxy_marshal_flags((struct wl_proxy *) zwp_pointer_constraints_v1,
ZWP_POINTER_CONSTRAINTS_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_pointer_constraints_v1), WL_MARSHAL_FLAG_DESTROY);
}
/**
* @ingroup iface_zwp_pointer_constraints_v1
*
* The lock_pointer request lets the client request to disable movements of
* the virtual pointer (i.e. the cursor), effectively locking the pointer
* to a position. This request may not take effect immediately; in the
* future, when the compositor deems implementation-specific constraints
* are satisfied, the pointer lock will be activated and the compositor
* sends a locked event.
*
* The protocol provides no guarantee that the constraints are ever
* satisfied, and does not require the compositor to send an error if the
* constraints cannot ever be satisfied. It is thus possible to request a
* lock that will never activate.
*
* There may not be another pointer constraint of any kind requested or
* active on the surface for any of the wl_pointer objects of the seat of
* the passed pointer when requesting a lock. If there is, an error will be
* raised. See general pointer lock documentation for more details.
*
* The intersection of the region passed with this request and the input
* region of the surface is used to determine where the pointer must be
* in order for the lock to activate. It is up to the compositor whether to
* warp the pointer or require some kind of user interaction for the lock
* to activate. If the region is null the surface input region is used.
*
* A surface may receive pointer focus without the lock being activated.
*
* The request creates a new object wp_locked_pointer which is used to
* interact with the lock as well as receive updates about its state. See
* the the description of wp_locked_pointer for further information.
*
* Note that while a pointer is locked, the wl_pointer objects of the
* corresponding seat will not emit any wl_pointer.motion events, but
* relative motion events will still be emitted via wp_relative_pointer
* objects of the same seat. wl_pointer.axis and wl_pointer.button events
* are unaffected.
*/
static inline struct zwp_locked_pointer_v1 *
zwp_pointer_constraints_v1_lock_pointer(struct zwp_pointer_constraints_v1 *zwp_pointer_constraints_v1, struct wl_surface *surface, struct wl_pointer *pointer, struct wl_region *region, uint32_t lifetime)
{
struct wl_proxy *id;
id = wl_proxy_marshal_flags((struct wl_proxy *) zwp_pointer_constraints_v1,
ZWP_POINTER_CONSTRAINTS_V1_LOCK_POINTER, &zwp_locked_pointer_v1_interface, wl_proxy_get_version((struct wl_proxy *) zwp_pointer_constraints_v1), 0, NULL, surface, pointer, region, lifetime);
return (struct zwp_locked_pointer_v1 *) id;
}
/**
* @ingroup iface_zwp_pointer_constraints_v1
*
* The confine_pointer request lets the client request to confine the
* pointer cursor to a given region. This request may not take effect
* immediately; in the future, when the compositor deems implementation-
* specific constraints are satisfied, the pointer confinement will be
* activated and the compositor sends a confined event.
*
* The intersection of the region passed with this request and the input
* region of the surface is used to determine where the pointer must be
* in order for the confinement to activate. It is up to the compositor
* whether to warp the pointer or require some kind of user interaction for
* the confinement to activate. If the region is null the surface input
* region is used.
*
* The request will create a new object wp_confined_pointer which is used
* to interact with the confinement as well as receive updates about its
* state. See the the description of wp_confined_pointer for further
* information.
*/
static inline struct zwp_confined_pointer_v1 *
zwp_pointer_constraints_v1_confine_pointer(struct zwp_pointer_constraints_v1 *zwp_pointer_constraints_v1, struct wl_surface *surface, struct wl_pointer *pointer, struct wl_region *region, uint32_t lifetime)
{
struct wl_proxy *id;
id = wl_proxy_marshal_flags((struct wl_proxy *) zwp_pointer_constraints_v1,
ZWP_POINTER_CONSTRAINTS_V1_CONFINE_POINTER, &zwp_confined_pointer_v1_interface, wl_proxy_get_version((struct wl_proxy *) zwp_pointer_constraints_v1), 0, NULL, surface, pointer, region, lifetime);
return (struct zwp_confined_pointer_v1 *) id;
}
/**
* @ingroup iface_zwp_locked_pointer_v1
* @struct zwp_locked_pointer_v1_listener
*/
struct zwp_locked_pointer_v1_listener {
/**
* lock activation event
*
* Notification that the pointer lock of the seat's pointer is
* activated.
*/
void (*locked)(void *data,
struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1);
/**
* lock deactivation event
*
* Notification that the pointer lock of the seat's pointer is no
* longer active. If this is a oneshot pointer lock (see
* wp_pointer_constraints.lifetime) this object is now defunct and
* should be destroyed. If this is a persistent pointer lock (see
* wp_pointer_constraints.lifetime) this pointer lock may again
* reactivate in the future.
*/
void (*unlocked)(void *data,
struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1);
};
/**
* @ingroup iface_zwp_locked_pointer_v1
*/
static inline int
zwp_locked_pointer_v1_add_listener(struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1,
const struct zwp_locked_pointer_v1_listener *listener, void *data)
{
return wl_proxy_add_listener((struct wl_proxy *) zwp_locked_pointer_v1,
(void (**)(void)) listener, data);
}
#define ZWP_LOCKED_POINTER_V1_DESTROY 0
#define ZWP_LOCKED_POINTER_V1_SET_CURSOR_POSITION_HINT 1
#define ZWP_LOCKED_POINTER_V1_SET_REGION 2
/**
* @ingroup iface_zwp_locked_pointer_v1
*/
#define ZWP_LOCKED_POINTER_V1_LOCKED_SINCE_VERSION 1
/**
* @ingroup iface_zwp_locked_pointer_v1
*/
#define ZWP_LOCKED_POINTER_V1_UNLOCKED_SINCE_VERSION 1
/**
* @ingroup iface_zwp_locked_pointer_v1
*/
#define ZWP_LOCKED_POINTER_V1_DESTROY_SINCE_VERSION 1
/**
* @ingroup iface_zwp_locked_pointer_v1
*/
#define ZWP_LOCKED_POINTER_V1_SET_CURSOR_POSITION_HINT_SINCE_VERSION 1
/**
* @ingroup iface_zwp_locked_pointer_v1
*/
#define ZWP_LOCKED_POINTER_V1_SET_REGION_SINCE_VERSION 1
/** @ingroup iface_zwp_locked_pointer_v1 */
static inline void
zwp_locked_pointer_v1_set_user_data(struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1, void *user_data)
{
wl_proxy_set_user_data((struct wl_proxy *) zwp_locked_pointer_v1, user_data);
}
/** @ingroup iface_zwp_locked_pointer_v1 */
static inline void *
zwp_locked_pointer_v1_get_user_data(struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1)
{
return wl_proxy_get_user_data((struct wl_proxy *) zwp_locked_pointer_v1);
}
static inline uint32_t
zwp_locked_pointer_v1_get_version(struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1)
{
return wl_proxy_get_version((struct wl_proxy *) zwp_locked_pointer_v1);
}
/**
* @ingroup iface_zwp_locked_pointer_v1
*
* Destroy the locked pointer object. If applicable, the compositor will
* unlock the pointer.
*/
static inline void
zwp_locked_pointer_v1_destroy(struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1)
{
wl_proxy_marshal_flags((struct wl_proxy *) zwp_locked_pointer_v1,
ZWP_LOCKED_POINTER_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_locked_pointer_v1), WL_MARSHAL_FLAG_DESTROY);
}
/**
* @ingroup iface_zwp_locked_pointer_v1
*
* Set the cursor position hint relative to the top left corner of the
* surface.
*
* If the client is drawing its own cursor, it should update the position
* hint to the position of its own cursor. A compositor may use this
* information to warp the pointer upon unlock in order to avoid pointer
* jumps.
*
* The cursor position hint is double-buffered state, see
* wl_surface.commit.
*/
static inline void
zwp_locked_pointer_v1_set_cursor_position_hint(struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1, wl_fixed_t surface_x, wl_fixed_t surface_y)
{
wl_proxy_marshal_flags((struct wl_proxy *) zwp_locked_pointer_v1,
ZWP_LOCKED_POINTER_V1_SET_CURSOR_POSITION_HINT, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_locked_pointer_v1), 0, surface_x, surface_y);
}
/**
* @ingroup iface_zwp_locked_pointer_v1
*
* Set a new region used to lock the pointer.
*
* The new lock region is double-buffered, see wl_surface.commit.
*
* For details about the lock region, see wp_locked_pointer.
*/
static inline void
zwp_locked_pointer_v1_set_region(struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1, struct wl_region *region)
{
wl_proxy_marshal_flags((struct wl_proxy *) zwp_locked_pointer_v1,
ZWP_LOCKED_POINTER_V1_SET_REGION, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_locked_pointer_v1), 0, region);
}
/**
* @ingroup iface_zwp_confined_pointer_v1
* @struct zwp_confined_pointer_v1_listener
*/
struct zwp_confined_pointer_v1_listener {
/**
* pointer confined
*
* Notification that the pointer confinement of the seat's
* pointer is activated.
*/
void (*confined)(void *data,
struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1);
/**
* pointer unconfined
*
* Notification that the pointer confinement of the seat's
* pointer is no longer active. If this is a oneshot pointer
* confinement (see wp_pointer_constraints.lifetime) this object is
* now defunct and should be destroyed. If this is a persistent
* pointer confinement (see wp_pointer_constraints.lifetime) this
* pointer confinement may again reactivate in the future.
*/
void (*unconfined)(void *data,
struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1);
};
/**
* @ingroup iface_zwp_confined_pointer_v1
*/
static inline int
zwp_confined_pointer_v1_add_listener(struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1,
const struct zwp_confined_pointer_v1_listener *listener, void *data)
{
return wl_proxy_add_listener((struct wl_proxy *) zwp_confined_pointer_v1,
(void (**)(void)) listener, data);
}
#define ZWP_CONFINED_POINTER_V1_DESTROY 0
#define ZWP_CONFINED_POINTER_V1_SET_REGION 1
/**
* @ingroup iface_zwp_confined_pointer_v1
*/
#define ZWP_CONFINED_POINTER_V1_CONFINED_SINCE_VERSION 1
/**
* @ingroup iface_zwp_confined_pointer_v1
*/
#define ZWP_CONFINED_POINTER_V1_UNCONFINED_SINCE_VERSION 1
/**
* @ingroup iface_zwp_confined_pointer_v1
*/
#define ZWP_CONFINED_POINTER_V1_DESTROY_SINCE_VERSION 1
/**
* @ingroup iface_zwp_confined_pointer_v1
*/
#define ZWP_CONFINED_POINTER_V1_SET_REGION_SINCE_VERSION 1
/** @ingroup iface_zwp_confined_pointer_v1 */
static inline void
zwp_confined_pointer_v1_set_user_data(struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1, void *user_data)
{
wl_proxy_set_user_data((struct wl_proxy *) zwp_confined_pointer_v1, user_data);
}
/** @ingroup iface_zwp_confined_pointer_v1 */
static inline void *
zwp_confined_pointer_v1_get_user_data(struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1)
{
return wl_proxy_get_user_data((struct wl_proxy *) zwp_confined_pointer_v1);
}
static inline uint32_t
zwp_confined_pointer_v1_get_version(struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1)
{
return wl_proxy_get_version((struct wl_proxy *) zwp_confined_pointer_v1);
}
/**
* @ingroup iface_zwp_confined_pointer_v1
*
* Destroy the confined pointer object. If applicable, the compositor will
* unconfine the pointer.
*/
static inline void
zwp_confined_pointer_v1_destroy(struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1)
{
wl_proxy_marshal_flags((struct wl_proxy *) zwp_confined_pointer_v1,
ZWP_CONFINED_POINTER_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_confined_pointer_v1), WL_MARSHAL_FLAG_DESTROY);
}
/**
* @ingroup iface_zwp_confined_pointer_v1
*
* Set a new region used to confine the pointer.
*
* The new confine region is double-buffered, see wl_surface.commit.
*
* If the confinement is active when the new confinement region is applied
* and the pointer ends up outside of newly applied region, the pointer may
* warped to a position within the new confinement region. If warped, a
* wl_pointer.motion event will be emitted, but no
* wp_relative_pointer.relative_motion event.
*
* The compositor may also, instead of using the new region, unconfine the
* pointer.
*
* For details about the confine region, see wp_confined_pointer.
*/
static inline void
zwp_confined_pointer_v1_set_region(struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1, struct wl_region *region)
{
wl_proxy_marshal_flags((struct wl_proxy *) zwp_confined_pointer_v1,
ZWP_CONFINED_POINTER_V1_SET_REGION, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_confined_pointer_v1), 0, region);
}
#ifdef __cplusplus
}
#endif
#endif

View File

@ -5,6 +5,9 @@
#define wp_cursor_shape_device_v1_interface z_uhdk_wp_cursor_shape_device_v1_interface #define wp_cursor_shape_device_v1_interface z_uhdk_wp_cursor_shape_device_v1_interface
#define wp_fractional_scale_manager_v1_interface z_uhdk_wp_fractional_scale_manager_v1_interface #define wp_fractional_scale_manager_v1_interface z_uhdk_wp_fractional_scale_manager_v1_interface
#define wp_fractional_scale_v1_interface z_uhdk_wp_fractional_scale_v1_interface #define wp_fractional_scale_v1_interface z_uhdk_wp_fractional_scale_v1_interface
#define zwp_pointer_constraints_v1_interface z_uhdk_zwp_pointer_constraints_v1_interface
#define zwp_locked_pointer_v1_interface z_uhdk_zwp_locked_pointer_v1_interface
#define zwp_confined_pointer_v1_interface z_uhdk_zwp_confined_pointer_v1_interface
#define zwp_tablet_manager_v2_interface z_uhdk_zwp_tablet_manager_v2_interface #define zwp_tablet_manager_v2_interface z_uhdk_zwp_tablet_manager_v2_interface
#define zwp_tablet_seat_v2_interface z_uhdk_zwp_tablet_seat_v2_interface #define zwp_tablet_seat_v2_interface z_uhdk_zwp_tablet_seat_v2_interface
#define zwp_tablet_tool_v2_interface z_uhdk_zwp_tablet_tool_v2_interface #define zwp_tablet_tool_v2_interface z_uhdk_zwp_tablet_tool_v2_interface

View File

@ -0,0 +1,334 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="pointer_constraints_unstable_v1">
<copyright>
Copyright © 2014 Jonas Ådahl
Copyright © 2015 Red Hat Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<description summary="protocol for constraining pointer motions">
This protocol specifies a set of interfaces used for adding constraints to
the motion of a pointer. Possible constraints include confining pointer
motions to a given region, or locking it to its current position.
In order to constrain the pointer, a client must first bind the global
interface "wp_pointer_constraints" which, if a compositor supports pointer
constraints, is exposed by the registry. Using the bound global object, the
client uses the request that corresponds to the type of constraint it wants
to make. See wp_pointer_constraints for more details.
Warning! The protocol described in this file is experimental and backward
incompatible changes may be made. Backward compatible changes may be added
together with the corresponding interface version bump. Backward
incompatible changes are done by bumping the version number in the protocol
and interface names and resetting the interface version. Once the protocol
is to be declared stable, the 'z' prefix and the version number in the
protocol and interface names are removed and the interface version number is
reset.
</description>
<interface name="zwp_pointer_constraints_v1" version="1">
<description summary="constrain the movement of a pointer">
The global interface exposing pointer constraining functionality. It
exposes two requests: lock_pointer for locking the pointer to its
position, and confine_pointer for locking the pointer to a region.
The lock_pointer and confine_pointer requests create the objects
wp_locked_pointer and wp_confined_pointer respectively, and the client can
use these objects to interact with the lock.
For any surface, only one lock or confinement may be active across all
wl_pointer objects of the same seat. If a lock or confinement is requested
when another lock or confinement is active or requested on the same surface
and with any of the wl_pointer objects of the same seat, an
'already_constrained' error will be raised.
</description>
<enum name="error">
<description summary="wp_pointer_constraints error values">
These errors can be emitted in response to wp_pointer_constraints
requests.
</description>
<entry name="already_constrained" value="1"
summary="pointer constraint already requested on that surface"/>
</enum>
<enum name="lifetime">
<description summary="constraint lifetime">
These values represent different lifetime semantics. They are passed
as arguments to the factory requests to specify how the constraint
lifetimes should be managed.
</description>
<entry name="oneshot" value="1">
<description summary="the pointer constraint is defunct once deactivated">
A oneshot pointer constraint will never reactivate once it has been
deactivated. See the corresponding deactivation event
(wp_locked_pointer.unlocked and wp_confined_pointer.unconfined) for
details.
</description>
</entry>
<entry name="persistent" value="2">
<description summary="the pointer constraint may reactivate">
A persistent pointer constraint may again reactivate once it has
been deactivated. See the corresponding deactivation event
(wp_locked_pointer.unlocked and wp_confined_pointer.unconfined) for
details.
</description>
</entry>
</enum>
<request name="destroy" type="destructor">
<description summary="destroy the pointer constraints manager object">
Used by the client to notify the server that it will no longer use this
pointer constraints object.
</description>
</request>
<request name="lock_pointer">
<description summary="lock pointer to a position">
The lock_pointer request lets the client request to disable movements of
the virtual pointer (i.e. the cursor), effectively locking the pointer
to a position. This request may not take effect immediately; in the
future, when the compositor deems implementation-specific constraints
are satisfied, the pointer lock will be activated and the compositor
sends a locked event.
The protocol provides no guarantee that the constraints are ever
satisfied, and does not require the compositor to send an error if the
constraints cannot ever be satisfied. It is thus possible to request a
lock that will never activate.
There may not be another pointer constraint of any kind requested or
active on the surface for any of the wl_pointer objects of the seat of
the passed pointer when requesting a lock. If there is, an error will be
raised. See general pointer lock documentation for more details.
The intersection of the region passed with this request and the input
region of the surface is used to determine where the pointer must be
in order for the lock to activate. It is up to the compositor whether to
warp the pointer or require some kind of user interaction for the lock
to activate. If the region is null the surface input region is used.
A surface may receive pointer focus without the lock being activated.
The request creates a new object wp_locked_pointer which is used to
interact with the lock as well as receive updates about its state. See
the the description of wp_locked_pointer for further information.
Note that while a pointer is locked, the wl_pointer objects of the
corresponding seat will not emit any wl_pointer.motion events, but
relative motion events will still be emitted via wp_relative_pointer
objects of the same seat. wl_pointer.axis and wl_pointer.button events
are unaffected.
</description>
<arg name="id" type="new_id" interface="zwp_locked_pointer_v1"/>
<arg name="surface" type="object" interface="wl_surface"
summary="surface to lock pointer to"/>
<arg name="pointer" type="object" interface="wl_pointer"
summary="the pointer that should be locked"/>
<arg name="region" type="object" interface="wl_region" allow-null="true"
summary="region of surface"/>
<arg name="lifetime" type="uint" enum="lifetime" summary="lock lifetime"/>
</request>
<request name="confine_pointer">
<description summary="confine pointer to a region">
The confine_pointer request lets the client request to confine the
pointer cursor to a given region. This request may not take effect
immediately; in the future, when the compositor deems implementation-
specific constraints are satisfied, the pointer confinement will be
activated and the compositor sends a confined event.
The intersection of the region passed with this request and the input
region of the surface is used to determine where the pointer must be
in order for the confinement to activate. It is up to the compositor
whether to warp the pointer or require some kind of user interaction for
the confinement to activate. If the region is null the surface input
region is used.
The request will create a new object wp_confined_pointer which is used
to interact with the confinement as well as receive updates about its
state. See the the description of wp_confined_pointer for further
information.
</description>
<arg name="id" type="new_id" interface="zwp_confined_pointer_v1"/>
<arg name="surface" type="object" interface="wl_surface"
summary="surface to lock pointer to"/>
<arg name="pointer" type="object" interface="wl_pointer"
summary="the pointer that should be confined"/>
<arg name="region" type="object" interface="wl_region" allow-null="true"
summary="region of surface"/>
<arg name="lifetime" type="uint" enum="lifetime" summary="confinement lifetime"/>
</request>
</interface>
<interface name="zwp_locked_pointer_v1" version="1">
<description summary="receive relative pointer motion events">
The wp_locked_pointer interface represents a locked pointer state.
While the lock of this object is active, the wl_pointer objects of the
associated seat will not emit any wl_pointer.motion events.
This object will send the event 'locked' when the lock is activated.
Whenever the lock is activated, it is guaranteed that the locked surface
will already have received pointer focus and that the pointer will be
within the region passed to the request creating this object.
To unlock the pointer, send the destroy request. This will also destroy
the wp_locked_pointer object.
If the compositor decides to unlock the pointer the unlocked event is
sent. See wp_locked_pointer.unlock for details.
When unlocking, the compositor may warp the cursor position to the set
cursor position hint. If it does, it will not result in any relative
motion events emitted via wp_relative_pointer.
If the surface the lock was requested on is destroyed and the lock is not
yet activated, the wp_locked_pointer object is now defunct and must be
destroyed.
</description>
<request name="destroy" type="destructor">
<description summary="destroy the locked pointer object">
Destroy the locked pointer object. If applicable, the compositor will
unlock the pointer.
</description>
</request>
<request name="set_cursor_position_hint">
<description summary="set the pointer cursor position hint">
Set the cursor position hint relative to the top left corner of the
surface.
If the client is drawing its own cursor, it should update the position
hint to the position of its own cursor. A compositor may use this
information to warp the pointer upon unlock in order to avoid pointer
jumps.
The cursor position hint is double-buffered state, see
wl_surface.commit.
</description>
<arg name="surface_x" type="fixed"
summary="surface-local x coordinate"/>
<arg name="surface_y" type="fixed"
summary="surface-local y coordinate"/>
</request>
<request name="set_region">
<description summary="set a new lock region">
Set a new region used to lock the pointer.
The new lock region is double-buffered, see wl_surface.commit.
For details about the lock region, see wp_locked_pointer.
</description>
<arg name="region" type="object" interface="wl_region" allow-null="true"
summary="region of surface"/>
</request>
<event name="locked">
<description summary="lock activation event">
Notification that the pointer lock of the seat's pointer is activated.
</description>
</event>
<event name="unlocked">
<description summary="lock deactivation event">
Notification that the pointer lock of the seat's pointer is no longer
active. If this is a oneshot pointer lock (see
wp_pointer_constraints.lifetime) this object is now defunct and should
be destroyed. If this is a persistent pointer lock (see
wp_pointer_constraints.lifetime) this pointer lock may again
reactivate in the future.
</description>
</event>
</interface>
<interface name="zwp_confined_pointer_v1" version="1">
<description summary="confined pointer object">
The wp_confined_pointer interface represents a confined pointer state.
This object will send the event 'confined' when the confinement is
activated. Whenever the confinement is activated, it is guaranteed that
the surface the pointer is confined to will already have received pointer
focus and that the pointer will be within the region passed to the request
creating this object. It is up to the compositor to decide whether this
requires some user interaction and if the pointer will warp to within the
passed region if outside.
To unconfine the pointer, send the destroy request. This will also destroy
the wp_confined_pointer object.
If the compositor decides to unconfine the pointer the unconfined event is
sent. The wp_confined_pointer object is at this point defunct and should
be destroyed.
</description>
<request name="destroy" type="destructor">
<description summary="destroy the confined pointer object">
Destroy the confined pointer object. If applicable, the compositor will
unconfine the pointer.
</description>
</request>
<request name="set_region">
<description summary="set a new confine region">
Set a new region used to confine the pointer.
The new confine region is double-buffered, see wl_surface.commit.
If the confinement is active when the new confinement region is applied
and the pointer ends up outside of newly applied region, the pointer may
warped to a position within the new confinement region. If warped, a
wl_pointer.motion event will be emitted, but no
wp_relative_pointer.relative_motion event.
The compositor may also, instead of using the new region, unconfine the
pointer.
For details about the confine region, see wp_confined_pointer.
</description>
<arg name="region" type="object" interface="wl_region" allow-null="true"
summary="region of surface"/>
</request>
<event name="confined">
<description summary="pointer confined">
Notification that the pointer confinement of the seat's pointer is
activated.
</description>
</event>
<event name="unconfined">
<description summary="pointer unconfined">
Notification that the pointer confinement of the seat's pointer is no
longer active. If this is a oneshot pointer confinement (see
wp_pointer_constraints.lifetime) this object is now defunct and should
be destroyed. If this is a persistent pointer confinement (see
wp_pointer_constraints.lifetime) this pointer confinement may again
reactivate in the future.
</description>
</event>
</interface>
</protocol>

View File

@ -9,7 +9,7 @@ per-file digests, and the scanner version.
`wayland/COPYING` and individual file notices. `wayland/COPYING` and individual file notices.
- wayland-protocols 1.45: xdg-shell, xdg-decoration, viewporter, fractional-scale, - wayland-protocols 1.45: xdg-shell, xdg-decoration, viewporter, fractional-scale,
cursor-shape, tablet descriptors, text-input-v3, xdg-foreign-v2, activation, cursor-shape, tablet descriptors, text-input-v3, xdg-foreign-v2, activation,
and toplevel icons. toplevel icons, and pointer-constraints-v1.
License in `wayland-protocols/COPYING` and each XML's copyright element. License in `wayland-protocols/COPYING` and each XML's copyright element.
- plasma-wayland-protocols revision `382dfabda886d3f2f5c067b22e5a22376685ba78`: - plasma-wayland-protocols revision `382dfabda886d3f2f5c067b22e5a22376685ba78`:
KDE appmenu surface association; MIT license in `plasma-wayland-protocols/MIT.txt`. KDE appmenu surface association; MIT license in `plasma-wayland-protocols/MIT.txt`.

View File

@ -30,7 +30,8 @@
"unstable/text-input/text-input-unstable-v3.xml": "protocols/xml/text-input-unstable-v3.xml", "unstable/text-input/text-input-unstable-v3.xml": "protocols/xml/text-input-unstable-v3.xml",
"unstable/xdg-foreign/xdg-foreign-unstable-v2.xml": "protocols/xml/xdg-foreign-unstable-v2.xml", "unstable/xdg-foreign/xdg-foreign-unstable-v2.xml": "protocols/xml/xdg-foreign-unstable-v2.xml",
"staging/xdg-activation/xdg-activation-v1.xml": "protocols/xml/xdg-activation-v1.xml", "staging/xdg-activation/xdg-activation-v1.xml": "protocols/xml/xdg-activation-v1.xml",
"staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml": "protocols/xml/xdg-toplevel-icon-v1.xml" "staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml": "protocols/xml/xdg-toplevel-icon-v1.xml",
"unstable/pointer-constraints/pointer-constraints-unstable-v1.xml": "protocols/xml/pointer-constraints-unstable-v1.xml"
} }
}, },
{ {
@ -158,7 +159,8 @@
"protocols/xml/xdg-toplevel-icon-v1.xml": "791dbfed89280c1b8031689955a03e9b2da55601be3c5854a6198e38cea4978f", "protocols/xml/xdg-toplevel-icon-v1.xml": "791dbfed89280c1b8031689955a03e9b2da55601be3c5854a6198e38cea4978f",
"vendor/xkbcommon/xkbcommon-compat.h": "fb0384a704897c0dcfcc49f021ad38fadbbedc3307d5390f4f0d1019e3d1a4d9", "vendor/xkbcommon/xkbcommon-compat.h": "fb0384a704897c0dcfcc49f021ad38fadbbedc3307d5390f4f0d1019e3d1a4d9",
"protocols/xml/appmenu.xml": "7d0251ee00d3d4bc7ee41e3cd1161beaf68a0c18c4f56f48ff1907a475846022", "protocols/xml/appmenu.xml": "7d0251ee00d3d4bc7ee41e3cd1161beaf68a0c18c4f56f48ff1907a475846022",
"vendor/plasma-wayland-protocols/MIT.txt": "8f25018489d6fe0dec34a352314c38dc146247b7de65735790f4398a92afa84b" "vendor/plasma-wayland-protocols/MIT.txt": "8f25018489d6fe0dec34a352314c38dc146247b7de65735790f4398a92afa84b",
"protocols/xml/pointer-constraints-unstable-v1.xml": "f980fac900ba1dcfbbe97f588fc17b893926bd2b57624563653a1bfe4d035948"
}, },
"generated": { "generated": {
"protocols/generated/appmenu.c": "4705014be761bdc059357f1731e9d68004531b1ec3db1469f4b2f823d0a4bc97", "protocols/generated/appmenu.c": "4705014be761bdc059357f1731e9d68004531b1ec3db1469f4b2f823d0a4bc97",
@ -168,7 +170,9 @@
"protocols/generated/dbus/dbus-arch-deps.h": "87a896df22f7b5e6ec5367cc9b3ed7c77c65b54405a50fd3c7133cd4c6fc3281", "protocols/generated/dbus/dbus-arch-deps.h": "87a896df22f7b5e6ec5367cc9b3ed7c77c65b54405a50fd3c7133cd4c6fc3281",
"protocols/generated/fractional-scale-v1.c": "fb40e729ee05acafe996d1261367424b47722be02dbee65c90b3f4972f259dca", "protocols/generated/fractional-scale-v1.c": "fb40e729ee05acafe996d1261367424b47722be02dbee65c90b3f4972f259dca",
"protocols/generated/fractional-scale-v1.h": "9243e57b2ce11317f6aaa2cd76c0a9f999fb54ced38b880d81891a6ee5dd27df", "protocols/generated/fractional-scale-v1.h": "9243e57b2ce11317f6aaa2cd76c0a9f999fb54ced38b880d81891a6ee5dd27df",
"protocols/generated/private-symbols.h": "a1c6d71c84c40c8ea0d2023ec650f219227c8059009f915497f07f06acd9161e", "protocols/generated/pointer-constraints-unstable-v1.c": "a4227659f61aa504eab8099983f0ea195b46c38a745cbb4572a0e70d001dc109",
"protocols/generated/pointer-constraints-unstable-v1.h": "ccb950e475f81762a0db3d360c3d9745b18e90c55774688f2ee2628a82fae97e",
"protocols/generated/private-symbols.h": "1a660e3638924ae5eff914b489793f4d3a03962b8665282763844e0574fa04fa",
"protocols/generated/tablet-v2.c": "6ce7899f31da919e1f04a8bd44038df5095b58a98b1178f9aa0a84d0835424c0", "protocols/generated/tablet-v2.c": "6ce7899f31da919e1f04a8bd44038df5095b58a98b1178f9aa0a84d0835424c0",
"protocols/generated/tablet-v2.h": "eff5398428ff21523ae6c745d57081f3bd5c18509c4bf5b18de75d89d58d18cd", "protocols/generated/tablet-v2.h": "eff5398428ff21523ae6c745d57081f3bd5c18509c4bf5b18de75d89d58d18cd",
"protocols/generated/text-input-unstable-v3.c": "5de60647b6e122860802d59b547632d4bcf838a443cebeb04429bbb17b5c971b", "protocols/generated/text-input-unstable-v3.c": "5de60647b6e122860802d59b547632d4bcf838a443cebeb04429bbb17b5c971b",

View File

@ -1669,6 +1669,10 @@ uhdk_status z_native_execute(
break; break;
} }
case Z_POINTER: case Z_POINTER:
if (cmd->number == UHDK_POINTER_CONFINED)
return UHDK_STATUS_UNSUPPORTED;
if (w.view.capture == (cmd->number == UHDK_POINTER_CAPTURE))
break;
w.view.capture = cmd->number != 0; w.view.capture = cmd->number != 0;
{ {
z_event e = {.type = UHDK_EVENT_POINTER_MODE_CHANGED, .window = w.handle}; z_event e = {.type = UHDK_EVENT_POINTER_MODE_CHANGED, .window = w.handle};
@ -1677,6 +1681,9 @@ uhdk_status z_native_execute(
z_emit(app, &e); z_emit(app, &e);
} }
break; break;
case Z_FUNCTION_KEYS:
// This policy controls the Windows native window fallback only.
break;
case Z_TEXT_ENABLE: case Z_TEXT_ENABLE:
w.view.textEnabled = cmd->number != 0; w.view.textEnabled = cmd->number != 0;
if (!cmd->number) { if (!cmd->number) {

View File

@ -7,6 +7,7 @@
#include "uhdk.h" #include "uhdk.h"
#include <stddef.h> #include <stddef.h>
#include "edit_keys.h" #include "edit_keys.h"
#include "function_keys.h"
enum { enum {
Z_WINDOW_OPENGL = 1u << 3 Z_WINDOW_OPENGL = 1u << 3
}; };
@ -83,6 +84,7 @@ enum {
Z_GL, Z_GL,
Z_CURSOR, Z_CURSOR,
Z_POINTER, Z_POINTER,
Z_FUNCTION_KEYS,
Z_TEXT_ENABLE, Z_TEXT_ENABLE,
Z_TEXT_STATE, Z_TEXT_STATE,
Z_TEXT_CANCEL, Z_TEXT_CANCEL,

View File

@ -51,7 +51,9 @@ typedef struct Graphics {
uint32_t major, minor; uint32_t major, minor;
} Graphics; } Graphics;
struct Window { struct Window {
BOOL releasing_capture; uhdk_pointer_mode pointer_mode;
uhdk_function_key_policy function_key_policy;
z_function_keys function_keys;
Window *next; Window *next;
HWND hwnd; HWND hwnd;
uhdk_window *handle; uhdk_window *handle;
@ -157,6 +159,47 @@ static void emit(Window *w, uint32_t type) {
e.window = w ? w->handle : NULL; e.window = w ? w->handle : NULL;
z_emit(host.app, &e); z_emit(host.app, &e);
} }
static void pointerModeEvent(Window *w, uhdk_pointer_mode mode, uhdk_cycle_end_reason reason) {
w->pointer_mode = mode;
z_event e = {0};
e.type = UHDK_EVENT_POINTER_MODE_CHANGED;
e.window = w->handle;
e.data.pointer_mode = mode;
e.cycle_end_reason = reason;
z_emit(host.app, &e);
}
static void releasePointer(Window *w, uhdk_cycle_end_reason reason) {
uhdk_pointer_mode previous = w->pointer_mode;
if (previous == UHDK_POINTER_NORMAL)
return;
/* Clear first: ReleaseCapture synchronously sends WM_CAPTURECHANGED. */
w->pointer_mode = UHDK_POINTER_NORMAL;
if (previous == UHDK_POINTER_CONFINED)
ClipCursor(NULL);
if (previous == UHDK_POINTER_CAPTURE && GetCapture() == w->hwnd)
ReleaseCapture();
pointerModeEvent(w, UHDK_POINTER_NORMAL, reason);
}
static BOOL confinementRect(Window *w, RECT *rect) {
if (!GetClientRect(w->hwnd, rect) || rect->right <= 0 || rect->bottom <= 0)
return FALSE;
POINT origin = {0, 0};
if (!ClientToScreen(w->hwnd, &origin))
return FALSE;
OffsetRect(rect, origin.x, origin.y);
return TRUE;
}
static void updateConfinement(Window *w) {
if (w->pointer_mode != UHDK_POINTER_CONFINED)
return;
RECT rect;
if (!IsWindowVisible(w->hwnd) || IsIconic(w->hwnd))
releasePointer(w, UHDK_CYCLE_HIDDEN);
else if (GetFocus() != w->hwnd || GetForegroundWindow() != w->hwnd)
releasePointer(w, UHDK_CYCLE_FOCUS_LOST);
else if (!confinementRect(w, &rect) || !ClipCursor(&rect))
releasePointer(w, UHDK_CYCLE_CAPTURE_LOST);
}
static uint32_t modifiers(void) { static uint32_t modifiers(void) {
uint32_t m = 0; uint32_t m = 0;
if (GetKeyState(VK_SHIFT) & 0x8000) if (GetKeyState(VK_SHIFT) & 0x8000)
@ -496,6 +539,7 @@ static LRESULT CALLBACK windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
case WM_ERASEBKGND: case WM_ERASEBKGND:
return 1; return 1;
case WM_ENTERSIZEMOVE: case WM_ENTERSIZEMOVE:
releasePointer(w, UHDK_CYCLE_CAPTURE_LOST);
w->resizing = TRUE; w->resizing = TRUE;
metrics(w); metrics(w);
break; break;
@ -505,18 +549,28 @@ static LRESULT CALLBACK windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
break; break;
case WM_SIZE: case WM_SIZE:
case WM_SHOWWINDOW: case WM_SHOWWINDOW:
if ((msg == WM_SIZE && wp == SIZE_MINIMIZED) || (msg == WM_SHOWWINDOW && !wp))
releasePointer(w, UHDK_CYCLE_HIDDEN);
updateConfinement(w);
metrics(w); metrics(w);
break; break;
case WM_WINDOWPOSCHANGED:
updateConfinement(w);
break;
case WM_SETFOCUS: case WM_SETFOCUS:
metrics(w); metrics(w);
break; break;
case WM_KILLFOCUS: case WM_KILLFOCUS:
w->high_surrogate = 0; w->high_surrogate = 0;
if (GetCapture() == hwnd) w->function_keys = (z_function_keys){0};
ReleaseCapture(); releasePointer(w, UHDK_CYCLE_FOCUS_LOST);
metrics(w); metrics(w);
break; break;
case WM_ACTIVATEAPP: { case WM_ACTIVATEAPP: {
if (!wp) {
w->function_keys = (z_function_keys){0};
releasePointer(w, UHDK_CYCLE_FOCUS_LOST);
}
z_event e = {0}; z_event e = {0};
e.type = UHDK_EVENT_APP_ACTIVATION; e.type = UHDK_EVENT_APP_ACTIVATION;
e.data.active = !!wp; e.data.active = !!wp;
@ -631,18 +685,12 @@ static LRESULT CALLBACK windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
return 0; return 0;
} }
case WM_CAPTURECHANGED: { case WM_CAPTURECHANGED: {
z_event e = {0}; if (w->pointer_mode == UHDK_POINTER_CAPTURE)
e.type = UHDK_EVENT_POINTER_MODE_CHANGED; releasePointer(w, UHDK_CYCLE_CAPTURE_LOST);
e.window = w->handle;
e.data.pointer_mode = UHDK_POINTER_NORMAL;
e.cycle_end_reason =
w->releasing_capture ? UHDK_CYCLE_CAPTURE_RELEASED : UHDK_CYCLE_CAPTURE_LOST;
z_emit(host.app, &e);
return 0; return 0;
} }
case WM_CANCELMODE: case WM_CANCELMODE:
if (GetCapture() == hwnd) releasePointer(w, UHDK_CYCLE_CAPTURE_LOST);
ReleaseCapture();
break; break;
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
case WM_MOUSEHWHEEL: { case WM_MOUSEHWHEEL: {
@ -673,6 +721,8 @@ static LRESULT CALLBACK windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
BOOL down = msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN; BOOL down = msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN;
uint32_t mods = modifiers(); uint32_t mods = modifiers();
uint32_t key = logicalKey(wp); uint32_t key = logicalKey(wp);
BOOL suppress_default =
z_function_key_suppress(&w->function_keys, w->function_key_policy, key, mods, down);
if (down) { if (down) {
w->suppress_char = FALSE; w->suppress_char = FALSE;
const uhdk_menu_item *item = const uhdk_menu_item *item =
@ -693,6 +743,8 @@ static LRESULT CALLBACK windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
e.data.key.pressed = down; e.data.key.pressed = down;
e.data.key.repeat = down && !!(lp & (1u << 30)); e.data.key.repeat = down && !!(lp & (1u << 30));
z_emit(host.app, &e); z_emit(host.app, &e);
if (suppress_default)
return 0;
if (down && w->text_enabled && !w->composing) { if (down && w->text_enabled && !w->composing) {
uint32_t command = z_edit_key(key, mods); uint32_t command = z_edit_key(key, mods);
if (command) { if (command) {
@ -1523,6 +1575,7 @@ void z_native_destroy(uint32_t kind, void *native) {
w->graphics = NULL; w->graphics = NULL;
} else if (kind == Z_KIND_WINDOW) { } else if (kind == Z_KIND_WINDOW) {
Window *w = native; Window *w = native;
releasePointer(w, UHDK_CYCLE_CANCELLED);
Window **link = &host.windows; Window **link = &host.windows;
while (*link && *link != w) while (*link && *link != w)
link = &(*link)->next; link = &(*link)->next;
@ -1781,6 +1834,8 @@ uhdk_status z_native_execute(
} }
case Z_STATE: { case Z_STATE: {
BOOL minimize = cmd->number == UHDK_WINDOW_MINIMIZED; BOOL minimize = cmd->number == UHDK_WINDOW_MINIMIZED;
if (minimize)
releasePointer(w, UHDK_CYCLE_HIDDEN);
BOOL full = cmd->number == UHDK_WINDOW_FULLSCREEN || (minimize && w->fullscreen); BOOL full = cmd->number == UHDK_WINDOW_FULLSCREEN || (minimize && w->fullscreen);
if (full && !w->fullscreen) { if (full && !w->fullscreen) {
if (IsIconic(w->hwnd)) if (IsIconic(w->hwnd))
@ -1822,6 +1877,8 @@ uhdk_status z_native_execute(
break; break;
} }
case Z_VISIBLE: case Z_VISIBLE:
if (!cmd->number)
releasePointer(w, UHDK_CYCLE_HIDDEN);
ShowWindow(w->hwnd, cmd->number ? SW_SHOWNOACTIVATE : SW_HIDE); ShowWindow(w->hwnd, cmd->number ? SW_SHOWNOACTIVATE : SW_HIDE);
metrics(w); metrics(w);
break; break;
@ -1893,24 +1950,31 @@ uhdk_status z_native_execute(
break; break;
} }
case Z_POINTER: { case Z_POINTER: {
if (w->pointer_mode == cmd->number)
break;
if (cmd->number == UHDK_POINTER_CONFINED) {
RECT rect;
POINT point;
if (GetFocus() != w->hwnd || GetForegroundWindow() != w->hwnd ||
!IsWindowVisible(w->hwnd) || IsIconic(w->hwnd) || !confinementRect(w, &rect) ||
!GetCursorPos(&point) || !PtInRect(&rect, point))
return UHDK_STATUS_UNAVAILABLE;
if (!ClipCursor(&rect))
return osError();
}
if (cmd->number == UHDK_POINTER_CAPTURE) { if (cmd->number == UHDK_POINTER_CAPTURE) {
SetCapture(w->hwnd); SetCapture(w->hwnd);
if (GetCapture() != w->hwnd) if (GetCapture() != w->hwnd)
return UHDK_STATUS_OS_ERROR; return UHDK_STATUS_OS_ERROR;
} else if (GetCapture() == w->hwnd) { }
w->releasing_capture = TRUE; releasePointer(w, UHDK_CYCLE_CAPTURE_RELEASED);
ReleaseCapture(); if (cmd->number != UHDK_POINTER_NORMAL)
w->releasing_capture = FALSE; pointerModeEvent(w, (uint32_t)cmd->number, UHDK_CYCLE_CAPTURE_RELEASED);
break; break;
} }
z_event e = {0}; case Z_FUNCTION_KEYS:
e.type = UHDK_EVENT_POINTER_MODE_CHANGED; w->function_key_policy = (uhdk_function_key_policy)cmd->number;
e.window = w->handle;
e.data.pointer_mode = (uint32_t)cmd->number;
e.cycle_end_reason = UHDK_CYCLE_CAPTURE_RELEASED;
z_emit(host.app, &e);
break; break;
}
case Z_TEXT_ENABLE: case Z_TEXT_ENABLE:
w->text_enabled = !!cmd->number; w->text_enabled = !!cmd->number;
ImmAssociateContextEx(w->hwnd, NULL, w->text_enabled ? IACE_DEFAULT : 0); ImmAssociateContextEx(w->hwnd, NULL, w->text_enabled ? IACE_DEFAULT : 0);