reformatted with zig fmt

This commit is contained in:
Squibid 2026-03-01 22:23:31 -05:00
parent e6a45f91b6
commit 6be66b6a71
Signed by: squibid
GPG key ID: BECE5684D3C4005D
32 changed files with 2108 additions and 2237 deletions

View file

@ -6,11 +6,6 @@ root = true
end_of_line = lf end_of_line = lf
insert_final_newline = true insert_final_newline = true
[*.zig]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
[*.lua] [*.lua]
indent_style = space indent_style = space
indent_size = 2 indent_size = 2

View file

@ -73,7 +73,7 @@ pub fn build(b: *std.Build) void {
var ret: u8 = undefined; var ret: u8 = undefined;
const version = b.runAllowFail( const version = b.runAllowFail(
&.{"git", "-C", b.build_root.path orelse ".", "describe", "--tags", "--dirty"}, &.{ "git", "-C", b.build_root.path orelse ".", "describe", "--tags", "--dirty" },
&ret, &ret,
.Inherit, .Inherit,
) catch "dev\n"; ) catch "dev\n";

View file

@ -31,15 +31,11 @@ mode: enum { normal, drag } = .normal,
// Drag information // Drag information
drag: ?struct { drag: ?struct {
event_code: u32, event_code: u32,
start: struct { start: struct { x: c_int, y: c_int },
view: ?struct { view: *View, dims: struct { width: c_int, height: c_int }, offset: struct {
x: c_int, x: c_int,
y: c_int y: c_int,
}, } },
view: ?struct {
view: *View,
dims: struct { width: c_int, height: c_int },
offset: struct { x: c_int, y: c_int, }
},
}, },
pub fn init(self: *Cursor) void { pub fn init(self: *Cursor) void {
@ -48,7 +44,7 @@ pub fn init(self: *Cursor) void {
self.* = .{ self.* = .{
.wlr_cursor = try wlr.Cursor.create(), .wlr_cursor = try wlr.Cursor.create(),
.x_cursor_manager = try wlr.XcursorManager.create(null, 24), .x_cursor_manager = try wlr.XcursorManager.create(null, 24),
.drag = null .drag = null,
}; };
try self.x_cursor_manager.load(1); try self.x_cursor_manager.load(1);
@ -87,38 +83,21 @@ pub fn processCursorMotion(self: *Cursor, time_msec: u32) void {
// Proceed if mousemap for current mouse and modifier state's exist // Proceed if mousemap for current mouse and modifier state's exist
if (server.mousemaps.get(Mousemap.hash(modifiers, @bitCast(self.drag.?.event_code)))) |map| { if (server.mousemaps.get(Mousemap.hash(modifiers, @bitCast(self.drag.?.event_code)))) |map| {
if(map.options.lua_drag_ref_idx > 0) { if (map.options.lua_drag_ref_idx > 0) {
passthrough = map.callback(.drag, .{ passthrough = map.callback(.drag, .{ .{ .x = @as(c_int, @intFromFloat(self.wlr_cursor.x)), .y = @as(c_int, @intFromFloat(self.wlr_cursor.y)) }, .{ .start = self.drag.?.start, .view = if (self.drag.?.view != null) .{ .id = self.drag.?.view.?.view.id, .dims = self.drag.?.view.?.dims, .offset = self.drag.?.view.?.offset } else null } });
.{
.x = @as(c_int, @intFromFloat(self.wlr_cursor.x)),
.y = @as(c_int, @intFromFloat(self.wlr_cursor.y))
},
.{
.start = self.drag.?.start,
.view = if (self.drag.?.view != null) .{
.id = self.drag.?.view.?.view.id,
.dims = self.drag.?.view.?.dims,
.offset = self.drag.?.view.?.offset
} else null
}
});
} }
} }
} }
if(passthrough) { if (passthrough) {
const output = server.seat.focused_output; const output = server.seat.focused_output;
// Exit the switch if no focused output exists // Exit the switch if no focused output exists
std.debug.assert(output != null); std.debug.assert(output != null);
const surfaceAtResult = output.?.surfaceAt(self.wlr_cursor.x, self.wlr_cursor.y); const surfaceAtResult = output.?.surfaceAt(self.wlr_cursor.x, self.wlr_cursor.y);
if (surfaceAtResult) |surface| { if (surfaceAtResult) |surface| {
if(surface.scene_node_data.* == .view) { if (surface.scene_node_data.* == .view) {
server.events.exec("ViewPointerMotion", .{ server.events.exec("ViewPointerMotion", .{ surface.scene_node_data.view.id, @as(c_int, @intFromFloat(self.wlr_cursor.x)), @as(c_int, @intFromFloat(self.wlr_cursor.y)) });
surface.scene_node_data.view.id,
@as(c_int, @intFromFloat(self.wlr_cursor.x)),
@as(c_int, @intFromFloat(self.wlr_cursor.y))
});
} }
server.seat.wlr_seat.pointerNotifyEnter(surfaceAtResult.?.surface, surfaceAtResult.?.sx, surfaceAtResult.?.sy); server.seat.wlr_seat.pointerNotifyEnter(surfaceAtResult.?.surface, surfaceAtResult.?.sx, surfaceAtResult.?.sy);
@ -133,53 +112,37 @@ pub fn processCursorMotion(self: *Cursor, time_msec: u32) void {
// --------- WLR Cursor event handlers --------- // --------- WLR Cursor event handlers ---------
fn handleMotion( fn handleMotion(
_: *wl.Listener(*wlr.Pointer.event.Motion), _: *wl.Listener(*wlr.Pointer.event.Motion),
event: *wlr.Pointer.event.Motion, event: *wlr.Pointer.event.Motion,
) void { ) void {
server.cursor.wlr_cursor.move(event.device, event.delta_x, event.delta_y); server.cursor.wlr_cursor.move(event.device, event.delta_x, event.delta_y);
server.cursor.processCursorMotion(event.time_msec); server.cursor.processCursorMotion(event.time_msec);
} }
fn handleMotionAbsolute( fn handleMotionAbsolute(
_: *wl.Listener(*wlr.Pointer.event.MotionAbsolute), _: *wl.Listener(*wlr.Pointer.event.MotionAbsolute),
event: *wlr.Pointer.event.MotionAbsolute, event: *wlr.Pointer.event.MotionAbsolute,
) void { ) void {
server.cursor.wlr_cursor.warpAbsolute(event.device, event.x, event.y); server.cursor.wlr_cursor.warpAbsolute(event.device, event.x, event.y);
server.cursor.processCursorMotion(event.time_msec); server.cursor.processCursorMotion(event.time_msec);
} }
fn handleButton( fn handleButton(listener: *wl.Listener(*wlr.Pointer.event.Button), event: *wlr.Pointer.event.Button) void {
listener: *wl.Listener(*wlr.Pointer.event.Button),
event: *wlr.Pointer.event.Button
) void {
const cursor: *Cursor = @fieldParentPtr("button", listener); const cursor: *Cursor = @fieldParentPtr("button", listener);
switch (event.state) { switch (event.state) {
.pressed => { .pressed => {
cursor.mode = .drag; cursor.mode = .drag;
cursor.drag = .{ cursor.drag = .{ .event_code = event.button, .start = .{ .x = @as(c_int, @intFromFloat(cursor.wlr_cursor.x)), .y = @as(c_int, @intFromFloat(cursor.wlr_cursor.y)) }, .view = null };
.event_code = event.button,
.start = .{
.x = @as(c_int, @intFromFloat(cursor.wlr_cursor.x)),
.y = @as(c_int, @intFromFloat(cursor.wlr_cursor.y))
},
.view = null
};
// Keep track of where the drag started // Keep track of where the drag started
if(server.seat.focused_surface) |fs| { if (server.seat.focused_surface) |fs| {
if(fs == .view) { if (fs == .view) {
cursor.drag.?.view = .{ cursor.drag.?.view = .{
.view = fs.view, .view = fs.view,
.dims = .{ .dims = .{ .width = fs.view.xdg_toplevel.base.geometry.width, .height = fs.view.xdg_toplevel.base.geometry.height },
.width = fs.view.xdg_toplevel.base.geometry.width, .offset = .{ .x = cursor.drag.?.start.x - fs.view.scene_tree.node.x, .y = cursor.drag.?.start.y - fs.view.scene_tree.node.y },
.height = fs.view.xdg_toplevel.base.geometry.height
},
.offset = .{
.x = cursor.drag.?.start.x - fs.view.scene_tree.node.x,
.y = cursor.drag.?.start.y - fs.view.scene_tree.node.y
},
}; };
} }
} }
@ -196,7 +159,7 @@ fn handleButton(
}, },
else => { else => {
std.log.err("Invalid/Unimplemented pointer button event type", .{}); std.log.err("Invalid/Unimplemented pointer button event type", .{});
} },
} }
var passthrough = true; var passthrough = true;
@ -207,49 +170,39 @@ fn handleButton(
switch (event.state) { switch (event.state) {
.pressed => { .pressed => {
// Only make callback if a callback function exists // Only make callback if a callback function exists
if(map.options.lua_press_ref_idx > 0) { if (map.options.lua_press_ref_idx > 0) {
passthrough = map.callback(.press, .{ passthrough = map.callback(.press, .{
.{ .{ .x = @as(c_int, @intFromFloat(cursor.wlr_cursor.x)), .y = @as(c_int, @intFromFloat(cursor.wlr_cursor.y)) },
.x = @as(c_int, @intFromFloat(cursor.wlr_cursor.x)),
.y = @as(c_int, @intFromFloat(cursor.wlr_cursor.y))
},
}); });
} }
}, },
.released => { .released => {
if(map.options.lua_press_ref_idx > 0) { if (map.options.lua_press_ref_idx > 0) {
passthrough = map.callback(.release, .{ passthrough = map.callback(.release, .{
.{ .{ .x = @as(c_int, @intFromFloat(cursor.wlr_cursor.x)), .y = @as(c_int, @intFromFloat(cursor.wlr_cursor.y)) },
.x = @as(c_int, @intFromFloat(cursor.wlr_cursor.x)),
.y = @as(c_int, @intFromFloat(cursor.wlr_cursor.y))
},
}); });
} }
}, },
else => { unreachable; } else => {
unreachable;
},
} }
} }
// If no keymap exists for button event, forward it to a surface // If no keymap exists for button event, forward it to a surface
// TODO: Allow for transparent mousemaps that pass mouse button events anyways // TODO: Allow for transparent mousemaps that pass mouse button events anyways
if(passthrough) { if (passthrough) {
_ = server.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state); _ = server.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state);
} }
} }
fn handleHoldBegin( fn handleHoldBegin(listener: *wl.Listener(*wlr.Pointer.event.HoldBegin), event: *wlr.Pointer.event.HoldBegin) void {
listener: *wl.Listener(*wlr.Pointer.event.HoldBegin),
event: *wlr.Pointer.event.HoldBegin
) void {
_ = listener; _ = listener;
_ = event; _ = event;
std.log.err("Unimplemented cursor start hold", .{}); std.log.err("Unimplemented cursor start hold", .{});
} }
fn handleHoldEnd( fn handleHoldEnd(listener: *wl.Listener(*wlr.Pointer.event.HoldEnd), event: *wlr.Pointer.event.HoldEnd) void {
listener: *wl.Listener(*wlr.Pointer.event.HoldEnd),
event: *wlr.Pointer.event.HoldEnd
) void {
_ = listener; _ = listener;
_ = event; _ = event;
std.log.err("Unimplemented cursor end hold", .{}); std.log.err("Unimplemented cursor end hold", .{});

View file

@ -31,15 +31,10 @@ fn printNode(node: *wlr.SceneNode, depth: usize) void {
const type_name = switch (node.type) { const type_name = switch (node.type) {
.tree => "TREE", .tree => "TREE",
.rect => "RECT", .rect => "RECT",
.buffer => "BUFFER" .buffer => "BUFFER",
}; };
writer.print("{s} @ ({d}, {d}) enabled={}", .{ writer.print("{s} @ ({d}, {d}) enabled={}", .{ type_name, node.x, node.y, node.enabled }) catch unreachable;
type_name,
node.x,
node.y,
node.enabled
}) catch unreachable;
// Add associated data if present // Add associated data if present
if (node.data) |data| { if (node.data) |data| {
@ -84,7 +79,7 @@ fn printNode(node: *wlr.SceneNode, depth: usize) void {
if (namespace.len > 0) { if (namespace.len > 0) {
writer.print(" namespace=\"{s}\"", .{namespace}) catch unreachable; writer.print(" namespace=\"{s}\"", .{namespace}) catch unreachable;
} }
} },
} }
} }

View file

@ -53,14 +53,14 @@ pub fn init(device: *wlr.InputDevice) *Keyboard {
self.wlr_keyboard.data = self; self.wlr_keyboard.data = self;
std.log.err("Adding new keyboard {s}", .{device.name orelse "(unnamed)"}); std.log.err("Adding new keyboard {s}", .{device.name orelse "(unnamed)"});
if(!server.seat.keyboard_group.wlr_group.addKeyboard(self.wlr_keyboard)) { if (!server.seat.keyboard_group.wlr_group.addKeyboard(self.wlr_keyboard)) {
std.log.err("Adding new keyboard {s} failed", .{device.name orelse "(unnamed)"}); std.log.err("Adding new keyboard {s} failed", .{device.name orelse "(unnamed)"});
} }
return self; return self;
} }
pub fn deinit (self: *Keyboard) void { pub fn deinit(self: *Keyboard) void {
self.key.link.remove(); self.key.link.remove();
self.key_map.link.remove(); self.key_map.link.remove();
self.modifiers.link.remove(); self.modifiers.link.remove();
@ -99,9 +99,7 @@ fn handleKey(listener: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboa
} }
} }
if (handled and keyboard.wlr_keyboard.repeat_info.delay > 0) { if (handled and keyboard.wlr_keyboard.repeat_info.delay > 0) {}
}
if (!handled) { if (!handled) {
server.seat.wlr_seat.setKeyboard(&server.seat.keyboard_group.wlr_group.keyboard); server.seat.wlr_seat.setKeyboard(&server.seat.keyboard_group.wlr_group.keyboard);
@ -109,11 +107,7 @@ fn handleKey(listener: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboa
} }
} }
pub fn keypress( pub fn keypress(modifiers: wlr.Keyboard.ModifierMask, sym: xkb.Keysym, state: wl.Keyboard.KeyState) bool {
modifiers: wlr.Keyboard.ModifierMask,
sym: xkb.Keysym,
state: wl.Keyboard.KeyState
) bool {
if (server.keymaps.get(Keymap.hash(modifiers, sym))) |map| { if (server.keymaps.get(Keymap.hash(modifiers, sym))) |map| {
if (state == .pressed and map.options.lua_press_ref_idx > 0) { if (state == .pressed and map.options.lua_press_ref_idx > 0) {
map.callback(false); map.callback(false);

View file

@ -45,7 +45,8 @@ fn handleRepeat(data: ?*KeyboardGroup) c_int {
if (data.?.repeat_source == null) return 0; if (data.?.repeat_source == null) return 0;
if (data == null or data.?.keysyms == null or data.?.modifiers == null or if (data == null or data.?.keysyms == null or data.?.modifiers == null or
data.?.wlr_group.keyboard.repeat_info.rate <= 0) { data.?.wlr_group.keyboard.repeat_info.rate <= 0)
{
return 0; return 0;
} }

View file

@ -31,16 +31,16 @@ pub fn init(wlr_layer_surface: *wlr.LayerSurfaceV1) *LayerSurface {
.output = undefined, .output = undefined,
.wlr_layer_surface = wlr_layer_surface, .wlr_layer_surface = wlr_layer_surface,
.scene_layer_surface = undefined, .scene_layer_surface = undefined,
.scene_node_data = .{ .layer_surface = self } .scene_node_data = .{ .layer_surface = self },
}; };
if(wlr_layer_surface.output.?.data == null) { if (wlr_layer_surface.output.?.data == null) {
std.log.err("Wlr_output arbitrary data not assigned", .{}); std.log.err("Wlr_output arbitrary data not assigned", .{});
unreachable; unreachable;
} }
self.output = @ptrCast(@alignCast(wlr_layer_surface.output.?.data)); self.output = @ptrCast(@alignCast(wlr_layer_surface.output.?.data));
if(server.seat.focused_output) |output| { if (server.seat.focused_output) |output| {
self.scene_layer_surface = switch (wlr_layer_surface.current.layer) { self.scene_layer_surface = switch (wlr_layer_surface.current.layer) {
.background => try output.layers.background.createSceneLayerSurfaceV1(wlr_layer_surface), .background => try output.layers.background.createSceneLayerSurfaceV1(wlr_layer_surface),
.bottom => try output.layers.bottom.createSceneLayerSurfaceV1(wlr_layer_surface), .bottom => try output.layers.bottom.createSceneLayerSurfaceV1(wlr_layer_surface),
@ -49,7 +49,7 @@ pub fn init(wlr_layer_surface: *wlr.LayerSurfaceV1) *LayerSurface {
else => { else => {
std.log.err("New layer surface of unidentified type", .{}); std.log.err("New layer surface of unidentified type", .{});
unreachable; unreachable;
} },
}; };
} }
@ -77,27 +77,18 @@ pub fn deinit(self: *LayerSurface) void {
pub fn allowKeyboard(self: *LayerSurface) void { pub fn allowKeyboard(self: *LayerSurface) void {
const keyboard_interactive = self.wlr_layer_surface.current.keyboard_interactive; const keyboard_interactive = self.wlr_layer_surface.current.keyboard_interactive;
if(keyboard_interactive == .exclusive or keyboard_interactive == .on_demand) { if (keyboard_interactive == .exclusive or keyboard_interactive == .on_demand) {
server.seat.wlr_seat.keyboardNotifyEnter( server.seat.wlr_seat.keyboardNotifyEnter(self.wlr_layer_surface.surface, &server.seat.keyboard_group.wlr_group.keyboard.keycodes, &server.seat.keyboard_group.wlr_group.keyboard.modifiers);
self.wlr_layer_surface.surface,
&server.seat.keyboard_group.wlr_group.keyboard.keycodes,
&server.seat.keyboard_group.wlr_group.keyboard.modifiers
);
} }
} }
// --------- LayerSurface event handlers --------- // --------- LayerSurface event handlers ---------
fn handleDestroy( fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfaceV1) void {
listener: *wl.Listener(*wlr.LayerSurfaceV1),
_: *wlr.LayerSurfaceV1
) void {
const layer: *LayerSurface = @fieldParentPtr("destroy", listener); const layer: *LayerSurface = @fieldParentPtr("destroy", listener);
layer.deinit(); layer.deinit();
} }
fn handleMap( fn handleMap(listener: *wl.Listener(void)) void {
listener: *wl.Listener(void)
) void {
const layer_suraface: *LayerSurface = @fieldParentPtr("map", listener); const layer_suraface: *LayerSurface = @fieldParentPtr("map", listener);
std.log.debug("layer surface mapped", .{}); std.log.debug("layer surface mapped", .{});
layer_suraface.output.arrangeLayers(); layer_suraface.output.arrangeLayers();
@ -120,10 +111,7 @@ fn handleUnmap(listener: *wl.Listener(void)) void {
layer_surface.deinit(); layer_surface.deinit();
} }
fn handleCommit( fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
listener: *wl.Listener(*wlr.Surface),
_: *wlr.Surface
) void {
const layer_surface: *LayerSurface = @fieldParentPtr("commit", listener); const layer_surface: *LayerSurface = @fieldParentPtr("commit", listener);
if (!layer_surface.wlr_layer_surface.initial_commit) return; if (!layer_surface.wlr_layer_surface.initial_commit) return;

View file

@ -33,7 +33,7 @@ layers: struct {
content: *wlr.SceneTree, content: *wlr.SceneTree,
top: *wlr.SceneTree, top: *wlr.SceneTree,
fullscreen: *wlr.SceneTree, fullscreen: *wlr.SceneTree,
overlay: *wlr.SceneTree overlay: *wlr.SceneTree,
}, },
layer_scene_node_data: struct { layer_scene_node_data: struct {
@ -42,14 +42,13 @@ layer_scene_node_data: struct {
content: SceneNodeData, content: SceneNodeData,
top: SceneNodeData, top: SceneNodeData,
fullscreen: SceneNodeData, fullscreen: SceneNodeData,
overlay: SceneNodeData overlay: SceneNodeData,
}, },
frame: wl.Listener(*wlr.Output) = .init(handleFrame), frame: wl.Listener(*wlr.Output) = .init(handleFrame),
request_state: wl.Listener(*wlr.Output.event.RequestState) = .init(handleRequestState), request_state: wl.Listener(*wlr.Output.event.RequestState) = .init(handleRequestState),
destroy: wl.Listener(*wlr.Output) = .init(handleDestroy), destroy: wl.Listener(*wlr.Output) = .init(handleDestroy),
// The wlr.Output should be destroyed by the caller on failure to trigger cleanup. // The wlr.Output should be destroyed by the caller on failure to trigger cleanup.
pub fn init(wlr_output: *wlr.Output) ?*Output { pub fn init(wlr_output: *wlr.Output) ?*Output {
errdefer Utils.oomPanic(); errdefer Utils.oomPanic();
@ -62,6 +61,7 @@ pub fn init(wlr_output: *wlr.Output) ?*Output {
.wlr_output = wlr_output, .wlr_output = wlr_output,
.tree = try server.root.scene.tree.createSceneTree(), .tree = try server.root.scene.tree.createSceneTree(),
.fullscreen = null, .fullscreen = null,
.layers = .{ .layers = .{
.background = try self.tree.createSceneTree(), .background = try self.tree.createSceneTree(),
.bottom = try self.tree.createSceneTree(), .bottom = try self.tree.createSceneTree(),
@ -70,14 +70,16 @@ pub fn init(wlr_output: *wlr.Output) ?*Output {
.fullscreen = try self.tree.createSceneTree(), .fullscreen = try self.tree.createSceneTree(),
.overlay = try self.tree.createSceneTree(), .overlay = try self.tree.createSceneTree(),
}, },
.layer_scene_node_data = .{ .layer_scene_node_data = .{
.background = .{ .output_layer = self.layers.background }, .background = .{ .output_layer = self.layers.background },
.bottom = .{ .output_layer = self.layers.bottom }, .bottom = .{ .output_layer = self.layers.bottom },
.content = .{ .output_layer = self.layers.content }, .content = .{ .output_layer = self.layers.content },
.top = .{ .output_layer = self.layers.top }, .top = .{ .output_layer = self.layers.top },
.fullscreen = .{ .output_layer = self.layers.fullscreen }, .fullscreen = .{ .output_layer = self.layers.fullscreen },
.overlay = .{ .output_layer = self.layers.overlay } .overlay = .{ .output_layer = self.layers.overlay },
}, },
.scene_output = try server.root.scene.createSceneOutput(wlr_output), .scene_output = try server.root.scene.createSceneOutput(wlr_output),
.scene_node_data = SceneNodeData{ .output = self }, .scene_node_data = SceneNodeData{ .output = self },
.state = wlr.Output.State.init() .state = wlr.Output.State.init()
@ -89,7 +91,7 @@ pub fn init(wlr_output: *wlr.Output) ?*Output {
errdefer deinit(self); errdefer deinit(self);
if(!wlr_output.initRender(server.allocator, server.renderer)) { if (!wlr_output.initRender(server.allocator, server.renderer)) {
std.log.err("Unable to start output {s}", .{wlr_output.name}); std.log.err("Unable to start output {s}", .{wlr_output.name});
return null; return null;
} }
@ -100,7 +102,7 @@ pub fn init(wlr_output: *wlr.Output) ?*Output {
self.state.setMode(mode); self.state.setMode(mode);
} }
if(!wlr_output.commitState(&self.state)) { if (!wlr_output.commitState(&self.state)) {
std.log.err("Unable to commit state to output {s}", .{wlr_output.name}); std.log.err("Unable to commit state to output {s}", .{wlr_output.name});
return null; return null;
} }
@ -142,7 +144,7 @@ pub fn deinit(self: *Output) void {
} }
pub fn setFocused(self: *Output) void { pub fn setFocused(self: *Output) void {
if(server.seat.focused_output) |prev_output| { if (server.seat.focused_output) |prev_output| {
prev_output.focused = false; prev_output.focused = false;
} }
@ -172,21 +174,18 @@ pub fn configureLayers(self: *Output) void {
}; };
var it = tree.children.iterator(.forward); var it = tree.children.iterator(.forward);
while(it.next()) |node| { while (it.next()) |node| {
if(node.data == null) continue; if (node.data == null) continue;
const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?)); const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?));
switch (scene_node_data.*) { switch (scene_node_data.*) {
.layer_surface => { .layer_surface => {
_ = scene_node_data.layer_surface.wlr_layer_surface.configured( _ = scene_node_data.layer_surface.wlr_layer_surface.configured(@intCast(output_box.width), @intCast(output_box.height));
@intCast(output_box.width),
@intCast(output_box.height)
);
}, },
else => { else => {
std.log.err("Something other than a layer surface found in layer surface scene trees", .{}); std.log.err("Something other than a layer surface found in layer surface scene trees", .{});
unreachable; unreachable;
} },
} }
} }
} }
@ -203,18 +202,11 @@ pub fn surfaceAt(self: *Output, lx: f64, ly: f64) ?SurfaceAtResult {
var sx: f64 = undefined; var sx: f64 = undefined;
var sy: f64 = undefined; var sy: f64 = undefined;
const layers = [_]*wlr.SceneTree{ const layers = [_]*wlr.SceneTree{ self.layers.top, self.layers.overlay, self.layers.fullscreen, self.layers.content, self.layers.bottom, self.layers.background };
self.layers.top,
self.layers.overlay,
self.layers.fullscreen,
self.layers.content,
self.layers.bottom,
self.layers.background
};
for(layers) |layer| { for (layers) |layer| {
const node = layer.node.at(lx, ly, &sx, &sy); const node = layer.node.at(lx, ly, &sx, &sy);
if(node == null) continue; if (node == null) continue;
const surface: ?*wlr.Surface = blk: { const surface: ?*wlr.Surface = blk: {
if (node.?.type == .buffer) { if (node.?.type == .buffer) {
@ -225,7 +217,7 @@ pub fn surfaceAt(self: *Output, lx: f64, ly: f64) ?SurfaceAtResult {
} }
break :blk null; break :blk null;
}; };
if(surface == null) continue; if (surface == null) continue;
const scene_node_data: *SceneNodeData = blk: { const scene_node_data: *SceneNodeData = blk: {
var n = node.?; var n = node.?;
@ -250,7 +242,7 @@ pub fn surfaceAt(self: *Output, lx: f64, ly: f64) ?SurfaceAtResult {
.sy = sy, .sy = sy,
}; };
}, },
else => continue else => continue,
} }
} }
@ -258,14 +250,14 @@ pub fn surfaceAt(self: *Output, lx: f64, ly: f64) ?SurfaceAtResult {
} }
pub fn getFullscreenedView(self: *Output) ?*View { pub fn getFullscreenedView(self: *Output) ?*View {
if(self.layers.fullscreen.children.length() != 1) { if (self.layers.fullscreen.children.length() != 1) {
return null; return null;
} }
var it = self.layers.fullscreen.children.iterator(.forward); var it = self.layers.fullscreen.children.iterator(.forward);
if(it.next().?.data) |data| { if (it.next().?.data) |data| {
const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(data)); const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(data));
if(scene_node_data.* == .view) { if (scene_node_data.* == .view) {
return scene_node_data.view; return scene_node_data.view;
} }
} }
@ -286,13 +278,10 @@ fn handleRequestState(
server.events.exec("OutputStateChange", .{}); server.events.exec("OutputStateChange", .{});
} }
fn handleFrame( fn handleFrame(_: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
_: *wl.Listener(*wlr.Output),
wlr_output: *wlr.Output
) void {
const scene_output = server.root.scene.getSceneOutput(wlr_output); const scene_output = server.root.scene.getSceneOutput(wlr_output);
if(scene_output == null) { if (scene_output == null) {
std.log.err("Unable to get scene output to render", .{}); std.log.err("Unable to get scene output to render", .{});
return; return;
} }
@ -304,10 +293,7 @@ fn handleFrame(
scene_output.?.sendFrameDone(&now); scene_output.?.sendFrameDone(&now);
} }
fn handleDestroy( fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
listener: *wl.Listener(*wlr.Output),
_: *wlr.Output
) void {
std.log.debug("Handling destroy", .{}); std.log.debug("Handling destroy", .{});
const output: *Output = @fieldParentPtr("destroy", listener); const output: *Output = @fieldParentPtr("destroy", listener);
@ -336,14 +322,14 @@ pub fn arrangeLayers(self: *Output) void {
var it = layer.children.safeIterator(.forward); var it = layer.children.safeIterator(.forward);
while (it.next()) |node| { while (it.next()) |node| {
if(node.data == null) continue; if (node.data == null) continue;
// if (@as(?*SceneNodeData, @alignCast(@ptrCast(node.data)))) |node_data| { // if (@as(?*SceneNodeData, @alignCast(@ptrCast(node.data)))) |node_data| {
const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?)); const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?));
const layer_surface: *LayerSurface = switch(scene_node_data.*) { const layer_surface: *LayerSurface = switch (scene_node_data.*) {
.layer_surface => @fieldParentPtr("scene_node_data", scene_node_data), .layer_surface => @fieldParentPtr("scene_node_data", scene_node_data),
else => continue else => continue,
}; };
if (!layer_surface.wlr_layer_surface.initialized) continue; if (!layer_surface.wlr_layer_surface.initialized) continue;

View file

@ -49,9 +49,9 @@ pub fn create(client: *wl.Client, version: u32, id: u32) !void {
} }
fn handleRequest( fn handleRequest(
remote_lua_v1: *mez.RemoteLuaV1, remote_lua_v1: *mez.RemoteLuaV1,
request: mez.RemoteLuaV1.Request, request: mez.RemoteLuaV1.Request,
remote: *RemoteLua, remote: *RemoteLua,
) void { ) void {
const L = remote.L; const L = remote.L;
switch (request) { switch (request) {
@ -75,7 +75,9 @@ remote: *RemoteLua,
return; return;
}; };
L.protectedCall(.{ .results = zlua.mult_return, }) catch { L.protectedCall(.{
.results = zlua.mult_return,
}) catch {
catchLuaFail(remote); catchLuaFail(remote);
L.pop(1); L.pop(1);
}; };

View file

@ -29,9 +29,9 @@ fn bind(client: *wl.Client, _: ?*anyopaque, version: u32, id: u32) void {
} }
fn handleRequest( fn handleRequest(
remote_lua_manager_v1: *mez.RemoteLuaManagerV1, remote_lua_manager_v1: *mez.RemoteLuaManagerV1,
request: mez.RemoteLuaManagerV1.Request, request: mez.RemoteLuaManagerV1.Request,
_: ?*anyopaque, _: ?*anyopaque,
) void { ) void {
switch (request) { switch (request) {
.destroy => remote_lua_manager_v1.destroy(), .destroy => remote_lua_manager_v1.destroy(),

View file

@ -1,5 +1,4 @@
/// The root of Mezzaluna is, you guessed it, the root of many of the systems mez needs: /// The root of Mezzaluna is, you guessed it, the root of many of the systems mez needs:
const Root = @This(); const Root = @This();
const std = @import("std"); const std = @import("std");
@ -50,18 +49,18 @@ pub fn init(self: *Root) void {
pub fn deinit(self: *Root) void { pub fn deinit(self: *Root) void {
var it = self.scene.tree.children.iterator(.forward); var it = self.scene.tree.children.iterator(.forward);
while(it.next()) |node| { while (it.next()) |node| {
if(node.data == null) continue; if (node.data == null) continue;
const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?)); const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?));
switch(scene_node_data.*) { switch (scene_node_data.*) {
.output => { .output => {
scene_node_data.output.deinit(); scene_node_data.output.deinit();
}, },
else => { else => {
std.log.debug("The root has a child that is not an output", .{}); std.log.debug("The root has a child that is not an output", .{});
unreachable; unreachable;
} },
} }
} }
@ -73,8 +72,8 @@ pub fn deinit(self: *Root) void {
pub fn viewById(self: *Root, id: u64) ?*View { pub fn viewById(self: *Root, id: u64) ?*View {
var output_it = self.output_layout.outputs.iterator(.forward); var output_it = self.output_layout.outputs.iterator(.forward);
while(output_it.next()) |o| { while (output_it.next()) |o| {
if(o.output.data == null) { if (o.output.data == null) {
std.log.err("Wlr_output arbitrary data not assigned", .{}); std.log.err("Wlr_output arbitrary data not assigned", .{});
unreachable; unreachable;
} }
@ -82,21 +81,21 @@ pub fn viewById(self: *Root, id: u64) ?*View {
const output: *Output = @ptrCast(@alignCast(o.output.data.?)); const output: *Output = @ptrCast(@alignCast(o.output.data.?));
var node_it = output.layers.content.children.iterator(.forward); var node_it = output.layers.content.children.iterator(.forward);
while(node_it.next()) |node| { while (node_it.next()) |node| {
if(node.data == null) continue; if (node.data == null) continue;
const view_snd: *SceneNodeData = @ptrCast(@alignCast(node.data.?)); const view_snd: *SceneNodeData = @ptrCast(@alignCast(node.data.?));
// TODO: Should we assert that we want only views to be here // TODO: Should we assert that we want only views to be here
// -- Basically should we use switch statements for snd interactions // -- Basically should we use switch statements for snd interactions
// -- Or if statements, for simplicity // -- Or if statements, for simplicity
if(view_snd.* == .view and view_snd.view.id == id) { if (view_snd.* == .view and view_snd.view.id == id) {
return view_snd.view; return view_snd.view;
} }
} }
if(output.fullscreen) |fullscreen| { if (output.fullscreen) |fullscreen| {
if(fullscreen.id == id) return fullscreen; if (fullscreen.id == id) return fullscreen;
} }
} }
@ -106,11 +105,11 @@ pub fn viewById(self: *Root, id: u64) ?*View {
pub fn outputById(self: *Root, id: u64) ?*Output { pub fn outputById(self: *Root, id: u64) ?*Output {
var it = self.scene.outputs.iterator(.forward); var it = self.scene.outputs.iterator(.forward);
while(it.next()) |scene_output| { while (it.next()) |scene_output| {
if(scene_output.output.data == null) continue; if (scene_output.output.data == null) continue;
const output: *Output = @as(*Output, @ptrCast(@alignCast(scene_output.output.data.?))); const output: *Output = @as(*Output, @ptrCast(@alignCast(scene_output.output.data.?)));
if(output.id == id) return output; if (output.id == id) return output;
} }
return null; return null;

View file

@ -5,10 +5,4 @@ const LayerSurface = @import("LayerSurface.zig");
const Output = @import("Output.zig"); const Output = @import("Output.zig");
const Root = @import("Root.zig"); const Root = @import("Root.zig");
pub const SceneNodeData = union(enum) { pub const SceneNodeData = union(enum) { view: *View, layer_surface: *LayerSurface, output: *Output, output_layer: *wlr.SceneTree, root: *Root };
view: *View,
layer_surface: *LayerSurface,
output: *Output,
output_layer: *wlr.SceneTree,
root: *Root
};

View file

@ -101,26 +101,26 @@ pub fn focusSurface(self: *Seat, to_focus: ?FocusData) void {
const current_surface = current_focus.getSurface(); const current_surface = current_focus.getSurface();
if (current_surface == surface) return; // Same surface if (current_surface == surface) return; // Same surface
if(to_focus != null) { if (to_focus != null) {
switch (current_focus) { switch (current_focus) {
.layer_surface => |*current_layer_surface| { .layer_surface => |*current_layer_surface| {
if(current_layer_surface.*.wlr_layer_surface.current.keyboard_interactive == .exclusive) return; if (current_layer_surface.*.wlr_layer_surface.current.keyboard_interactive == .exclusive) return;
}, },
.view => |*current_view| { .view => |*current_view| {
if(current_view.*.fullscreen) { if (current_view.*.fullscreen) {
switch (to_focus.?) { switch (to_focus.?) {
.layer_surface => |*layer_surface| { .layer_surface => |*layer_surface| {
const layer = layer_surface.*.wlr_layer_surface.current.layer; const layer = layer_surface.*.wlr_layer_surface.current.layer;
if(layer == .background or layer == .bottom) return; if (layer == .background or layer == .bottom) return;
}, },
.view => |*view| { .view => |*view| {
if(!view.*.fullscreen) return; if (!view.*.fullscreen) return;
},
} }
} }
},
} }
} } else if (current_focus == .view and current_focus.view.fullscreen) {
}
} else if(current_focus == .view and current_focus.view.fullscreen){
return; return;
} }
@ -128,23 +128,18 @@ pub fn focusSurface(self: *Seat, to_focus: ?FocusData) void {
switch (current_focus) { switch (current_focus) {
.layer_surface => {}, // IDK if we actually have to clear any focus here .layer_surface => {}, // IDK if we actually have to clear any focus here
else => { else => {
if(wlr.XdgSurface.tryFromWlrSurface(current_surface)) |xdg_surface| { if (wlr.XdgSurface.tryFromWlrSurface(current_surface)) |xdg_surface| {
_ = xdg_surface.role_data.toplevel.?.setActivated(false); _ = xdg_surface.role_data.toplevel.?.setActivated(false);
} }
} },
} }
} }
if (to_focus != null) {
if(to_focus != null) { server.seat.wlr_seat.keyboardNotifyEnter(surface.?, &server.seat.keyboard_group.wlr_group.keyboard.keycodes, &server.seat.keyboard_group.wlr_group.keyboard.modifiers);
server.seat.wlr_seat.keyboardNotifyEnter( if (to_focus.? != .layer_surface) {
surface.?, if (to_focus.? == .view) to_focus.?.view.focused = true;
&server.seat.keyboard_group.wlr_group.keyboard.keycodes, if (wlr.XdgSurface.tryFromWlrSurface(surface.?)) |xdg_surface| {
&server.seat.keyboard_group.wlr_group.keyboard.modifiers
);
if(to_focus.? != .layer_surface) {
if(to_focus.? == .view) to_focus.?.view.focused = true;
if(wlr.XdgSurface.tryFromWlrSurface(surface.?)) |xdg_surface| {
_ = xdg_surface.role_data.toplevel.?.setActivated(true); _ = xdg_surface.role_data.toplevel.?.setActivated(true);
} }
} }
@ -153,7 +148,7 @@ pub fn focusSurface(self: *Seat, to_focus: ?FocusData) void {
} }
pub fn focusOutput(self: *Seat, output: *Output) void { pub fn focusOutput(self: *Seat, output: *Output) void {
if(server.seat.focused_output) |prev_output| { if (server.seat.focused_output) |prev_output| {
prev_output.focused = false; prev_output.focused = false;
} }

View file

@ -167,18 +167,12 @@ pub fn deinit(self: *Server) noreturn {
} }
// --------- Backend event handlers --------- // --------- Backend event handlers ---------
fn handleNewInput( fn handleNewInput(_: *wl.Listener(*wlr.InputDevice), device: *wlr.InputDevice) void {
_: *wl.Listener(*wlr.InputDevice),
device: *wlr.InputDevice
) void {
switch (device.type) { switch (device.type) {
.keyboard => _ = Keyboard.init(device), .keyboard => _ = Keyboard.init(device),
.pointer => server.cursor.wlr_cursor.attachInputDevice(device), .pointer => server.cursor.wlr_cursor.attachInputDevice(device),
else => { else => {
std.log.err( std.log.err("New input request for input that is not a keyboard or pointer: {s}", .{device.name orelse "(null)"});
"New input request for input that is not a keyboard or pointer: {s}",
.{device.name orelse "(null)"}
);
}, },
} }
@ -189,25 +183,16 @@ fn handleNewInput(
}); });
} }
fn handleNewOutput( fn handleNewOutput(_: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
_: *wl.Listener(*wlr.Output),
wlr_output: *wlr.Output
) void {
_ = Output.init(wlr_output); _ = Output.init(wlr_output);
} }
fn handleNewXdgToplevel( fn handleNewXdgToplevel(_: *wl.Listener(*wlr.XdgToplevel), xdg_toplevel: *wlr.XdgToplevel) void {
_: *wl.Listener(*wlr.XdgToplevel),
xdg_toplevel: *wlr.XdgToplevel
) void {
_ = View.init(xdg_toplevel); _ = View.init(xdg_toplevel);
} }
fn handleNewXdgToplevelDecoration( fn handleNewXdgToplevelDecoration(_: *wl.Listener(*wlr.XdgToplevelDecorationV1), decoration: *wlr.XdgToplevelDecorationV1) void {
_: *wl.Listener(*wlr.XdgToplevelDecorationV1), if (server.root.viewById(@intFromPtr(decoration.toplevel))) |view| {
decoration: *wlr.XdgToplevelDecorationV1
) void {
if(server.root.viewById(@intFromPtr(decoration.toplevel))) |view| {
view.xdg_toplevel_decoration = decoration; view.xdg_toplevel_decoration = decoration;
} }
} }
@ -216,10 +201,7 @@ fn handleNewXdgPopup(_: *wl.Listener(*wlr.XdgPopup), _: *wlr.XdgPopup) void {
std.log.debug("Unimplemented Server.handleNewXdgPopup\n", .{}); std.log.debug("Unimplemented Server.handleNewXdgPopup\n", .{});
} }
fn handleNewLayerSurface( fn handleNewLayerSurface(_: *wl.Listener(*wlr.LayerSurfaceV1), layer_surface: *wlr.LayerSurfaceV1) void {
_: *wl.Listener(*wlr.LayerSurfaceV1),
layer_surface: *wlr.LayerSurfaceV1
) void {
std.log.debug("requested layer shell\n", .{}); std.log.debug("requested layer shell\n", .{});
if (layer_surface.output == null) { if (layer_surface.output == null) {
if (server.seat.focused_output == null) { if (server.seat.focused_output == null) {
@ -238,13 +220,13 @@ fn handleRequestActivate(
_: *wl.Listener(*wlr.XdgActivationV1.event.RequestActivate), _: *wl.Listener(*wlr.XdgActivationV1.event.RequestActivate),
event: *wlr.XdgActivationV1.event.RequestActivate, event: *wlr.XdgActivationV1.event.RequestActivate,
) void { ) void {
if(event.surface.data == null) return; if (event.surface.data == null) return;
const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(event.surface.data.?)); const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(event.surface.data.?));
if(scene_node_data.* == .view) { if (scene_node_data.* == .view) {
if(server.seat.focused_output) |output| { if (server.seat.focused_output) |output| {
if(output.fullscreen) |fullscreen| { if (output.fullscreen) |fullscreen| {
server.seat.focusSurface(.{ .view = fullscreen }); server.seat.focusSurface(.{ .view = fullscreen });
return; return;
} }

View file

@ -68,19 +68,17 @@ pub fn init(xdg_toplevel: *wlr.XdgToplevel) *View {
.id = @intFromPtr(xdg_toplevel), .id = @intFromPtr(xdg_toplevel),
.output = null, .output = null,
.geometry = .{ .width = 0, .height = 0, .x = 0, .y = 0 }, .geometry = .{ .width = 0, .height = 0, .x = 0, .y = 0 },
.xdg_toplevel = xdg_toplevel, .xdg_toplevel = xdg_toplevel,
.scene_tree = undefined, .scene_tree = undefined,
.surface_tree = undefined, .surface_tree = undefined,
.xdg_toplevel_decoration = null, .xdg_toplevel_decoration = null,
.borders = undefined, .borders = undefined,
.border_width = 0, .border_width = 0,
.scene_node_data = .{ .view = self },
.scene_node_data = .{ .view = self }
}; };
// Add new Toplevel to root of the tree // Add new Toplevel to root of the tree
if(server.seat.focused_output) |output| { if (server.seat.focused_output) |output| {
self.scene_tree = try output.layers.content.createSceneTree(); self.scene_tree = try output.layers.content.createSceneTree();
self.surface_tree = try self.scene_tree.createSceneXdgSurface(xdg_toplevel.base); self.surface_tree = try self.scene_tree.createSceneXdgSurface(xdg_toplevel.base);
self.output = output; self.output = output;
@ -117,10 +115,10 @@ pub fn setBorderColor(self: *View, color: *const [4]f32) void {
pub fn toggleFullscreen(self: *View) void { pub fn toggleFullscreen(self: *View) void {
self.fullscreen = !self.fullscreen; self.fullscreen = !self.fullscreen;
if(self.output) |output| { if (self.output) |output| {
if(self.fullscreen and output.fullscreen != self) { if (self.fullscreen and output.fullscreen != self) {
// Check to see if another fullscreened view exists, if so replace it // Check to see if another fullscreened view exists, if so replace it
if(output.getFullscreenedView()) |view| { if (output.getFullscreenedView()) |view| {
view.toggleFullscreen(); view.toggleFullscreen();
} }
@ -263,7 +261,9 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
// 5 is the XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION, I'm just not sure where it is in the bindings // 5 is the XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION, I'm just not sure where it is in the bindings
if (view.xdg_toplevel.base.client.shell.version >= 5) { if (view.xdg_toplevel.base.client.shell.version >= 5) {
// the client should know that it can only fullscreen, nothing else // the client should know that it can only fullscreen, nothing else
_ = view.xdg_toplevel.setWmCapabilities(.{ .fullscreen = true, }); _ = view.xdg_toplevel.setWmCapabilities(.{
.fullscreen = true,
});
} }
// before committing we tell the client that we'll handle the decorations // before committing we tell the client that we'll handle the decorations
@ -285,18 +285,12 @@ fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), xdg_popup: *wlr.XdgPopu
_ = Popup.init(xdg_popup, view.scene_tree); _ = Popup.init(xdg_popup, view.scene_tree);
} }
fn handleRequestMove( fn handleRequestMove(listener: *wl.Listener(*wlr.XdgToplevel.event.Move), _: *wlr.XdgToplevel.event.Move) void {
listener: *wl.Listener(*wlr.XdgToplevel.event.Move),
_: *wlr.XdgToplevel.event.Move
) void {
const view: *View = @fieldParentPtr("request_move", listener); const view: *View = @fieldParentPtr("request_move", listener);
server.events.exec("ViewRequestMove", .{view.id}); server.events.exec("ViewRequestMove", .{view.id});
} }
fn handleRequestResize( fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), _: *wlr.XdgToplevel.event.Resize) void {
listener: *wl.Listener(*wlr.XdgToplevel.event.Resize),
_: *wlr.XdgToplevel.event.Resize
) void {
const view: *View = @fieldParentPtr("request_resize", listener); const view: *View = @fieldParentPtr("request_resize", listener);
server.events.exec("ViewRequestResize", .{view.id}); server.events.exec("ViewRequestResize", .{view.id});
} }
@ -310,32 +304,24 @@ fn handleAckConfigure(
std.log.err("Unimplemented ack configure", .{}); std.log.err("Unimplemented ack configure", .{});
} }
fn handleRequestFullscreen( fn handleRequestFullscreen(listener: *wl.Listener(void)) void {
listener: *wl.Listener(void)
) void {
const view: *View = @fieldParentPtr("request_fullscreen", listener); const view: *View = @fieldParentPtr("request_fullscreen", listener);
server.events.exec("ViewRequestFullscreen", .{view.id}); server.events.exec("ViewRequestFullscreen", .{view.id});
} }
fn handleRequestMinimize( fn handleRequestMinimize(listener: *wl.Listener(void)) void {
listener: *wl.Listener(void)
) void {
const view: *View = @fieldParentPtr("request_minimize", listener); const view: *View = @fieldParentPtr("request_minimize", listener);
server.events.exec("ViewRequestMinimize", .{view.id}); server.events.exec("ViewRequestMinimize", .{view.id});
std.log.debug("request_minimize unimplemented", .{}); std.log.debug("request_minimize unimplemented", .{});
} }
fn handleSetAppId( fn handleSetAppId(listener: *wl.Listener(void)) void {
listener: *wl.Listener(void)
) void {
const view: *View = @fieldParentPtr("set_app_id", listener); const view: *View = @fieldParentPtr("set_app_id", listener);
server.events.exec("ViewAppIdUpdate", .{view.id}); server.events.exec("ViewAppIdUpdate", .{view.id});
std.log.debug("request_set_app_id unimplemented", .{}); std.log.debug("request_set_app_id unimplemented", .{});
} }
fn handleSetTitle( fn handleSetTitle(listener: *wl.Listener(void)) void {
listener: *wl.Listener(void)
) void {
const view: *View = @fieldParentPtr("set_title", listener); const view: *View = @fieldParentPtr("set_title", listener);
server.events.exec("ViewTitleUpdate", .{view.id}); server.events.exec("ViewTitleUpdate", .{view.id});
std.log.debug("request_set_title unimplemented", .{}); std.log.debug("request_set_title unimplemented", .{});

View file

@ -51,7 +51,7 @@ pub fn setBaseConfig(self: *zlua.Lua, path: []const u8) !void {
_ = try self.getGlobal("mez"); _ = try self.getGlobal("mez");
_ = self.getField(-1, "path"); _ = self.getField(-1, "path");
defer self.pop(2); defer self.pop(2);
const new_path = try std.fs.path.join(gpa, &[_][]const u8{path, "init.lua"}); const new_path = try std.fs.path.join(gpa, &[_][]const u8{ path, "init.lua" });
defer gpa.free(new_path); defer gpa.free(new_path);
_ = self.pushString(new_path); _ = self.pushString(new_path);
self.setField(-2, "config"); self.setField(-2, "config");
@ -148,7 +148,10 @@ pub fn openLibs(self: *zlua.Lua) void {
} }
} }
pub const Config = struct { str: ?[]const u8, enabled: bool, }; pub const Config = struct {
str: ?[]const u8,
enabled: bool,
};
pub fn init(self: *Lua, cfg: Config) !void { pub fn init(self: *Lua, cfg: Config) !void {
self.state = try zlua.Lua.init(gpa); self.state = try zlua.Lua.init(gpa);
errdefer self.state.deinit(); errdefer self.state.deinit();

View file

@ -50,8 +50,8 @@ pub fn toStringEx(L: *zlua.Lua) [:0]const u8 {
pub fn viewById(view_id: u64) ?*View { pub fn viewById(view_id: u64) ?*View {
if (view_id == 0) { if (view_id == 0) {
if(server.seat.focused_surface) |fs| { if (server.seat.focused_surface) |fs| {
if(fs == .view) return fs.view; if (fs == .view) return fs.view;
} }
} else { } else {
return server.root.viewById(view_id); return server.root.viewById(view_id);

View file

@ -11,7 +11,6 @@ fn output_id_err(L: *zlua.Lua) noreturn {
} }
/// ---@alias output_id integer /// ---@alias output_id integer
/// ---Get the ids for all available outputs /// ---Get the ids for all available outputs
/// ---@return output_id[]? /// ---@return output_id[]?
pub fn get_all_ids(L: *zlua.Lua) i32 { pub fn get_all_ids(L: *zlua.Lua) i32 {
@ -20,8 +19,8 @@ pub fn get_all_ids(L: *zlua.Lua) i32 {
L.newTable(); L.newTable();
while(it.next()) |scene_output| : (index += 1) { while (it.next()) |scene_output| : (index += 1) {
if(scene_output.output.data == null) continue; if (scene_output.output.data == null) continue;
const output = @as(*Output, @ptrCast(@alignCast(scene_output.output.data.?))); const output = @as(*Output, @ptrCast(@alignCast(scene_output.output.data.?)));
@ -36,7 +35,7 @@ pub fn get_all_ids(L: *zlua.Lua) i32 {
/// ---Get the id for the focused output /// ---Get the id for the focused output
/// ---@return output_id? /// ---@return output_id?
pub fn get_focused_id(L: *zlua.Lua) i32 { pub fn get_focused_id(L: *zlua.Lua) i32 {
if(server.seat.focused_output) |output| { if (server.seat.focused_output) |output| {
L.pushInteger(@intCast(output.id)); L.pushInteger(@intCast(output.id));
return 1; return 1;
} }
@ -52,7 +51,7 @@ pub fn get_rate(L: *zlua.Lua) i32 {
const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L); const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L);
const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id); const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
if(output) |o| { if (output) |o| {
L.pushInteger(@intCast(o.wlr_output.refresh)); L.pushInteger(@intCast(o.wlr_output.refresh));
return 1; return 1;
} }
@ -68,7 +67,7 @@ pub fn get_resolution(L: *zlua.Lua) i32 {
const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L); const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L);
const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id); const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
if(output) |o| { if (output) |o| {
L.newTable(); L.newTable();
_ = L.pushString("width"); _ = L.pushString("width");
@ -93,8 +92,8 @@ pub fn get_serial(L: *zlua.Lua) i32 {
const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L); const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L);
const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id); const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
if(output) |o| { if (output) |o| {
if(o.wlr_output.serial == null) { if (o.wlr_output.serial == null) {
L.pushNil(); L.pushNil();
return 1; return 1;
} }
@ -114,8 +113,8 @@ pub fn get_make(L: *zlua.Lua) i32 {
const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L); const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L);
const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id); const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
if(output) |o| { if (output) |o| {
if(o.wlr_output.make == null) { if (o.wlr_output.make == null) {
L.pushNil(); L.pushNil();
return 1; return 1;
} }
@ -135,8 +134,8 @@ pub fn get_model(L: *zlua.Lua) i32 {
const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L); const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L);
const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id); const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
if(output) |o| { if (output) |o| {
if(o.wlr_output.model == null) { if (o.wlr_output.model == null) {
L.pushNil(); L.pushNil();
return 1; return 1;
} }
@ -156,8 +155,8 @@ pub fn get_description(L: *zlua.Lua) i32 {
const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L); const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L);
const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id); const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
if(output) |o| { if (output) |o| {
if(o.wlr_output.description == null) { if (o.wlr_output.description == null) {
L.pushNil(); L.pushNil();
return 1; return 1;
} }
@ -177,7 +176,7 @@ pub fn get_name(L: *zlua.Lua) i32 {
const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L); const output_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch output_id_err(L);
const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id); const output: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
if(output) |o| { if (output) |o| {
_ = L.pushString(std.mem.span(o.wlr_output.name)); _ = L.pushString(std.mem.span(o.wlr_output.name));
return 1; return 1;
} }

View file

@ -25,8 +25,8 @@ pub fn get_all_ids(L: *zlua.Lua) i32 {
var index: i32 = 1; var index: i32 = 1;
L.newTable(); L.newTable();
while(output_it.next()) |o| { while (output_it.next()) |o| {
if(o.output.data == null) { if (o.output.data == null) {
std.log.err("Output arbitrary data not assigned", .{}); std.log.err("Output arbitrary data not assigned", .{});
unreachable; unreachable;
} }
@ -40,26 +40,25 @@ pub fn get_all_ids(L: *zlua.Lua) i32 {
output.layers.fullscreen, output.layers.fullscreen,
}; };
for(layers) |layer| { for (layers) |layer| {
if(layer.children.length() == 0) continue; // No children if (layer.children.length() == 0) continue; // No children
if(@intFromPtr(layer) == 0) { if (@intFromPtr(layer) == 0) {
std.log.err("ts is literally a null ptr", .{}); std.log.err("ts is literally a null ptr", .{});
unreachable; unreachable;
} }
var view_it = layer.children.iterator(.forward); var view_it = layer.children.iterator(.forward);
while(view_it.next()) |v| { while (view_it.next()) |v| {
if (v.data == null) {
if(v.data == null) {
std.log.err("Unassigned arbitrary data in scene graph", .{}); std.log.err("Unassigned arbitrary data in scene graph", .{});
unreachable; unreachable;
} }
const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(v.data.?)); const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(v.data.?));
if(scene_node_data.* == .view) { if (scene_node_data.* == .view) {
L.pushInteger(@intCast(index)); L.pushInteger(@intCast(index));
L.pushInteger(@intCast(scene_node_data.view.id)); L.pushInteger(@intCast(scene_node_data.view.id));
L.setTable(-3); L.setTable(-3);
@ -76,8 +75,8 @@ pub fn get_all_ids(L: *zlua.Lua) i32 {
// ---Get the id for the focused view // ---Get the id for the focused view
// ---@return view_id? // ---@return view_id?
pub fn get_focused_id(L: *zlua.Lua) i32 { pub fn get_focused_id(L: *zlua.Lua) i32 {
if(server.seat.focused_surface) |fs| { if (server.seat.focused_surface) |fs| {
if(fs == .view) { if (fs == .view) {
L.pushInteger(@intCast(fs.view.id)); L.pushInteger(@intCast(fs.view.id));
return 1; return 1;
} }
@ -92,7 +91,7 @@ pub fn get_focused_id(L: *zlua.Lua) i32 {
pub fn close(L: *zlua.Lua) i32 { pub fn close(L: *zlua.Lua) i32 {
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
if(LuaUtils.viewById(view_id)) |v| { if (LuaUtils.viewById(view_id)) |v| {
v.close(); v.close();
} }
@ -109,7 +108,7 @@ pub fn set_position(L: *zlua.Lua) i32 {
const x = LuaUtils.coerceNumber(i32, L.checkNumber(2)) catch L.raiseErrorStr("The x must be > -inf and < inf", .{}); const x = LuaUtils.coerceNumber(i32, L.checkNumber(2)) catch L.raiseErrorStr("The x must be > -inf and < inf", .{});
const y = LuaUtils.coerceNumber(i32, L.checkNumber(3)) catch L.raiseErrorStr("The y must be > -inf and < inf", .{}); const y = LuaUtils.coerceNumber(i32, L.checkNumber(3)) catch L.raiseErrorStr("The y must be > -inf and < inf", .{});
if(LuaUtils.viewById(view_id)) |v| { if (LuaUtils.viewById(view_id)) |v| {
v.setPosition(x, y); v.setPosition(x, y);
} }
@ -153,7 +152,7 @@ pub fn set_size(L: *zlua.Lua) i32 {
const width = LuaUtils.coerceNumber(u32, L.checkNumber(2)) catch L.raiseErrorStr("The width must be >= 0 and < inf", .{}); const width = LuaUtils.coerceNumber(u32, L.checkNumber(2)) catch L.raiseErrorStr("The width must be >= 0 and < inf", .{});
const height = LuaUtils.coerceNumber(u32, L.checkNumber(3)) catch L.raiseErrorStr("The height must be >= 0 and < inf", .{}); const height = LuaUtils.coerceNumber(u32, L.checkNumber(3)) catch L.raiseErrorStr("The height must be >= 0 and < inf", .{});
if(LuaUtils.viewById(view_id)) |v| { if (LuaUtils.viewById(view_id)) |v| {
v.setSize(@intCast(width), @intCast(height)); v.setSize(@intCast(width), @intCast(height));
} }
@ -189,9 +188,9 @@ pub fn get_size(L: *zlua.Lua) i32 {
pub fn set_focused(L: *zlua.Lua) i32 { pub fn set_focused(L: *zlua.Lua) i32 {
const view_id: ?c_longlong = L.optInteger(1); const view_id: ?c_longlong = L.optInteger(1);
if(view_id == null) { if (view_id == null) {
server.seat.focusSurface(null); server.seat.focusSurface(null);
} else if(server.root.viewById(@intCast(view_id.?))) |view| { } else if (server.root.viewById(@intCast(view_id.?))) |view| {
server.seat.focusSurface(.{ .view = view }); server.seat.focusSurface(.{ .view = view });
} }
@ -206,7 +205,7 @@ pub fn toggle_fullscreen(L: *zlua.Lua) i32 {
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
std.log.debug("fullscreen view {d}", .{view_id}); std.log.debug("fullscreen view {d}", .{view_id});
if(LuaUtils.viewById(view_id)) |v| { if (LuaUtils.viewById(view_id)) |v| {
std.log.debug("toggling fullscreen", .{}); std.log.debug("toggling fullscreen", .{});
v.toggleFullscreen(); v.toggleFullscreen();
} }
@ -221,8 +220,8 @@ pub fn toggle_fullscreen(L: *zlua.Lua) i32 {
pub fn get_title(L: *zlua.Lua) i32 { pub fn get_title(L: *zlua.Lua) i32 {
const view_id: u64 = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); const view_id: u64 = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
if(LuaUtils.viewById(view_id)) |v| { if (LuaUtils.viewById(view_id)) |v| {
if(v.xdg_toplevel.title == null) { if (v.xdg_toplevel.title == null) {
L.pushNil(); L.pushNil();
return 1; return 1;
} }
@ -241,8 +240,8 @@ pub fn get_title(L: *zlua.Lua) i32 {
pub fn get_app_id(L: *zlua.Lua) i32 { pub fn get_app_id(L: *zlua.Lua) i32 {
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
if(LuaUtils.viewById(view_id)) |v| { if (LuaUtils.viewById(view_id)) |v| {
if(v.xdg_toplevel.app_id == null) { if (v.xdg_toplevel.app_id == null) {
L.pushNil(); L.pushNil();
return 1; return 1;
} }
@ -280,7 +279,7 @@ pub fn set_enabled(L: *zlua.Lua) i32 {
pub fn get_enabled(L: *zlua.Lua) i32 { pub fn get_enabled(L: *zlua.Lua) i32 {
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
if(LuaUtils.viewById(view_id)) |v| { if (LuaUtils.viewById(view_id)) |v| {
_ = L.pushBoolean(v.xdg_toplevel.current.activated); _ = L.pushBoolean(v.xdg_toplevel.current.activated);
return 1; return 1;
} }
@ -314,7 +313,7 @@ pub fn set_resizing(L: *zlua.Lua) i32 {
pub fn get_resizing(L: *zlua.Lua) i32 { pub fn get_resizing(L: *zlua.Lua) i32 {
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
if(LuaUtils.viewById(view_id)) |v| { if (LuaUtils.viewById(view_id)) |v| {
_ = L.pushBoolean(v.xdg_toplevel.current.resizing); _ = L.pushBoolean(v.xdg_toplevel.current.resizing);
return 1; return 1;
} }
@ -346,10 +345,10 @@ pub fn set_border(L: *zlua.Lua) i32 {
alpha = 1; alpha = 1;
} }
const r = ((@as(f32, @floatFromInt(try std.fmt.parseInt(u8, color[start_color_idx..start_color_idx + 2], 16))) / 255.0) * 1000.0) / 1000.0; const r = ((@as(f32, @floatFromInt(try std.fmt.parseInt(u8, color[start_color_idx .. start_color_idx + 2], 16))) / 255.0) * 1000.0) / 1000.0;
const g = ((@as(f32, @floatFromInt(try std.fmt.parseInt(u8, color[start_color_idx + 2..start_color_idx + 4], 16))) / 255.0) * 1000.0) / 1000.0; const g = ((@as(f32, @floatFromInt(try std.fmt.parseInt(u8, color[start_color_idx + 2 .. start_color_idx + 4], 16))) / 255.0) * 1000.0) / 1000.0;
const b = ((@as(f32, @floatFromInt(try std.fmt.parseInt(u8, color[start_color_idx + 4..start_color_idx + 6], 16))) / 255.0) * 1000.0) / 1000.0; const b = ((@as(f32, @floatFromInt(try std.fmt.parseInt(u8, color[start_color_idx + 4 .. start_color_idx + 6], 16))) / 255.0) * 1000.0) / 1000.0;
const a = alpha orelse ((@as(f32, @floatFromInt(try std.fmt.parseInt(u8, color[start_color_idx + 6..start_color_idx + 8], 16))) / 255.0) * 1000.0) / 1000.0; const a = alpha orelse ((@as(f32, @floatFromInt(try std.fmt.parseInt(u8, color[start_color_idx + 6 .. start_color_idx + 8], 16))) / 255.0) * 1000.0) / 1000.0;
break :color .{ r, g, b, a }; break :color .{ r, g, b, a };
}; };

View file

@ -32,10 +32,10 @@ pub fn callback(self: *const Mousemap, state: MousemapState, args: anytype) bool
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType)); @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
} }
const lua_ref_idx = switch(state) { const lua_ref_idx = switch (state) {
.press => self.options.lua_press_ref_idx, .press => self.options.lua_press_ref_idx,
.release => self.options.lua_release_ref_idx, .release => self.options.lua_release_ref_idx,
.drag => self.options.lua_drag_ref_idx .drag => self.options.lua_drag_ref_idx,
}; };
const t = Lua.state.rawGetIndex(zlua.registry_index, lua_ref_idx); const t = Lua.state.rawGetIndex(zlua.registry_index, lua_ref_idx);