From 0ebb5ccc179a48420d19f9f92162400522a38077 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 16 Jul 2020 21:20:43 +0200 Subject: [PATCH] code: update to wlroots 0.11.0 --- README.md | 2 +- river/Cursor.zig | 4 ++-- river/Keyboard.zig | 7 +++---- river/Seat.zig | 5 +++-- river/Server.zig | 7 +++---- river/View.zig | 10 +++++----- river/render.zig | 2 +- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 6f3e9df..0cdb98f 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ installed: - [zig](https://github.com/ziglang/zig) 0.6.0 - wayland - wayland-protocols -- [wlroots](https://github.com/swaywm/wlroots) 0.10.1 +- [wlroots](https://github.com/swaywm/wlroots) 0.11.0 - xkbcommon - pixman - pkg-config diff --git a/river/Cursor.zig b/river/Cursor.zig index 5c3e1b1..a1ed427 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -130,7 +130,7 @@ pub fn setTheme(self: *Self, theme: ?[*:0]const u8, size: ?u32) !void { var it = server.root.outputs.first; while (it) |node| : (it = node.next) { const wlr_output = node.data.wlr_output; - if (c.wlr_xcursor_manager_load(self.wlr_xcursor_manager, wlr_output.scale) != 0) + if (!c.wlr_xcursor_manager_load(self.wlr_xcursor_manager, wlr_output.scale)) log.err(.cursor, "failed to load xcursor theme '{}' at scale {}", .{ theme, wlr_output.scale }); } @@ -143,7 +143,7 @@ pub fn setTheme(self: *Self, theme: ?[*:0]const u8, size: ?u32) !void { if (theme) |t| if (c.setenv("XCURSOR_THEME", t, 1) < 0) return error.OutOfMemory; if (build_options.xwayland) { - if (c.wlr_xcursor_manager_load(self.wlr_xcursor_manager, 1) == 0) { + if (c.wlr_xcursor_manager_load(self.wlr_xcursor_manager, 1)) { const wlr_xcursor = c.wlr_xcursor_manager_get_xcursor(self.wlr_xcursor_manager, "left_ptr", 1).?; const image: *c.wlr_xcursor_image = wlr_xcursor.*.images[0]; c.wlr_xwayland_set_cursor( diff --git a/river/Keyboard.zig b/river/Keyboard.zig index c52a392..24e4022 100644 --- a/river/Keyboard.zig +++ b/river/Keyboard.zig @@ -46,18 +46,17 @@ pub fn init(self: *Self, seat: *Seat, wlr_input_device: *c.wlr_input_device) !vo .variant = null, .options = null, }; - const context = c.xkb_context_new(.XKB_CONTEXT_NO_FLAGS) orelse return error.CreateXkbContextError; + const context = c.xkb_context_new(.XKB_CONTEXT_NO_FLAGS) orelse return error.XkbContextFailed; defer c.xkb_context_unref(context); const keymap = c.xkb_keymap_new_from_names( context, &rules, .XKB_KEYMAP_COMPILE_NO_FLAGS, - ) orelse return error.CreateXkbKeymapError; + ) orelse return error.XkbKeymapFailed; defer c.xkb_keymap_unref(keymap); - // TODO: handle failure after https://github.com/swaywm/wlroots/pull/2081 - c.wlr_keyboard_set_keymap(self.wlr_keyboard, keymap); + if (!c.wlr_keyboard_set_keymap(self.wlr_keyboard, keymap)) return error.SetKeymapFailed; c.wlr_keyboard_set_repeat_info(self.wlr_keyboard, 25, 600); // Setup listeners for keyboard events diff --git a/river/Seat.zig b/river/Seat.zig index c3d75db..886cacc 100644 --- a/river/Seat.zig +++ b/river/Seat.zig @@ -294,8 +294,9 @@ fn addKeyboard(self: *Self, device: *c.wlr_input_device) !void { const node = try self.keyboards.allocateNode(util.gpa); node.data.init(self, device) catch |err| { switch (err) { - error.CreateXkbContextError => log.err(.keyboard, "Failed to create XKB context", .{}), - error.CreateXkbKeymapError => log.err(.keyboard, "Failed to create XKB keymap", .{}), + error.XkbContextFailed => log.err(.keyboard, "Failed to create XKB context", .{}), + error.XkbKeymapFailed => log.err(.keyboard, "Failed to create XKB keymap", .{}), + error.SetKeymapFailed => log.err(.keyboard, "Failed to set wlr keyboard keymap", .{}), } return; }; diff --git a/river/Server.zig b/river/Server.zig index 0621a58..66af1e7 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -84,9 +84,8 @@ pub fn init(self: *Self) !void { // The renderer is responsible for defining the various pixel formats it // supports for shared memory, this configures that for clients. const wlr_renderer = c.river_wlr_backend_get_renderer(self.wlr_backend).?; - // TODO: Handle failure after https://github.com/swaywm/wlroots/pull/2080 - c.wlr_renderer_init_wl_display(wlr_renderer, self.wl_display); // orelse - // return error.CantInitWlDisplay; + if (!c.wlr_renderer_init_wl_display(wlr_renderer, self.wl_display)) return error.DisplayInitFailed; + self.listen_new_output.notify = handleNewOutput; c.wl_signal_add(&self.wlr_backend.events.new_output, &self.listen_new_output); @@ -149,7 +148,7 @@ pub fn start(self: Self) !void { if (!c.river_wlr_backend_start(self.wlr_backend)) return error.StartBackendError; if (c.setenv("WAYLAND_DISPLAY", socket, 1) < 0) return error.SetenvError; if (build_options.xwayland) { - if (c.setenv("DISPLAY", &self.wlr_xwayland.display_name, 1) < 0) return error.SetenvError; + if (c.setenv("DISPLAY", self.wlr_xwayland.display_name, 1) < 0) return error.SetenvError; } } diff --git a/river/View.zig b/river/View.zig index b405602..3df7e1c 100644 --- a/river/View.zig +++ b/river/View.zig @@ -50,7 +50,7 @@ const State = struct { }; const SavedBuffer = struct { - wlr_buffer: *c.wlr_buffer, + wlr_client_buffer: *c.wlr_client_buffer, box: Box, transform: c.wl_output_transform, }; @@ -127,7 +127,7 @@ pub fn init(self: *Self, output: *Output, tags: u32, surface: var) void { } pub fn deinit(self: Self) void { - for (self.saved_buffers.items) |buffer| c.wlr_buffer_unref(buffer.wlr_buffer); + for (self.saved_buffers.items) |buffer| c.wlr_buffer_unlock(&buffer.wlr_client_buffer.*.base); self.saved_buffers.deinit(); } @@ -152,7 +152,7 @@ pub fn sendFrameDone(self: Self) void { } pub fn dropSavedBuffers(self: *Self) void { - for (self.saved_buffers.items) |buffer| c.wlr_buffer_unref(buffer.wlr_buffer); + for (self.saved_buffers.items) |buffer| c.wlr_buffer_unlock(&buffer.wlr_client_buffer.*.base); self.saved_buffers.items.len = 0; } @@ -176,7 +176,7 @@ fn saveBuffersIterator( if (wlr_surface) |surface| { if (c.wlr_surface_has_buffer(surface)) { saved_buffers.append(.{ - .wlr_buffer = surface.buffer, + .wlr_client_buffer = surface.buffer, .box = Box{ .x = surface_x, .y = surface_y, @@ -185,7 +185,7 @@ fn saveBuffersIterator( }, .transform = surface.current.transform, }) catch return; - _ = c.wlr_buffer_ref(surface.buffer); + _ = c.wlr_buffer_lock(&surface.buffer.*.base); } } } diff --git a/river/render.zig b/river/render.zig index 0ef67b5..fc72266 100644 --- a/river/render.zig +++ b/river/render.zig @@ -156,7 +156,7 @@ fn renderView(output: Output, view: *View, now: *c.timespec) void { for (view.saved_buffers.items) |saved_buffer| renderTexture( output, - saved_buffer.wlr_buffer.texture, + saved_buffer.wlr_client_buffer.texture, .{ .x = saved_buffer.box.x + view.current.box.x - view.saved_surface_box.x, .y = saved_buffer.box.y + view.current.box.y - view.saved_surface_box.y,