core: wayland: use Linux object instead of Wayland obj in listeners

This commit is contained in:
Joshua Holmes 2024-11-16 12:35:38 -08:00 committed by Emi Gutekanst
parent fbf274ccbe
commit f90fb1170b

View file

@ -113,7 +113,7 @@ pub fn init(
const registry = c.wl_display_get_registry(wl.display) orelse return error.FailedToGetDisplayRegistry; const registry = c.wl_display_get_registry(wl.display) orelse return error.FailedToGetDisplayRegistry;
// TODO: handle error return value here // TODO: handle error return value here
_ = c.wl_registry_add_listener(registry, &registry_listener.listener, wl); _ = c.wl_registry_add_listener(registry, &registry_listener.listener, linux);
//Round trip to get all the registry objects //Round trip to get all the registry objects
_ = wl.libwaylandclient.wl_display_roundtrip(wl.display); _ = wl.libwaylandclient.wl_display_roundtrip(wl.display);
@ -148,10 +148,10 @@ pub fn init(
const toplevel = c.xdg_surface_get_toplevel(xdg_surface) orelse return error.UnableToGetXdgTopLevel; const toplevel = c.xdg_surface_get_toplevel(xdg_surface) orelse return error.UnableToGetXdgTopLevel;
// TODO: handle this return value // TODO: handle this return value
_ = c.xdg_surface_add_listener(xdg_surface, &xdg_surface_listener.listener, wl); _ = c.xdg_surface_add_listener(xdg_surface, &xdg_surface_listener.listener, linux);
// TODO: handle this return value // TODO: handle this return value
_ = c.xdg_toplevel_add_listener(toplevel, &xdg_toplevel_listener.listener, wl); _ = c.xdg_toplevel_add_listener(toplevel, &xdg_toplevel_listener.listener, linux);
// Commit changes to surface // Commit changes to surface
c.wl_surface_commit(wl.surface); c.wl_surface_commit(wl.surface);
@ -317,8 +317,9 @@ const KeyModInd = struct {
}; };
const registry_listener = struct { const registry_listener = struct {
fn registryHandleGlobal(wl: *Wayland, registry: ?*c.struct_wl_registry, name: u32, interface_ptr: [*:0]const u8, version: u32) callconv(.C) void { fn registryHandleGlobal(linux: *Linux, registry: ?*c.struct_wl_registry, name: u32, interface_ptr: [*:0]const u8, version: u32) callconv(.C) void {
const interface = std.mem.span(interface_ptr); const interface = std.mem.span(interface_ptr);
const wl = &linux.backend.wayland;
if (std.mem.eql(u8, "wl_compositor", interface)) { if (std.mem.eql(u8, "wl_compositor", interface)) {
wl.interfaces.wl_compositor = @ptrCast(c.wl_registry_bind( wl.interfaces.wl_compositor = @ptrCast(c.wl_registry_bind(
@ -364,7 +365,7 @@ const registry_listener = struct {
) orelse @panic("uh idk how to proceed")); ) orelse @panic("uh idk how to proceed"));
// TODO: handle return value // TODO: handle return value
_ = c.xdg_wm_base_add_listener(wl.interfaces.xdg_wm_base, &xdg_wm_base_listener.listener, wl); _ = c.xdg_wm_base_add_listener(wl.interfaces.xdg_wm_base, &xdg_wm_base_listener.listener, linux);
} else if (std.mem.eql(u8, "zxdg_decoration_manager_v1", interface)) { } else if (std.mem.eql(u8, "zxdg_decoration_manager_v1", interface)) {
wl.interfaces.zxdg_decoration_manager_v1 = @ptrCast(c.wl_registry_bind( wl.interfaces.zxdg_decoration_manager_v1 = @ptrCast(c.wl_registry_bind(
registry, registry,
@ -381,12 +382,12 @@ const registry_listener = struct {
) orelse @panic("uh idk how to proceed")); ) orelse @panic("uh idk how to proceed"));
// TODO: handle return value // TODO: handle return value
_ = c.wl_seat_add_listener(wl.interfaces.wl_seat, &seat_listener.listener, wl); _ = c.wl_seat_add_listener(wl.interfaces.wl_seat, &seat_listener.listener, linux);
} }
} }
fn registryHandleGlobalRemove(wl: *Wayland, registry: ?*c.struct_wl_registry, name: u32) callconv(.C) void { fn registryHandleGlobalRemove(linux: *Linux, registry: ?*c.struct_wl_registry, name: u32) callconv(.C) void {
_ = wl; _ = linux;
_ = registry; _ = registry;
_ = name; _ = name;
} }
@ -400,8 +401,9 @@ const registry_listener = struct {
}; };
const keyboard_listener = struct { const keyboard_listener = struct {
fn keyboardHandleKeymap(wl: *Wayland, keyboard: ?*c.struct_wl_keyboard, format: u32, fd: i32, keymap_size: u32) callconv(.C) void { fn keyboardHandleKeymap(linux: *Linux, keyboard: ?*c.struct_wl_keyboard, format: u32, fd: i32, keymap_size: u32) callconv(.C) void {
_ = keyboard; _ = keyboard;
const wl = &linux.backend.wayland;
if (format != c.WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { if (format != c.WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
@panic("TODO"); @panic("TODO");
@ -456,27 +458,30 @@ const keyboard_listener = struct {
wl.modifier_indices.num_lock_index = wl.libxkbcommon.xkb_keymap_mod_get_index(keymap, "Mod2"); wl.modifier_indices.num_lock_index = wl.libxkbcommon.xkb_keymap_mod_get_index(keymap, "Mod2");
} }
fn keyboardHandleEnter(wl: *Wayland, keyboard: ?*c.struct_wl_keyboard, serial: u32, surface: ?*c.struct_wl_surface, keys: [*c]c.struct_wl_array) callconv(.C) void { fn keyboardHandleEnter(linux: *Linux, keyboard: ?*c.struct_wl_keyboard, serial: u32, surface: ?*c.struct_wl_surface, keys: [*c]c.struct_wl_array) callconv(.C) void {
_ = keyboard; _ = keyboard;
_ = serial; _ = serial;
_ = surface; _ = surface;
_ = keys; _ = keys;
const wl = &linux.backend.wayland;
wl.state.pushEvent(.focus_gained); wl.state.pushEvent(.focus_gained);
} }
fn keyboardHandleLeave(wl: *Wayland, keyboard: ?*c.struct_wl_keyboard, serial: u32, surface: ?*c.struct_wl_surface) callconv(.C) void { fn keyboardHandleLeave(linux: *Linux, keyboard: ?*c.struct_wl_keyboard, serial: u32, surface: ?*c.struct_wl_surface) callconv(.C) void {
_ = keyboard; _ = keyboard;
_ = serial; _ = serial;
_ = surface; _ = surface;
const wl = &linux.backend.wayland;
wl.state.pushEvent(.focus_lost); wl.state.pushEvent(.focus_lost);
} }
fn keyboardHandleKey(wl: *Wayland, keyboard: ?*c.struct_wl_keyboard, serial: u32, time: u32, scancode: u32, state: u32) callconv(.C) void { fn keyboardHandleKey(linux: *Linux, keyboard: ?*c.struct_wl_keyboard, serial: u32, time: u32, scancode: u32, state: u32) callconv(.C) void {
_ = keyboard; _ = keyboard;
_ = serial; _ = serial;
_ = time; _ = time;
var wl = &linux.backend.wayland;
const key = toMachKey(scancode); const key = toMachKey(scancode);
const pressed = state == 1; const pressed = state == 1;
@ -509,9 +514,10 @@ const keyboard_listener = struct {
} }
} }
fn keyboardHandleModifiers(wl: *Wayland, keyboard: ?*c.struct_wl_keyboard, serial: u32, mods_depressed: u32, mods_latched: u32, mods_locked: u32, group: u32) callconv(.C) void { fn keyboardHandleModifiers(linux: *Linux, keyboard: ?*c.struct_wl_keyboard, serial: u32, mods_depressed: u32, mods_latched: u32, mods_locked: u32, group: u32) callconv(.C) void {
_ = keyboard; _ = keyboard;
_ = serial; _ = serial;
var wl = &linux.backend.wayland;
if (wl.keymap == null) if (wl.keymap == null)
return; return;
@ -544,8 +550,8 @@ const keyboard_listener = struct {
} }
} }
fn keyboardHandleRepeatInfo(wl: *Wayland, keyboard: ?*c.struct_wl_keyboard, rate: i32, delay: i32) callconv(.C) void { fn keyboardHandleRepeatInfo(linux: *Linux, keyboard: ?*c.struct_wl_keyboard, rate: i32, delay: i32) callconv(.C) void {
_ = wl; _ = linux;
_ = keyboard; _ = keyboard;
_ = rate; _ = rate;
_ = delay; _ = delay;
@ -562,72 +568,73 @@ const keyboard_listener = struct {
}; };
const pointer_listener = struct { const pointer_listener = struct {
fn handlePointerAxis(wl: *Wayland, pointer: ?*c.struct_wl_pointer, time: u32, axis: u32, value: c.wl_fixed_t) callconv(.C) void { fn handlePointerAxis(linux: *Linux, pointer: ?*c.struct_wl_pointer, time: u32, axis: u32, value: c.wl_fixed_t) callconv(.C) void {
_ = wl; _ = linux;
_ = pointer; _ = pointer;
_ = time; _ = time;
_ = axis; _ = axis;
_ = value; _ = value;
} }
fn handlePointerFrame(wl: *Wayland, pointer: ?*c.struct_wl_pointer) callconv(.C) void { fn handlePointerFrame(linux: *Linux, pointer: ?*c.struct_wl_pointer) callconv(.C) void {
_ = wl; _ = linux;
_ = pointer; _ = pointer;
} }
fn handlePointerAxisSource(wl: *Wayland, pointer: ?*c.struct_wl_pointer, axis_source: u32) callconv(.C) void { fn handlePointerAxisSource(linux: *Linux, pointer: ?*c.struct_wl_pointer, axis_source: u32) callconv(.C) void {
_ = wl; _ = linux;
_ = pointer; _ = pointer;
_ = axis_source; _ = axis_source;
} }
fn handlePointerAxisStop(wl: *Wayland, pointer: ?*c.struct_wl_pointer, time: u32, axis: u32) callconv(.C) void { fn handlePointerAxisStop(linux: *Linux, pointer: ?*c.struct_wl_pointer, time: u32, axis: u32) callconv(.C) void {
_ = wl; _ = linux;
_ = pointer; _ = pointer;
_ = time; _ = time;
_ = axis; _ = axis;
} }
fn handlePointerAxisDiscrete(wl: *Wayland, pointer: ?*c.struct_wl_pointer, axis: u32, discrete: i32) callconv(.C) void { fn handlePointerAxisDiscrete(linux: *Linux, pointer: ?*c.struct_wl_pointer, axis: u32, discrete: i32) callconv(.C) void {
_ = wl; _ = linux;
_ = pointer; _ = pointer;
_ = axis; _ = axis;
_ = discrete; _ = discrete;
} }
fn handlePointerAxisValue120(wl: *Wayland, pointer: ?*c.struct_wl_pointer, axis: u32, value_120: i32) callconv(.C) void { fn handlePointerAxisValue120(linux: *Linux, pointer: ?*c.struct_wl_pointer, axis: u32, value_120: i32) callconv(.C) void {
_ = wl; _ = linux;
_ = pointer; _ = pointer;
_ = axis; _ = axis;
_ = value_120; _ = value_120;
} }
fn handlePointerAxisRelativeDirection(wl: *Wayland, pointer: ?*c.struct_wl_pointer, axis: u32, direction: u32) callconv(.C) void { fn handlePointerAxisRelativeDirection(linux: *Linux, pointer: ?*c.struct_wl_pointer, axis: u32, direction: u32) callconv(.C) void {
_ = wl; _ = linux;
_ = pointer; _ = pointer;
_ = axis; _ = axis;
_ = direction; _ = direction;
} }
fn handlePointerEnter(wl: *Wayland, pointer: ?*c.struct_wl_pointer, serial: u32, surface: ?*c.struct_wl_surface, fixed_x: c.wl_fixed_t, fixed_y: c.wl_fixed_t) callconv(.C) void { fn handlePointerEnter(linux: *Linux, pointer: ?*c.struct_wl_pointer, serial: u32, surface: ?*c.struct_wl_surface, fixed_x: c.wl_fixed_t, fixed_y: c.wl_fixed_t) callconv(.C) void {
_ = fixed_x; _ = fixed_x;
_ = fixed_y; _ = fixed_y;
_ = wl; _ = linux;
_ = pointer; _ = pointer;
_ = serial; _ = serial;
_ = surface; _ = surface;
} }
fn handlePointerLeave(wl: *Wayland, pointer: ?*c.struct_wl_pointer, serial: u32, surface: ?*c.struct_wl_surface) callconv(.C) void { fn handlePointerLeave(linux: *Linux, pointer: ?*c.struct_wl_pointer, serial: u32, surface: ?*c.struct_wl_surface) callconv(.C) void {
_ = wl; _ = linux;
_ = pointer; _ = pointer;
_ = serial; _ = serial;
_ = surface; _ = surface;
} }
fn handlePointerMotion(wl: *Wayland, pointer: ?*c.struct_wl_pointer, serial: u32, fixed_x: c.wl_fixed_t, fixed_y: c.wl_fixed_t) callconv(.C) void { fn handlePointerMotion(linux: *Linux, pointer: ?*c.struct_wl_pointer, serial: u32, fixed_x: c.wl_fixed_t, fixed_y: c.wl_fixed_t) callconv(.C) void {
_ = pointer; _ = pointer;
_ = serial; _ = serial;
var wl = &linux.backend.wayland;
const x = c.wl_fixed_to_double(fixed_x); const x = c.wl_fixed_to_double(fixed_x);
const y = c.wl_fixed_to_double(fixed_y); const y = c.wl_fixed_to_double(fixed_y);
@ -636,10 +643,11 @@ const pointer_listener = struct {
wl.input_state.mouse_position = .{ .x = x, .y = y }; wl.input_state.mouse_position = .{ .x = x, .y = y };
} }
fn handlePointerButton(wl: *Wayland, pointer: ?*c.struct_wl_pointer, serial: u32, time: u32, button: u32, state: u32) callconv(.C) void { fn handlePointerButton(linux: *Linux, pointer: ?*c.struct_wl_pointer, serial: u32, time: u32, button: u32, state: u32) callconv(.C) void {
_ = pointer; _ = pointer;
_ = serial; _ = serial;
_ = time; _ = time;
var wl = &linux.backend.wayland;
const mouse_button: Core.MouseButton = @enumFromInt(button - c.BTN_LEFT); const mouse_button: Core.MouseButton = @enumFromInt(button - c.BTN_LEFT);
const pressed = state == c.WL_POINTER_BUTTON_STATE_PRESSED; const pressed = state == c.WL_POINTER_BUTTON_STATE_PRESSED;
@ -677,18 +685,20 @@ const pointer_listener = struct {
}; };
const seat_listener = struct { const seat_listener = struct {
fn seatHandleName(wl: *Wayland, seat: ?*c.struct_wl_seat, name_ptr: [*:0]const u8) callconv(.C) void { fn seatHandleName(linux: *Linux, seat: ?*c.struct_wl_seat, name_ptr: [*:0]const u8) callconv(.C) void {
_ = wl; _ = linux;
_ = seat; _ = seat;
_ = name_ptr; _ = name_ptr;
} }
fn seatHandleCapabilities(wl: *Wayland, seat: ?*c.struct_wl_seat, caps: c.wl_seat_capability) callconv(.C) void { fn seatHandleCapabilities(linux: *Linux, seat: ?*c.struct_wl_seat, caps: c.wl_seat_capability) callconv(.C) void {
const wl = &linux.backend.wayland;
if ((caps & c.WL_SEAT_CAPABILITY_KEYBOARD) != 0) { if ((caps & c.WL_SEAT_CAPABILITY_KEYBOARD) != 0) {
wl.keyboard = c.wl_seat_get_keyboard(seat); wl.keyboard = c.wl_seat_get_keyboard(seat);
// TODO: handle return value // TODO: handle return value
_ = c.wl_keyboard_add_listener(wl.keyboard, &keyboard_listener.listener, wl); _ = c.wl_keyboard_add_listener(wl.keyboard, &keyboard_listener.listener, linux);
} }
if ((caps & c.WL_SEAT_CAPABILITY_TOUCH) != 0) { if ((caps & c.WL_SEAT_CAPABILITY_TOUCH) != 0) {
@ -699,7 +709,7 @@ const seat_listener = struct {
wl.pointer = c.wl_seat_get_pointer(seat); wl.pointer = c.wl_seat_get_pointer(seat);
// TODO: handle return value // TODO: handle return value
_ = c.wl_pointer_add_listener(wl.pointer, &pointer_listener.listener, wl); _ = c.wl_pointer_add_listener(wl.pointer, &pointer_listener.listener, linux);
} }
// Delete keyboard if its no longer in the seat // Delete keyboard if its no longer in the seat
@ -725,8 +735,8 @@ const seat_listener = struct {
}; };
const xdg_wm_base_listener = struct { const xdg_wm_base_listener = struct {
fn wmBaseHandlePing(wl: *Wayland, wm_base: ?*c.struct_xdg_wm_base, serial: u32) callconv(.C) void { fn wmBaseHandlePing(linux: *Linux, wm_base: ?*c.struct_xdg_wm_base, serial: u32) callconv(.C) void {
_ = wl; _ = linux;
c.xdg_wm_base_pong(wm_base, serial); c.xdg_wm_base_pong(wm_base, serial);
} }
@ -734,8 +744,9 @@ const xdg_wm_base_listener = struct {
}; };
const xdg_surface_listener = struct { const xdg_surface_listener = struct {
fn xdgSurfaceHandleConfigure(wl: *Wayland, xdg_surface: ?*c.struct_xdg_surface, serial: u32) callconv(.C) void { fn xdgSurfaceHandleConfigure(linux: *Linux, xdg_surface: ?*c.struct_xdg_surface, serial: u32) callconv(.C) void {
c.xdg_surface_ack_configure(xdg_surface, serial); c.xdg_surface_ack_configure(xdg_surface, serial);
var wl = &linux.backend.wayland;
if (wl.configured) { if (wl.configured) {
c.wl_surface_commit(wl.surface); c.wl_surface_commit(wl.surface);
@ -750,14 +761,15 @@ const xdg_surface_listener = struct {
}; };
const xdg_toplevel_listener = struct { const xdg_toplevel_listener = struct {
fn xdgToplevelHandleClose(wl: *Wayland, toplevel: ?*c.struct_xdg_toplevel) callconv(.C) void { fn xdgToplevelHandleClose(linux: *Linux, toplevel: ?*c.struct_xdg_toplevel) callconv(.C) void {
_ = wl; _ = linux;
_ = toplevel; _ = toplevel;
} }
fn xdgToplevelHandleConfigure(wl: *Wayland, toplevel: ?*c.struct_xdg_toplevel, width: i32, height: i32, states: [*c]c.struct_wl_array) callconv(.C) void { fn xdgToplevelHandleConfigure(linux: *Linux, toplevel: ?*c.struct_xdg_toplevel, width: i32, height: i32, states: [*c]c.struct_wl_array) callconv(.C) void {
_ = toplevel; _ = toplevel;
_ = states; _ = states;
const wl = &linux.backend.wayland;
if (width > 0 and height > 0) { if (width > 0 and height > 0) {
wl.size.* = .{ .width = @intCast(width), .height = @intCast(height) }; wl.size.* = .{ .width = @intCast(width), .height = @intCast(height) };