From e01a150f6d53108f8dad29f7a4e4a275b616c351 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Tue, 24 Mar 2020 19:40:47 +0100 Subject: [PATCH] Get rid of [*c] pointers --- src/cursor.zig | 24 ++++++++++++------------ src/keyboard.zig | 8 ++++---- src/output.zig | 8 +++++--- src/seat.zig | 4 ++-- src/server.zig | 8 ++++---- src/view.zig | 16 ++++++++-------- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/cursor.zig b/src/cursor.zig index 10bd4bc..f5becb7 100644 --- a/src/cursor.zig +++ b/src/cursor.zig @@ -218,10 +218,10 @@ pub const Cursor = struct { } } - fn handle_motion(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_motion(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is forwarded by the cursor when a pointer emits a _relative_ // pointer motion event (i.e. a delta) - var cursor = @fieldParentPtr(Cursor, "listen_motion", listener); + var cursor = @fieldParentPtr(Cursor, "listen_motion", listener.?); var event = @ptrCast( *c.wlr_event_pointer_motion, @alignCast(@alignOf(*c.wlr_event_pointer_motion), data), @@ -235,14 +235,14 @@ pub const Cursor = struct { cursor.process_motion(event.time_msec); } - fn handle_motion_absolute(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_motion_absolute(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is forwarded by the cursor when a pointer emits an _absolute_ // motion event, from 0..1 on each axis. This happens, for example, when // wlroots is running under a Wayland window rather than KMS+DRM, and you // move the mouse over the window. You could enter the window from any edge, // so we have to warp the mouse there. There is also some hardware which // emits these events. - var cursor = @fieldParentPtr(Cursor, "listen_motion_absolute", listener); + var cursor = @fieldParentPtr(Cursor, "listen_motion_absolute", listener.?); var event = @ptrCast( *c.wlr_event_pointer_motion_absolute, @alignCast(@alignOf(*c.wlr_event_pointer_motion_absolute), data), @@ -251,10 +251,10 @@ pub const Cursor = struct { cursor.process_motion(event.time_msec); } - fn handle_button(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_button(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is forwarded by the cursor when a pointer emits a button // event. - var cursor = @fieldParentPtr(Cursor, "listen_button", listener); + var cursor = @fieldParentPtr(Cursor, "listen_button", listener.?); var event = @ptrCast( *c.wlr_event_pointer_button, @alignCast(@alignOf(*c.wlr_event_pointer_button), data), @@ -290,10 +290,10 @@ pub const Cursor = struct { } } - fn handle_axis(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_axis(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is forwarded by the cursor when a pointer emits an axis event, // for example when you move the scroll wheel. - var cursor = @fieldParentPtr(Cursor, "listen_axis", listener); + var cursor = @fieldParentPtr(Cursor, "listen_axis", listener.?); var event = @ptrCast( *c.wlr_event_pointer_axis, @alignCast(@alignOf(*c.wlr_event_pointer_axis), data), @@ -310,19 +310,19 @@ pub const Cursor = struct { ); } - fn handle_frame(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_frame(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is forwarded by the cursor when a pointer emits an frame // event. Frame events are sent after regular pointer events to group // multiple events together. For instance, two axis events may happen at the // same time, in which case a frame event won't be sent in between. - var cursor = @fieldParentPtr(Cursor, "listen_frame", listener); + var cursor = @fieldParentPtr(Cursor, "listen_frame", listener.?); // Notify the client with pointer focus of the frame event. c.wlr_seat_pointer_notify_frame(cursor.seat.wlr_seat); } - fn handle_request_set_cursor(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_request_set_cursor(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is rasied by the seat when a client provides a cursor image - var cursor = @fieldParentPtr(Cursor, "listen_request_set_cursor", listener); + var cursor = @fieldParentPtr(Cursor, "listen_request_set_cursor", listener.?); var event = @ptrCast( *c.wlr_seat_pointer_request_set_cursor_event, @alignCast(@alignOf(*c.wlr_seat_pointer_request_set_cursor_event), data), diff --git a/src/keyboard.zig b/src/keyboard.zig index 0077c6e..1a86a02 100644 --- a/src/keyboard.zig +++ b/src/keyboard.zig @@ -48,10 +48,10 @@ pub const Keyboard = struct { c.wl_signal_add(&keyboard_device.*.events.key, &self.listen_key); } - fn handle_modifiers(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_modifiers(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is raised when a modifier key, such as shift or alt, is // pressed. We simply communicate this to the client. */ - var keyboard = @fieldParentPtr(Keyboard, "listen_modifiers", listener); + var keyboard = @fieldParentPtr(Keyboard, "listen_modifiers", listener.?); // A seat can only have one keyboard, but this is a limitation of the // Wayland protocol - not wlroots. We assign all connected keyboards to the @@ -63,9 +63,9 @@ pub const Keyboard = struct { c.wlr_seat_keyboard_notify_modifiers(keyboard.seat.wlr_seat, &keyboard.*.device.*.unnamed_37.keyboard.*.modifiers); } - fn handle_key(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_key(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is raised when a key is pressed or released. - const keyboard = @fieldParentPtr(Keyboard, "listen_key", listener); + const keyboard = @fieldParentPtr(Keyboard, "listen_key", listener.?); const event = @ptrCast( *c.wlr_event_keyboard_key, @alignCast(@alignOf(*c.wlr_event_keyboard_key), data), diff --git a/src/output.zig b/src/output.zig index 9d13334..21cc4c6 100644 --- a/src/output.zig +++ b/src/output.zig @@ -52,10 +52,10 @@ pub const Output = struct { c.wlr_output_create_global(wlr_output); } - fn handle_frame(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_frame(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This function is called every time an output is ready to display a frame, // generally at the output's refresh rate (e.g. 60Hz). - var output = @fieldParentPtr(Output, "listen_frame", listener); + var output = @fieldParentPtr(Output, "listen_frame", listener.?); var renderer = output.server.wlr_renderer; var now: c.struct_timespec = undefined; @@ -110,7 +110,9 @@ pub const Output = struct { _ = c.wlr_output_commit(output.*.wlr_output); } - fn render_surface(surface: [*c]c.wlr_surface, sx: c_int, sy: c_int, data: ?*c_void) callconv(.C) void { + fn render_surface(opt_surface: ?*c.wlr_surface, sx: c_int, sy: c_int, data: ?*c_void) callconv(.C) void { + // wlroots says this will never be null + var surface = opt_surface.?; // This function is called for every surface that needs to be rendered. var rdata = @ptrCast(*RenderData, @alignCast(@alignOf(RenderData), data)); var view = rdata.*.view; diff --git a/src/seat.zig b/src/seat.zig index df54684..f589b2f 100644 --- a/src/seat.zig +++ b/src/seat.zig @@ -60,9 +60,9 @@ pub const Seat = struct { c.wlr_cursor_attach_input_device(self.cursor.wlr_cursor, device); } - fn handle_new_input(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_new_input(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is raised by the backend when a new input device becomes available. - var seat = @fieldParentPtr(Seat, "listen_new_input", listener); + var seat = @fieldParentPtr(Seat, "listen_new_input", listener.?); var device = @ptrCast(*c.wlr_input_device, @alignCast(@alignOf(*c.wlr_input_device), data)); switch (device.*.type) { diff --git a/src/server.zig b/src/server.zig index 7cdedff..0703e78 100644 --- a/src/server.zig +++ b/src/server.zig @@ -143,8 +143,8 @@ pub const Server = struct { return true; } - fn handle_new_output(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { - var server = @fieldParentPtr(Server, "listen_new_output", listener); + fn handle_new_output(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { + var server = @fieldParentPtr(Server, "listen_new_output", listener.?); var wlr_output = @ptrCast(*c.wlr_output, @alignCast(@alignOf(*c.wlr_output), data)); // TODO: Handle failure @@ -153,10 +153,10 @@ pub const Server = struct { server.outputs.append(node); } - fn handle_new_xdg_surface(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_new_xdg_surface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // This event is raised when wlr_xdg_shell receives a new xdg surface from a // client, either a toplevel (application window) or popup. - var server = @fieldParentPtr(Server, "listen_new_xdg_surface", listener); + var server = @fieldParentPtr(Server, "listen_new_xdg_surface", listener.?); var wlr_xdg_surface = @ptrCast(*c.wlr_xdg_surface, @alignCast(@alignOf(*c.wlr_xdg_surface), data)); if (wlr_xdg_surface.role != c.enum_wlr_xdg_surface_role.WLR_XDG_SURFACE_ROLE_TOPLEVEL) { diff --git a/src/view.zig b/src/view.zig index 39c9306..e440379 100644 --- a/src/view.zig +++ b/src/view.zig @@ -39,20 +39,20 @@ pub const View = struct { // c.wl_signal_add(&toplevel.*.events.request_resize, &view.*.request_resize); } - fn handle_map(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + fn handle_map(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // Called when the surface is mapped, or ready to display on-screen. - var view = @fieldParentPtr(View, "listen_map", listener); + var view = @fieldParentPtr(View, "listen_map", listener.?); view.mapped = true; view.focus(view.wlr_xdg_surface.surface); } - fn handle_unmap(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { - var view = @fieldParentPtr(View, "listen_unmap", listener); + fn handle_unmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { + var view = @fieldParentPtr(View, "listen_unmap", listener.?); view.*.mapped = false; } - fn handle_destroy(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { - var view = @fieldParentPtr(View, "listen_destroy", listener); + fn handle_destroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { + var view = @fieldParentPtr(View, "listen_destroy", listener.?); var server = view.server; var it = server.views.first; @@ -66,11 +66,11 @@ pub const View = struct { server.views.destroyNode(target, server.allocator); } - // fn xdg_toplevel_request_move(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + // fn xdg_toplevel_request_move(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // // ignore for now // } - // fn xdg_toplevel_request_resize(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { + // fn xdg_toplevel_request_resize(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { // // ignore for now // }