Remove superfluous .*.
I may be be slowly getting the hang of this language.
This commit is contained in:
		| @ -100,11 +100,11 @@ pub const Cursor = struct { | ||||
|         // can choose how we want to process them, forwarding them to clients and | ||||
|         // moving the cursor around. See following post for more detail: | ||||
|         // https://drewdevault.com/2018/07/17/Input-handling-in-wlroots.html | ||||
|         c.wl_signal_add(&self.wlr_cursor.*.events.motion, &self.listen_motion); | ||||
|         c.wl_signal_add(&self.wlr_cursor.*.events.motion_absolute, &self.listen_motion_absolute); | ||||
|         c.wl_signal_add(&self.wlr_cursor.*.events.button, &self.listen_button); | ||||
|         c.wl_signal_add(&self.wlr_cursor.*.events.axis, &self.listen_axis); | ||||
|         c.wl_signal_add(&self.wlr_cursor.*.events.frame, &self.listen_frame); | ||||
|         c.wl_signal_add(&self.wlr_cursor.events.motion, &self.listen_motion); | ||||
|         c.wl_signal_add(&self.wlr_cursor.events.motion_absolute, &self.listen_motion_absolute); | ||||
|         c.wl_signal_add(&self.wlr_cursor.events.button, &self.listen_button); | ||||
|         c.wl_signal_add(&self.wlr_cursor.events.axis, &self.listen_axis); | ||||
|         c.wl_signal_add(&self.wlr_cursor.events.frame, &self.listen_frame); | ||||
|  | ||||
|         // This listens for clients requesting a specific cursor image | ||||
|         c.wl_signal_add(&self.seat.wlr_seat.events.request_set_cursor, &self.listen_request_set_cursor); | ||||
| @ -112,8 +112,8 @@ pub const Cursor = struct { | ||||
|  | ||||
|     fn process_move(self: *@This(), time: u32) void { | ||||
|         // Move the grabbed view to the new position. | ||||
|         self.grabbed_view.?.*.x = @floatToInt(c_int, self.wlr_cursor.x - self.grab_x); | ||||
|         self.grabbed_view.?.*.y = @floatToInt(c_int, self.wlr_cursor.y - self.grab_y); | ||||
|         self.grabbed_view.?.x = @floatToInt(c_int, self.wlr_cursor.x - self.grab_x); | ||||
|         self.grabbed_view.?.y = @floatToInt(c_int, self.wlr_cursor.y - self.grab_y); | ||||
|     } | ||||
|  | ||||
|     fn process_resize(self: *@This(), time: u32) void { | ||||
| @ -279,7 +279,7 @@ pub const Cursor = struct { | ||||
|             &sy, | ||||
|         ); | ||||
|  | ||||
|         if (event.*.state == c.enum_wlr_button_state.WLR_BUTTON_RELEASED) { | ||||
|         if (event.state == c.enum_wlr_button_state.WLR_BUTTON_RELEASED) { | ||||
|             // If you released any buttons, we exit interactive move/resize mode. | ||||
|             cursor.mode = CursorMode.Passthrough; | ||||
|         } else { | ||||
| @ -331,7 +331,7 @@ pub const Cursor = struct { | ||||
|  | ||||
|         // This can be sent by any client, so we check to make sure this one is | ||||
|         // actually has pointer focus first. | ||||
|         if (focused_client == event.*.seat_client) { | ||||
|         if (focused_client == event.seat_client) { | ||||
|             // Once we've vetted the client, we can tell the cursor to use the | ||||
|             // provided surface as the cursor image. It will set the hardware cursor | ||||
|             // on the output that it's currently on and continue to do so as the | ||||
|  | ||||
| @ -6,6 +6,7 @@ const Seat = @import("seat.zig").Seat; | ||||
| pub const Keyboard = struct { | ||||
|     seat: *Seat, | ||||
|     device: *c.wlr_input_device, | ||||
|     wlr_keyboard: *c.wlr_keyboard, | ||||
|  | ||||
|     listen_modifiers: c.wl_listener, | ||||
|     listen_key: c.wl_listener, | ||||
| @ -13,6 +14,7 @@ pub const Keyboard = struct { | ||||
|     pub fn init(self: *@This(), seat: *Seat, device: *c.wlr_input_device) !void { | ||||
|         self.seat = seat; | ||||
|         self.device = device; | ||||
|         self.wlr_keyboard = device.unnamed_37.keyboard; | ||||
|  | ||||
|         // We need to prepare an XKB keymap and assign it to the keyboard. This | ||||
|         // assumes the defaults (e.g. layout = "us"). | ||||
| @ -35,17 +37,16 @@ pub const Keyboard = struct { | ||||
|             return error.CantCreateXkbKeymap; | ||||
|         defer c.xkb_keymap_unref(keymap); | ||||
|  | ||||
|         var keyboard_device = self.device.unnamed_37.keyboard; | ||||
|         // TODO: handle failure after https://github.com/swaywm/wlroots/pull/2081 | ||||
|         c.wlr_keyboard_set_keymap(keyboard_device, keymap); | ||||
|         c.wlr_keyboard_set_repeat_info(keyboard_device, 25, 600); | ||||
|         c.wlr_keyboard_set_keymap(self.wlr_keyboard, keymap); | ||||
|         c.wlr_keyboard_set_repeat_info(self.wlr_keyboard, 25, 600); | ||||
|  | ||||
|         // Setup listeners for keyboard events | ||||
|         self.listen_modifiers.notify = handle_modifiers; | ||||
|         c.wl_signal_add(&keyboard_device.*.events.modifiers, &self.listen_modifiers); | ||||
|         c.wl_signal_add(&self.wlr_keyboard.events.modifiers, &self.listen_modifiers); | ||||
|  | ||||
|         self.listen_key.notify = handle_key; | ||||
|         c.wl_signal_add(&keyboard_device.*.events.key, &self.listen_key); | ||||
|         c.wl_signal_add(&self.wlr_keyboard.events.key, &self.listen_key); | ||||
|     } | ||||
|  | ||||
|     fn handle_modifiers(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { | ||||
| @ -57,10 +58,13 @@ pub const Keyboard = struct { | ||||
|         // Wayland protocol - not wlroots. We assign all connected keyboards to the | ||||
|         // same seat. You can swap out the underlying wlr_keyboard like this and | ||||
|         // wlr_seat handles this transparently. | ||||
|         c.wlr_seat_set_keyboard(keyboard.seat.wlr_seat, keyboard.*.device); | ||||
|         c.wlr_seat_set_keyboard(keyboard.seat.wlr_seat, keyboard.device); | ||||
|  | ||||
|         // Send modifiers to the client. | ||||
|         c.wlr_seat_keyboard_notify_modifiers(keyboard.seat.wlr_seat, &keyboard.*.device.*.unnamed_37.keyboard.*.modifiers); | ||||
|         c.wlr_seat_keyboard_notify_modifiers( | ||||
|             keyboard.seat.wlr_seat, | ||||
|             &keyboard.wlr_keyboard.modifiers, | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     fn handle_key(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { | ||||
| @ -71,16 +75,16 @@ pub const Keyboard = struct { | ||||
|             @alignCast(@alignOf(*c.wlr_event_keyboard_key), data), | ||||
|         ); | ||||
|  | ||||
|         const keyboard_device = keyboard.device.unnamed_37.keyboard; | ||||
|         const wlr_keyboard: *c.wlr_keyboard = keyboard.device.unnamed_37.keyboard; | ||||
|  | ||||
|         // Translate libinput keycode -> xkbcommon | ||||
|         const keycode = event.keycode + 8; | ||||
|         // Get a list of keysyms based on the keymap for this keyboard | ||||
|         var syms: ?[*]c.xkb_keysym_t = undefined; | ||||
|         const nsyms = c.xkb_state_key_get_syms(keyboard_device.*.xkb_state, keycode, &syms); | ||||
|         const nsyms = c.xkb_state_key_get_syms(wlr_keyboard.xkb_state, keycode, &syms); | ||||
|  | ||||
|         var handled = false; | ||||
|         const modifiers = c.wlr_keyboard_get_modifiers(keyboard_device); | ||||
|         const modifiers = c.wlr_keyboard_get_modifiers(wlr_keyboard); | ||||
|         if (modifiers & @intCast(u32, c.WLR_MODIFIER_LOGO) != 0 and | ||||
|             event.state == c.enum_wlr_key_state.WLR_KEY_PRESSED) | ||||
|         { | ||||
|  | ||||
| @ -24,7 +24,7 @@ pub const Output = struct { | ||||
|         // would let the user configure it. | ||||
|  | ||||
|         // if not empty | ||||
|         if (c.wl_list_empty(&wlr_output.*.modes) == 0) { | ||||
|         if (c.wl_list_empty(&wlr_output.modes) == 0) { | ||||
|             const mode = c.wlr_output_preferred_mode(wlr_output); | ||||
|             c.wlr_output_set_mode(wlr_output, mode); | ||||
|             c.wlr_output_enable(wlr_output, true); | ||||
| @ -62,13 +62,13 @@ pub const Output = struct { | ||||
|         _ = c.clock_gettime(c.CLOCK_MONOTONIC, &now); | ||||
|  | ||||
|         // wlr_output_attach_render makes the OpenGL context current. | ||||
|         if (!c.wlr_output_attach_render(output.*.wlr_output, null)) { | ||||
|         if (!c.wlr_output_attach_render(output.wlr_output, null)) { | ||||
|             return; | ||||
|         } | ||||
|         // The "effective" resolution can change if you rotate your outputs. | ||||
|         var width: c_int = undefined; | ||||
|         var height: c_int = undefined; | ||||
|         c.wlr_output_effective_resolution(output.*.wlr_output, &width, &height); | ||||
|         c.wlr_output_effective_resolution(output.wlr_output, &width, &height); | ||||
|         // Begin the renderer (calls glViewport and some other GL sanity checks) | ||||
|         c.wlr_renderer_begin(renderer, width, height); | ||||
|  | ||||
| @ -85,14 +85,14 @@ pub const Output = struct { | ||||
|                 continue; | ||||
|             } | ||||
|             var rdata = RenderData{ | ||||
|                 .output = output.*.wlr_output, | ||||
|                 .output = output.wlr_output, | ||||
|                 .view = view, | ||||
|                 .renderer = renderer, | ||||
|                 .when = &now, | ||||
|             }; | ||||
|             // This calls our render_surface function for each surface among the | ||||
|             // xdg_surface's toplevel and popups. | ||||
|             c.wlr_xdg_surface_for_each_surface(view.*.wlr_xdg_surface, render_surface, &rdata); | ||||
|             c.wlr_xdg_surface_for_each_surface(view.wlr_xdg_surface, render_surface, &rdata); | ||||
|         } | ||||
|  | ||||
|         // Hardware cursors are rendered by the GPU on a separate plane, and can be | ||||
| @ -101,13 +101,13 @@ pub const Output = struct { | ||||
|         // reason, wlroots provides a software fallback, which we ask it to render | ||||
|         // here. wlr_cursor handles configuring hardware vs software cursors for you, | ||||
|         // and this function is a no-op when hardware cursors are in use. | ||||
|         c.wlr_output_render_software_cursors(output.*.wlr_output, null); | ||||
|         c.wlr_output_render_software_cursors(output.wlr_output, null); | ||||
|  | ||||
|         // Conclude rendering and swap the buffers, showing the final frame | ||||
|         // on-screen. | ||||
|         c.wlr_renderer_end(renderer); | ||||
|         // TODO: handle failure | ||||
|         _ = c.wlr_output_commit(output.*.wlr_output); | ||||
|         _ = c.wlr_output_commit(output.wlr_output); | ||||
|     } | ||||
|  | ||||
|     fn render_surface(opt_surface: ?*c.wlr_surface, sx: c_int, sy: c_int, data: ?*c_void) callconv(.C) void { | ||||
| @ -115,8 +115,8 @@ pub const Output = struct { | ||||
|         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; | ||||
|         var output = rdata.*.output; | ||||
|         var view = rdata.view; | ||||
|         var output = rdata.output; | ||||
|  | ||||
|         // We first obtain a wlr_texture, which is a GPU resource. wlroots | ||||
|         // automatically handles negotiating these with the client. The underlying | ||||
| @ -135,16 +135,16 @@ pub const Output = struct { | ||||
|         var ox: f64 = 0.0; | ||||
|         var oy: f64 = 0.0; | ||||
|         c.wlr_output_layout_output_coords(view.server.wlr_output_layout, output, &ox, &oy); | ||||
|         ox += @intToFloat(f64, view.*.x + sx); | ||||
|         oy += @intToFloat(f64, view.*.y + sy); | ||||
|         ox += @intToFloat(f64, view.x + sx); | ||||
|         oy += @intToFloat(f64, view.y + sy); | ||||
|  | ||||
|         // We also have to apply the scale factor for HiDPI outputs. This is only | ||||
|         // part of the puzzle, TinyWL does not fully support HiDPI. | ||||
|         var box = c.wlr_box{ | ||||
|             .x = @floatToInt(c_int, ox * output.*.scale), | ||||
|             .y = @floatToInt(c_int, oy * output.*.scale), | ||||
|             .width = @floatToInt(c_int, @intToFloat(f32, surface.*.current.width) * output.*.scale), | ||||
|             .height = @floatToInt(c_int, @intToFloat(f32, surface.*.current.height) * output.*.scale), | ||||
|             .x = @floatToInt(c_int, ox * output.scale), | ||||
|             .y = @floatToInt(c_int, oy * output.scale), | ||||
|             .width = @floatToInt(c_int, @intToFloat(f32, surface.current.width) * output.scale), | ||||
|             .height = @floatToInt(c_int, @intToFloat(f32, surface.current.height) * output.scale), | ||||
|         }; | ||||
|  | ||||
|         // Those familiar with OpenGL are also familiar with the role of matricies | ||||
| @ -157,15 +157,15 @@ pub const Output = struct { | ||||
|         // Naturally you can do this any way you like, for example to make a 3D | ||||
|         // compositor. | ||||
|         var matrix: [9]f32 = undefined; | ||||
|         var transform = c.wlr_output_transform_invert(surface.*.current.transform); | ||||
|         c.wlr_matrix_project_box(&matrix, &box, transform, 0.0, &output.*.transform_matrix); | ||||
|         var transform = c.wlr_output_transform_invert(surface.current.transform); | ||||
|         c.wlr_matrix_project_box(&matrix, &box, transform, 0.0, &output.transform_matrix); | ||||
|  | ||||
|         // This takes our matrix, the texture, and an alpha, and performs the actual | ||||
|         // rendering on the GPU. | ||||
|         _ = c.wlr_render_texture_with_matrix(rdata.*.renderer, texture, &matrix, 1.0); | ||||
|         _ = c.wlr_render_texture_with_matrix(rdata.renderer, texture, &matrix, 1.0); | ||||
|  | ||||
|         // This lets the client know that we've displayed that frame and it can | ||||
|         // prepare another one now if it likes. | ||||
|         c.wlr_surface_send_frame_done(surface, rdata.*.when); | ||||
|         c.wlr_surface_send_frame_done(surface, rdata.when); | ||||
|     } | ||||
| }; | ||||
|  | ||||
| @ -29,7 +29,7 @@ pub const Seat = struct { | ||||
|         }; | ||||
|  | ||||
|         // This seems to be the default seat name used by compositors | ||||
|         seat.wlr_seat = c.wlr_seat_create(server.*.wl_display, "seat0") orelse | ||||
|         seat.wlr_seat = c.wlr_seat_create(server.wl_display, "seat0") orelse | ||||
|             return error.CantCreateWlrSeat; | ||||
|  | ||||
|         return seat; | ||||
| @ -65,7 +65,7 @@ pub const Seat = struct { | ||||
|         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) { | ||||
|         switch (device.type) { | ||||
|             .WLR_INPUT_DEVICE_KEYBOARD => seat.add_keyboard(device) catch unreachable, | ||||
|             .WLR_INPUT_DEVICE_POINTER => seat.add_pointer(device), | ||||
|             else => {}, | ||||
|  | ||||
| @ -84,8 +84,8 @@ pub const Server = struct { | ||||
|         // This can't be done in create() as wl_signal_add() creates a pointer | ||||
|         // to the wl_list link in our wl_listener, a pointer that would be | ||||
|         // broken when returning from create(); | ||||
|         c.wl_signal_add(&self.wlr_backend.*.events.new_output, &self.listen_new_output); | ||||
|         c.wl_signal_add(&self.wlr_xdg_shell.*.events.new_surface, &self.listen_new_xdg_surface); | ||||
|         c.wl_signal_add(&self.wlr_backend.events.new_output, &self.listen_new_output); | ||||
|         c.wl_signal_add(&self.wlr_xdg_shell.events.new_surface, &self.listen_new_xdg_surface); | ||||
|     } | ||||
|  | ||||
|     /// Free allocated memory and clean up | ||||
| @ -129,13 +129,13 @@ pub const Server = struct { | ||||
|             c.XKB_KEY_Escape => c.wl_display_terminate(self.wl_display), | ||||
|             c.XKB_KEY_F1 => { | ||||
|                 // Cycle to the next view | ||||
|                 //if (c.wl_list_length(&server.*.views) > 1) { | ||||
|                 //    const current_view = @fieldParentPtr(View, "link", server.*.views.next); | ||||
|                 //    const next_view = @fieldParentPtr(View, "link", current_view.*.link.next); | ||||
|                 //    focus_view(next_view, next_view.*.xdg_surface.*.surface); | ||||
|                 //if (c.wl_list_length(&server.views) > 1) { | ||||
|                 //    const current_view = @fieldParentPtr(View, "link", server.views.next); | ||||
|                 //    const next_view = @fieldParentPtr(View, "link", current_view.link.next); | ||||
|                 //    focus_view(next_view, next_view.xdg_surface.surface); | ||||
|                 //    // Move the previous view to the end of the list | ||||
|                 //    c.wl_list_remove(¤t_view.*.link); | ||||
|                 //    c.wl_list_insert(server.*.views.prev, ¤t_view.*.link); | ||||
|                 //    c.wl_list_remove(¤t_view.link); | ||||
|                 //    c.wl_list_insert(server.views.prev, ¤t_view.link); | ||||
|                 //} | ||||
|             }, | ||||
|             else => return false, | ||||
|  | ||||
							
								
								
									
										16
									
								
								src/view.zig
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								src/view.zig
									
									
									
									
									
								
							| @ -34,9 +34,9 @@ pub const View = struct { | ||||
|         self.listen_destroy.notify = handle_destroy; | ||||
|         c.wl_signal_add(&self.wlr_xdg_surface.events.destroy, &self.listen_destroy); | ||||
|  | ||||
|         // var toplevel = xdg_surface.*.unnamed_160.toplevel; | ||||
|         // c.wl_signal_add(&toplevel.*.events.request_move, &view.*.request_move); | ||||
|         // c.wl_signal_add(&toplevel.*.events.request_resize, &view.*.request_resize); | ||||
|         // var toplevel = xdg_surface.unnamed_160.toplevel; | ||||
|         // c.wl_signal_add(&toplevel.events.request_move, &view.request_move); | ||||
|         // c.wl_signal_add(&toplevel.events.request_resize, &view.request_resize); | ||||
|     } | ||||
|  | ||||
|     fn handle_map(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { | ||||
| @ -48,7 +48,7 @@ pub const View = struct { | ||||
|  | ||||
|     fn handle_unmap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { | ||||
|         var view = @fieldParentPtr(View, "listen_unmap", listener.?); | ||||
|         view.*.mapped = false; | ||||
|         view.mapped = false; | ||||
|     } | ||||
|  | ||||
|     fn handle_destroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void { | ||||
| @ -110,13 +110,13 @@ pub const View = struct { | ||||
|         // Tell the seat to have the keyboard enter this surface. wlroots will keep | ||||
|         // track of this and automatically send key events to the appropriate | ||||
|         // clients without additional work on your part. | ||||
|         var keyboard = c.wlr_seat_get_keyboard(wlr_seat); | ||||
|         var keyboard: *c.wlr_keyboard = c.wlr_seat_get_keyboard(wlr_seat); | ||||
|         c.wlr_seat_keyboard_notify_enter( | ||||
|             wlr_seat, | ||||
|             self.wlr_xdg_surface.surface, | ||||
|             &keyboard.*.keycodes, | ||||
|             keyboard.*.num_keycodes, | ||||
|             &keyboard.*.modifiers, | ||||
|             &keyboard.keycodes, | ||||
|             keyboard.num_keycodes, | ||||
|             &keyboard.modifiers, | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user