Standardize panic messages and clean up code
This commit is contained in:
parent
c953fe3d68
commit
e1a0b89ced
5 changed files with 52 additions and 24 deletions
18
src/Seat.zig
18
src/Seat.zig
|
|
@ -46,22 +46,20 @@ fn seatListener(river_seat_v1: *river.SeatV1, event: river.SeatV1.Event, seat: *
|
||||||
.wl_seat => {
|
.wl_seat => {
|
||||||
// log.debug("initializing new river_seat_v1 corresponding to wl_seat: {d}", .{ev.name});
|
// log.debug("initializing new river_seat_v1 corresponding to wl_seat: {d}", .{ev.name});
|
||||||
},
|
},
|
||||||
.pointer_enter => |ev| {
|
.pointer_enter => |ev| seat.setWindowFocus(ev.window),
|
||||||
const window_v1 = ev.window orelse return;
|
.window_interaction => |ev| seat.setWindowFocus(ev.window),
|
||||||
const window: *Window = @ptrCast(@alignCast(window_v1.getUserData()));
|
|
||||||
seat.pending_manage.pending_focus = .{ .window = window };
|
|
||||||
},
|
|
||||||
.window_interaction => |ev| {
|
|
||||||
const window_v1 = ev.window orelse return;
|
|
||||||
const window: *Window = @ptrCast(@alignCast(window_v1.getUserData()));
|
|
||||||
seat.pending_manage.pending_focus = .{ .window = window };
|
|
||||||
},
|
|
||||||
else => |ev| {
|
else => |ev| {
|
||||||
log.debug("unhandled event: {s}", .{@tagName(ev)});
|
log.debug("unhandled event: {s}", .{@tagName(ev)});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn setWindowFocus(seat: *Seat, window_v1: ?*river.WindowV1) void {
|
||||||
|
const wv1 = window_v1 orelse return;
|
||||||
|
const window: *Window = @ptrCast(@alignCast(wv1.getUserData()));
|
||||||
|
seat.pending_manage.pending_focus = .{ .window = window };
|
||||||
|
}
|
||||||
|
|
||||||
pub fn manage(seat: *Seat) void {
|
pub fn manage(seat: *Seat) void {
|
||||||
defer seat.pending_manage = .{};
|
defer seat.pending_manage = .{};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ pub fn init(window: *Window, context: *Context, river_window_v1: *river.WindowV1
|
||||||
window.* = .{
|
window.* = .{
|
||||||
.context = context,
|
.context = context,
|
||||||
.window_v1 = river_window_v1,
|
.window_v1 = river_window_v1,
|
||||||
.node_v1 = river_window_v1.getNode() catch @panic("failed to get node"),
|
.node_v1 = river_window_v1.getNode() catch @panic("Failed to get node"),
|
||||||
.link = undefined, // Handled by the wl.list
|
.link = undefined, // Handled by the wl.list
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -126,7 +126,7 @@ pub fn manage(window: *Window) void {
|
||||||
if (pending_manage.fullscreen) |fullscreen| {
|
if (pending_manage.fullscreen) |fullscreen| {
|
||||||
window.fullscreen = fullscreen;
|
window.fullscreen = fullscreen;
|
||||||
if (fullscreen) {
|
if (fullscreen) {
|
||||||
const output = window.context.wm.outputs.first() orelse @panic("failed to get output");
|
const output = window.context.wm.outputs.first() orelse @panic("Failed to get output");
|
||||||
window.window_v1.fullscreen(output.output_v1);
|
window.window_v1.fullscreen(output.output_v1);
|
||||||
window.window_v1.informFullscreen();
|
window.window_v1.informFullscreen();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -165,18 +165,21 @@ pub fn render(window: *Window) void {
|
||||||
// Set borders
|
// Set borders
|
||||||
if (!window.fullscreen) {
|
if (!window.fullscreen) {
|
||||||
if (window.pending_render.focused) |focused| {
|
if (window.pending_render.focused) |focused| {
|
||||||
const border_width = window.context.config.border_width;
|
|
||||||
if (focused) {
|
if (focused) {
|
||||||
const border_color_focused = window.context.config.border_color_focused;
|
window.applyBorders(window.context.config.border_color_focused);
|
||||||
window.window_v1.setBorders(.{ .top = true, .bottom = true, .left = true, .right = true }, border_width, border_color_focused.red, border_color_focused.green, border_color_focused.blue, border_color_focused.alpha);
|
|
||||||
} else {
|
} else {
|
||||||
const border_color_unfocused = window.context.config.border_color_unfocused;
|
window.applyBorders(window.context.config.border_color_unfocused);
|
||||||
window.window_v1.setBorders(.{ .top = true, .bottom = true, .left = true, .right = true }, border_width, border_color_unfocused.red, border_color_unfocused.green, border_color_unfocused.blue, border_color_unfocused.alpha);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn applyBorders(window: *Window, color: utils.RiverColor) void {
|
||||||
|
const border_width = window.context.config.border_width;
|
||||||
|
const all_sides = river.WindowV1.Edges{ .top = true, .bottom = true, .left = true, .right = true };
|
||||||
|
window.window_v1.setBorders(all_sides, border_width, color.red, color.green, color.blue, color.alpha);
|
||||||
|
}
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,28 @@ pub fn create(context: *Context, window_manager_v1: *river.WindowManagerV1) !*Wi
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(wm: *WindowManager) void {
|
pub fn destroy(wm: *WindowManager) void {
|
||||||
// TODO: Go through lists and destroy everything
|
var window_it = wm.windows.iterator(.forward);
|
||||||
|
while (window_it.next()) |window| {
|
||||||
|
window.window_v1.destroy();
|
||||||
|
window.node_v1.destroy();
|
||||||
|
window.link.remove();
|
||||||
|
utils.allocator.destroy(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
var output_it = wm.outputs.iterator(.forward);
|
||||||
|
while (output_it.next()) |output| {
|
||||||
|
output.output_v1.destroy();
|
||||||
|
output.link.remove();
|
||||||
|
utils.allocator.destroy(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
var seat_it = wm.seats.iterator(.forward);
|
||||||
|
while (seat_it.next()) |seat| {
|
||||||
|
seat.seat_v1.destroy();
|
||||||
|
seat.link.remove();
|
||||||
|
utils.allocator.destroy(seat);
|
||||||
|
}
|
||||||
|
|
||||||
utils.allocator.destroy(wm);
|
utils.allocator.destroy(wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,7 +229,7 @@ fn windowManagerV1Listener(window_manager_v1: *river.WindowManagerV1, event: riv
|
||||||
},
|
},
|
||||||
.output => |ev| {
|
.output => |ev| {
|
||||||
// TODO: Support multi-output
|
// TODO: Support multi-output
|
||||||
var output = utils.allocator.create(Output) catch @panic("out-of-memory; exiting.");
|
var output = utils.allocator.create(Output) catch @panic("Out of memory");
|
||||||
output.init(context, ev.id);
|
output.init(context, ev.id);
|
||||||
wm.outputs.append(output);
|
wm.outputs.append(output);
|
||||||
},
|
},
|
||||||
|
|
@ -221,12 +242,12 @@ fn windowManagerV1Listener(window_manager_v1: *river.WindowManagerV1, event: riv
|
||||||
utils.versionNotSupported(river.SeatV1, river_seat_v1_version, MIN_RIVER_SEAT_V1_VERSION);
|
utils.versionNotSupported(river.SeatV1, river_seat_v1_version, MIN_RIVER_SEAT_V1_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
var seat = utils.allocator.create(Seat) catch @panic("out-of-memory; exiting.");
|
var seat = utils.allocator.create(Seat) catch @panic("Out of memory");
|
||||||
seat.init(context, river_seat_v1);
|
seat.init(context, river_seat_v1);
|
||||||
wm.seats.append(seat);
|
wm.seats.append(seat);
|
||||||
},
|
},
|
||||||
.window => |ev| {
|
.window => |ev| {
|
||||||
var window = utils.allocator.create(Window) catch @panic("out-of-memory; exiting.");
|
var window = utils.allocator.create(Window) catch @panic("Out of memory");
|
||||||
window.init(context, ev.id);
|
window.init(context, ev.id);
|
||||||
|
|
||||||
// TODO - CONFIG: Allow appending window instead of prepending
|
// TODO - CONFIG: Allow appending window instead of prepending
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,13 @@ pub fn create(context: *Context, xkb_bindings_v1: *river.XkbBindingsV1) !*XkbBin
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(xkb_bindings: *XkbBindings) void {
|
pub fn destroy(xkb_bindings: *XkbBindings) void {
|
||||||
xkb_bindings.destroy();
|
var it = xkb_bindings.bindings.iterator(.forward);
|
||||||
|
while (it.next()) |binding| {
|
||||||
|
binding.link.remove();
|
||||||
|
binding.xkb_binding_v1.destroy();
|
||||||
|
utils.allocator.destroy(binding);
|
||||||
|
}
|
||||||
|
utils.allocator.destroy(xkb_bindings);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addBinding(xkb_bindings: *XkbBindings, river_seat_v1: *river.SeatV1, keysym: u32, modifiers: river.SeatV1.Modifiers, command: Command) void {
|
pub fn addBinding(xkb_bindings: *XkbBindings, river_seat_v1: *river.SeatV1, keysym: u32, modifiers: river.SeatV1.Modifiers, command: Command) void {
|
||||||
|
|
@ -135,7 +141,7 @@ pub fn addBinding(xkb_bindings: *XkbBindings, river_seat_v1: *river.SeatV1, keys
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
const xkb_binding = utils.allocator.create(XkbBinding) catch @panic("out-of-memory");
|
const xkb_binding = utils.allocator.create(XkbBinding) catch @panic("Out of memory");
|
||||||
xkb_binding.init(xkb_binding_v1, command, xkb_bindings.context);
|
xkb_binding.init(xkb_binding_v1, command, xkb_bindings.context);
|
||||||
xkb_bindings.bindings.append(xkb_binding);
|
xkb_bindings.bindings.append(xkb_binding);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const Globals = struct {
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
const wayland_display_var = try utils.allocator.dupeZ(u8, process.getEnvVarOwned(utils.allocator, "WAYLAND_DISPLAY") catch {
|
const wayland_display_var = try utils.allocator.dupeZ(u8, process.getEnvVarOwned(utils.allocator, "WAYLAND_DISPLAY") catch {
|
||||||
log.err("Error getting WAYLAND_DISPLAY environment variable. Exiing", .{});
|
log.err("Error getting WAYLAND_DISPLAY environment variable. Exiting", .{});
|
||||||
std.posix.exit(1);
|
std.posix.exit(1);
|
||||||
});
|
});
|
||||||
defer utils.allocator.free(wayland_display_var);
|
defer utils.allocator.free(wayland_display_var);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue