aboutsummaryrefslogtreecommitdiff
path: root/src/cursor.zig
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2020-03-25 16:24:21 +0100
committerIsaac Freund <ifreund@ifreund.xyz>2020-03-25 16:24:21 +0100
commitac0c0449dcb23542595b77e220e70f7661f76fce (patch)
treeb7ace97002be3b3034df4051ea36b2affa027688 /src/cursor.zig
parent34e47360f5f8412d950eab788acc60073f86b0b3 (diff)
downloadriver-ac0c0449dcb23542595b77e220e70f7661f76fce.tar.gz
river-ac0c0449dcb23542595b77e220e70f7661f76fce.tar.xz
Simplify initialization functions
Diffstat (limited to 'src/cursor.zig')
-rw-r--r--src/cursor.zig104
1 files changed, 43 insertions, 61 deletions
diff --git a/src/cursor.zig b/src/cursor.zig
index 5b408b2..e1fb348 100644
--- a/src/cursor.zig
+++ b/src/cursor.zig
@@ -34,84 +34,66 @@ pub const Cursor = struct {
grab_height: c_int,
resize_edges: u32,
- pub fn create(seat: *Seat) !Self {
- const cursor = Self{
- .seat = seat,
+ pub fn init(self: *Self, seat: *Seat) !void {
+ self.seat = seat;
- // Creates a wlroots utility for tracking the cursor image shown on screen.
- //
- // TODO: free this, it allocates!
- .wlr_cursor = c.wlr_cursor_create() orelse
- return error.CantCreateWlrCursor,
-
- // Creates an xcursor manager, another wlroots utility which loads up
- // Xcursor themes to source cursor images from and makes sure that cursor
- // images are available at all scale factors on the screen (necessary for
- // HiDPI support). We add a cursor theme at scale factor 1 to begin with.
- //
- // TODO: free this, it allocates!
- .wlr_xcursor_manager = c.wlr_xcursor_manager_create(null, 24) orelse
- return error.CantCreateWlrXCursorManager,
-
- .listen_motion = c.wl_listener{
- .link = undefined,
- .notify = handleMotion,
- },
- .listen_motion_absolute = c.wl_listener{
- .link = undefined,
- .notify = handleMotionAbsolute,
- },
- .listen_button = c.wl_listener{
- .link = undefined,
- .notify = handleButton,
- },
- .listen_axis = c.wl_listener{
- .link = undefined,
- .notify = handleAxis,
- },
- .listen_frame = c.wl_listener{
- .link = undefined,
- .notify = handleFrame,
- },
-
- .listen_request_set_cursor = c.wl_listener{
- .link = undefined,
- .notify = handleRequestSetCursor,
- },
-
- .mode = CursorMode.Passthrough,
-
- .grabbed_view = null,
- .grab_x = 0.0,
- .grab_y = 0.0,
- .grab_width = 0,
- .grab_height = 0,
- .resize_edges = 0,
- };
-
- c.wlr_cursor_attach_output_layout(cursor.wlr_cursor, seat.server.root.wlr_output_layout);
- _ = c.wlr_xcursor_manager_load(cursor.wlr_xcursor_manager, 1);
-
- return cursor;
- }
+ // Creates a wlroots utility for tracking the cursor image shown on screen.
+ //
+ // TODO: free this, it allocates!
+ self.wlr_cursor = c.wlr_cursor_create() orelse
+ return error.CantCreateWlrCursor;
+
+ // Creates an xcursor manager, another wlroots utility which loads up
+ // Xcursor themes to source cursor images from and makes sure that cursor
+ // images are available at all scale factors on the screen (necessary for
+ // HiDPI support). We add a cursor theme at scale factor 1 to begin with.
+ //
+ // TODO: free this, it allocates!
+ self.wlr_xcursor_manager = c.wlr_xcursor_manager_create(null, 24) orelse
+ return error.CantCreateWlrXCursorManager;
+
+ c.wlr_cursor_attach_output_layout(self.wlr_cursor, seat.server.root.wlr_output_layout);
+ _ = c.wlr_xcursor_manager_load(self.wlr_xcursor_manager, 1);
+
+ self.mode = CursorMode.Passthrough;
+ self.grabbed_view = null;
+ self.grab_x = 0.0;
+ self.grab_y = 0.0;
+ self.grab_width = 0;
+ self.grab_height = 0;
+ self.resize_edges = 0;
- pub fn init(self: *Self) void {
// wlr_cursor *only* displays an image on screen. It does not move around
// when the pointer moves. However, we can attach input devices to it, and
// it will generate aggregate events for all of them. In these events, we
// 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
+ self.listen_motion.notify = handleMotion;
c.wl_signal_add(&self.wlr_cursor.events.motion, &self.listen_motion);
+
+ self.listen_motion_absolute.notify = handleMotionAbsolute;
c.wl_signal_add(&self.wlr_cursor.events.motion_absolute, &self.listen_motion_absolute);
+
+ self.listen_button.notify = handleButton;
c.wl_signal_add(&self.wlr_cursor.events.button, &self.listen_button);
+
+ self.listen_axis.notify = handleAxis;
c.wl_signal_add(&self.wlr_cursor.events.axis, &self.listen_axis);
+
+ self.listen_frame.notify = handleFrame;
c.wl_signal_add(&self.wlr_cursor.events.frame, &self.listen_frame);
// This listens for clients requesting a specific cursor image
+ self.listen_request_set_cursor.notify = handleRequestSetCursor;
c.wl_signal_add(&self.seat.wlr_seat.events.request_set_cursor, &self.listen_request_set_cursor);
}
+ pub fn destroy(self: *Self) void {
+ c.wlr_xcursor_manager_destroy(self.wlr_xcursor_manager);
+ c.wlr_cursor_destroy(self.wlr_cursor);
+ }
+
fn processMove(self: *Self, time: u32) void {
// Move the grabbed view to the new position.
// TODO: log on null
@@ -215,7 +197,7 @@ pub const Cursor = struct {
c.wlr_seat_pointer_notify_enter(wlr_seat, surface, sx, sy);
if (!focus_changed) {
// The enter event contains coordinates, so we only need to notify
- // on motion if the focus did not change.
+ //on motion if the focus did not change.
c.wlr_seat_pointer_notify_motion(wlr_seat, time, sx, sy);
}
} else {