Cursor: clean up cursor theme loading
wlroots will now load xcursor themes at the correct scale automatically based on the scale of the outputs where ther cursors are displayed. Also make the error handling a bit more robust.
This commit is contained in:
parent
9ce4525f08
commit
913770975b
2
deps/zig-wlroots
vendored
2
deps/zig-wlroots
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 0ddfe81c5957fd36f8f8faf3d0870df974860661
|
Subproject commit 68ce60769c6a8019c43de35197f4596eaac4df48
|
@ -237,20 +237,11 @@ pub fn deinit(self: *Self) void {
|
|||||||
pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void {
|
pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void {
|
||||||
const size = _size orelse default_size;
|
const size = _size orelse default_size;
|
||||||
|
|
||||||
self.xcursor_manager.destroy();
|
const xcursor_manager = try wlr.XcursorManager.create(theme, size);
|
||||||
self.xcursor_manager = try wlr.XcursorManager.create(theme, size);
|
errdefer xcursor_manager.destroy();
|
||||||
|
|
||||||
// For each output, ensure a theme of the proper scale is loaded
|
|
||||||
var it = server.root.active_outputs.iterator(.forward);
|
|
||||||
while (it.next()) |output| {
|
|
||||||
const wlr_output = output.wlr_output;
|
|
||||||
self.xcursor_manager.load(wlr_output.scale) catch
|
|
||||||
log.err("failed to load xcursor theme '{?s}' at scale {}", .{ theme, wlr_output.scale });
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this cursor belongs to the default seat, set the xcursor environment
|
// If this cursor belongs to the default seat, set the xcursor environment
|
||||||
// variables as well as the xwayland cursor theme and update the cursor
|
// variables as well as the xwayland cursor theme.
|
||||||
// image if necessary.
|
|
||||||
if (self.seat == server.input_manager.defaultSeat()) {
|
if (self.seat == server.input_manager.defaultSeat()) {
|
||||||
const size_str = try std.fmt.allocPrintZ(util.gpa, "{}", .{size});
|
const size_str = try std.fmt.allocPrintZ(util.gpa, "{}", .{size});
|
||||||
defer util.gpa.free(size_str);
|
defer util.gpa.free(size_str);
|
||||||
@ -258,11 +249,8 @@ 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 (theme) |t| if (c.setenv("XCURSOR_THEME", t, 1) < 0) return error.OutOfMemory;
|
||||||
|
|
||||||
if (build_options.xwayland) {
|
if (build_options.xwayland) {
|
||||||
self.xcursor_manager.load(1) catch {
|
try xcursor_manager.load(1);
|
||||||
log.err("failed to load xcursor theme '{?s}' at scale 1", .{theme});
|
const wlr_xcursor = xcursor_manager.getXcursor("left_ptr", 1).?;
|
||||||
return;
|
|
||||||
};
|
|
||||||
const wlr_xcursor = self.xcursor_manager.getXcursor("left_ptr", 1).?;
|
|
||||||
const image = wlr_xcursor.images[0];
|
const image = wlr_xcursor.images[0];
|
||||||
server.xwayland.setCursor(
|
server.xwayland.setCursor(
|
||||||
image.buffer,
|
image.buffer,
|
||||||
@ -275,6 +263,10 @@ pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Everything fallible is now done so the the old xcursor_manager can be destroyed.
|
||||||
|
self.xcursor_manager.destroy();
|
||||||
|
self.xcursor_manager = xcursor_manager;
|
||||||
|
|
||||||
if (self.xcursor_name) |name| {
|
if (self.xcursor_name) |name| {
|
||||||
self.setXcursor(name);
|
self.setXcursor(name);
|
||||||
}
|
}
|
||||||
|
@ -306,15 +306,6 @@ pub fn create(wlr_output: *wlr.Output) !void {
|
|||||||
wlr_output.events.frame.add(&output.frame);
|
wlr_output.events.frame.add(&output.frame);
|
||||||
wlr_output.events.present.add(&output.present);
|
wlr_output.events.present.add(&output.present);
|
||||||
|
|
||||||
// Ensure that a cursor image at the output's scale factor is loaded
|
|
||||||
// for each seat.
|
|
||||||
var it = server.input_manager.seats.first;
|
|
||||||
while (it) |seat_node| : (it = seat_node.next) {
|
|
||||||
const seat = &seat_node.data;
|
|
||||||
seat.cursor.xcursor_manager.load(wlr_output.scale) catch
|
|
||||||
log.err("failed to load xcursor theme at scale {}", .{wlr_output.scale});
|
|
||||||
}
|
|
||||||
|
|
||||||
output.setTitle();
|
output.setTitle();
|
||||||
|
|
||||||
output.active_link.init();
|
output.active_link.init();
|
||||||
|
Loading…
Reference in New Issue
Block a user