mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
reformatted with zig fmt
This commit is contained in:
parent
e6a45f91b6
commit
6be66b6a71
32 changed files with 2108 additions and 2237 deletions
|
|
@ -6,11 +6,6 @@ root = true
|
|||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.zig]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.lua]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ pub fn build(b: *std.Build) void {
|
|||
|
||||
var ret: u8 = undefined;
|
||||
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,
|
||||
.Inherit,
|
||||
) catch "dev\n";
|
||||
|
|
|
|||
109
src/Cursor.zig
109
src/Cursor.zig
|
|
@ -31,15 +31,11 @@ mode: enum { normal, drag } = .normal,
|
|||
// Drag information
|
||||
drag: ?struct {
|
||||
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,
|
||||
y: c_int
|
||||
},
|
||||
view: ?struct {
|
||||
view: *View,
|
||||
dims: struct { width: c_int, height: c_int },
|
||||
offset: struct { x: c_int, y: c_int, }
|
||||
},
|
||||
y: c_int,
|
||||
} },
|
||||
},
|
||||
|
||||
pub fn init(self: *Cursor) void {
|
||||
|
|
@ -48,7 +44,7 @@ pub fn init(self: *Cursor) void {
|
|||
self.* = .{
|
||||
.wlr_cursor = try wlr.Cursor.create(),
|
||||
.x_cursor_manager = try wlr.XcursorManager.create(null, 24),
|
||||
.drag = null
|
||||
.drag = null,
|
||||
};
|
||||
|
||||
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
|
||||
if (server.mousemaps.get(Mousemap.hash(modifiers, @bitCast(self.drag.?.event_code)))) |map| {
|
||||
if(map.options.lua_drag_ref_idx > 0) {
|
||||
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
|
||||
}
|
||||
});
|
||||
if (map.options.lua_drag_ref_idx > 0) {
|
||||
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 } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(passthrough) {
|
||||
if (passthrough) {
|
||||
const output = server.seat.focused_output;
|
||||
// Exit the switch if no focused output exists
|
||||
std.debug.assert(output != null);
|
||||
|
||||
const surfaceAtResult = output.?.surfaceAt(self.wlr_cursor.x, self.wlr_cursor.y);
|
||||
if (surfaceAtResult) |surface| {
|
||||
if(surface.scene_node_data.* == .view) {
|
||||
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))
|
||||
});
|
||||
if (surface.scene_node_data.* == .view) {
|
||||
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)) });
|
||||
}
|
||||
|
||||
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 ---------
|
||||
fn handleMotion(
|
||||
_: *wl.Listener(*wlr.Pointer.event.Motion),
|
||||
event: *wlr.Pointer.event.Motion,
|
||||
_: *wl.Listener(*wlr.Pointer.event.Motion),
|
||||
event: *wlr.Pointer.event.Motion,
|
||||
) void {
|
||||
server.cursor.wlr_cursor.move(event.device, event.delta_x, event.delta_y);
|
||||
server.cursor.processCursorMotion(event.time_msec);
|
||||
}
|
||||
|
||||
fn handleMotionAbsolute(
|
||||
_: *wl.Listener(*wlr.Pointer.event.MotionAbsolute),
|
||||
event: *wlr.Pointer.event.MotionAbsolute,
|
||||
_: *wl.Listener(*wlr.Pointer.event.MotionAbsolute),
|
||||
event: *wlr.Pointer.event.MotionAbsolute,
|
||||
) void {
|
||||
server.cursor.wlr_cursor.warpAbsolute(event.device, event.x, event.y);
|
||||
server.cursor.processCursorMotion(event.time_msec);
|
||||
}
|
||||
|
||||
fn handleButton(
|
||||
listener: *wl.Listener(*wlr.Pointer.event.Button),
|
||||
event: *wlr.Pointer.event.Button
|
||||
) void {
|
||||
fn handleButton(listener: *wl.Listener(*wlr.Pointer.event.Button), event: *wlr.Pointer.event.Button) void {
|
||||
const cursor: *Cursor = @fieldParentPtr("button", listener);
|
||||
|
||||
switch (event.state) {
|
||||
.pressed => {
|
||||
cursor.mode = .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
|
||||
};
|
||||
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 };
|
||||
|
||||
// Keep track of where the drag started
|
||||
if(server.seat.focused_surface) |fs| {
|
||||
if(fs == .view) {
|
||||
if (server.seat.focused_surface) |fs| {
|
||||
if (fs == .view) {
|
||||
cursor.drag.?.view = .{
|
||||
.view = fs.view,
|
||||
.dims = .{
|
||||
.width = fs.view.xdg_toplevel.base.geometry.width,
|
||||
.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
|
||||
},
|
||||
.dims = .{ .width = fs.view.xdg_toplevel.base.geometry.width, .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 => {
|
||||
std.log.err("Invalid/Unimplemented pointer button event type", .{});
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
var passthrough = true;
|
||||
|
|
@ -207,49 +170,39 @@ fn handleButton(
|
|||
switch (event.state) {
|
||||
.pressed => {
|
||||
// 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, .{
|
||||
.{
|
||||
.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 => {
|
||||
if(map.options.lua_press_ref_idx > 0) {
|
||||
if (map.options.lua_press_ref_idx > 0) {
|
||||
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
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
fn handleHoldBegin(
|
||||
listener: *wl.Listener(*wlr.Pointer.event.HoldBegin),
|
||||
event: *wlr.Pointer.event.HoldBegin
|
||||
) void {
|
||||
fn handleHoldBegin(listener: *wl.Listener(*wlr.Pointer.event.HoldBegin), event: *wlr.Pointer.event.HoldBegin) void {
|
||||
_ = listener;
|
||||
_ = event;
|
||||
std.log.err("Unimplemented cursor start hold", .{});
|
||||
}
|
||||
|
||||
fn handleHoldEnd(
|
||||
listener: *wl.Listener(*wlr.Pointer.event.HoldEnd),
|
||||
event: *wlr.Pointer.event.HoldEnd
|
||||
) void {
|
||||
fn handleHoldEnd(listener: *wl.Listener(*wlr.Pointer.event.HoldEnd), event: *wlr.Pointer.event.HoldEnd) void {
|
||||
_ = listener;
|
||||
_ = event;
|
||||
std.log.err("Unimplemented cursor end hold", .{});
|
||||
|
|
|
|||
|
|
@ -31,15 +31,10 @@ fn printNode(node: *wlr.SceneNode, depth: usize) void {
|
|||
const type_name = switch (node.type) {
|
||||
.tree => "TREE",
|
||||
.rect => "RECT",
|
||||
.buffer => "BUFFER"
|
||||
.buffer => "BUFFER",
|
||||
};
|
||||
|
||||
writer.print("{s} @ ({d}, {d}) enabled={}", .{
|
||||
type_name,
|
||||
node.x,
|
||||
node.y,
|
||||
node.enabled
|
||||
}) catch unreachable;
|
||||
writer.print("{s} @ ({d}, {d}) enabled={}", .{ type_name, node.x, node.y, node.enabled }) catch unreachable;
|
||||
|
||||
// Add associated data if present
|
||||
if (node.data) |data| {
|
||||
|
|
@ -84,7 +79,7 @@ fn printNode(node: *wlr.SceneNode, depth: usize) void {
|
|||
if (namespace.len > 0) {
|
||||
writer.print(" namespace=\"{s}\"", .{namespace}) catch unreachable;
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,14 +53,14 @@ pub fn init(device: *wlr.InputDevice) *Keyboard {
|
|||
self.wlr_keyboard.data = self;
|
||||
|
||||
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)"});
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn deinit (self: *Keyboard) void {
|
||||
pub fn deinit(self: *Keyboard) void {
|
||||
self.key.link.remove();
|
||||
self.key_map.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) {
|
||||
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(
|
||||
modifiers: wlr.Keyboard.ModifierMask,
|
||||
sym: xkb.Keysym,
|
||||
state: wl.Keyboard.KeyState
|
||||
) bool {
|
||||
pub fn keypress(modifiers: wlr.Keyboard.ModifierMask, sym: xkb.Keysym, state: wl.Keyboard.KeyState) bool {
|
||||
if (server.keymaps.get(Keymap.hash(modifiers, sym))) |map| {
|
||||
if (state == .pressed and map.options.lua_press_ref_idx > 0) {
|
||||
map.callback(false);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ fn handleRepeat(data: ?*KeyboardGroup) c_int {
|
|||
if (data.?.repeat_source == null) return 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,16 +31,16 @@ pub fn init(wlr_layer_surface: *wlr.LayerSurfaceV1) *LayerSurface {
|
|||
.output = undefined,
|
||||
.wlr_layer_surface = wlr_layer_surface,
|
||||
.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", .{});
|
||||
unreachable;
|
||||
}
|
||||
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) {
|
||||
.background => try output.layers.background.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 => {
|
||||
std.log.err("New layer surface of unidentified type", .{});
|
||||
unreachable;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -77,27 +77,18 @@ pub fn deinit(self: *LayerSurface) void {
|
|||
|
||||
pub fn allowKeyboard(self: *LayerSurface) void {
|
||||
const keyboard_interactive = self.wlr_layer_surface.current.keyboard_interactive;
|
||||
if(keyboard_interactive == .exclusive or keyboard_interactive == .on_demand) {
|
||||
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
|
||||
);
|
||||
if (keyboard_interactive == .exclusive or keyboard_interactive == .on_demand) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// --------- LayerSurface event handlers ---------
|
||||
fn handleDestroy(
|
||||
listener: *wl.Listener(*wlr.LayerSurfaceV1),
|
||||
_: *wlr.LayerSurfaceV1
|
||||
) void {
|
||||
fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfaceV1) void {
|
||||
const layer: *LayerSurface = @fieldParentPtr("destroy", listener);
|
||||
layer.deinit();
|
||||
}
|
||||
|
||||
fn handleMap(
|
||||
listener: *wl.Listener(void)
|
||||
) void {
|
||||
fn handleMap(listener: *wl.Listener(void)) void {
|
||||
const layer_suraface: *LayerSurface = @fieldParentPtr("map", listener);
|
||||
std.log.debug("layer surface mapped", .{});
|
||||
layer_suraface.output.arrangeLayers();
|
||||
|
|
@ -120,10 +111,7 @@ fn handleUnmap(listener: *wl.Listener(void)) void {
|
|||
layer_surface.deinit();
|
||||
}
|
||||
|
||||
fn handleCommit(
|
||||
listener: *wl.Listener(*wlr.Surface),
|
||||
_: *wlr.Surface
|
||||
) void {
|
||||
fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
||||
const layer_surface: *LayerSurface = @fieldParentPtr("commit", listener);
|
||||
|
||||
if (!layer_surface.wlr_layer_surface.initial_commit) return;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ layers: struct {
|
|||
content: *wlr.SceneTree,
|
||||
top: *wlr.SceneTree,
|
||||
fullscreen: *wlr.SceneTree,
|
||||
overlay: *wlr.SceneTree
|
||||
overlay: *wlr.SceneTree,
|
||||
},
|
||||
|
||||
layer_scene_node_data: struct {
|
||||
|
|
@ -42,14 +42,13 @@ layer_scene_node_data: struct {
|
|||
content: SceneNodeData,
|
||||
top: SceneNodeData,
|
||||
fullscreen: SceneNodeData,
|
||||
overlay: SceneNodeData
|
||||
overlay: SceneNodeData,
|
||||
},
|
||||
|
||||
frame: wl.Listener(*wlr.Output) = .init(handleFrame),
|
||||
request_state: wl.Listener(*wlr.Output.event.RequestState) = .init(handleRequestState),
|
||||
destroy: wl.Listener(*wlr.Output) = .init(handleDestroy),
|
||||
|
||||
|
||||
// The wlr.Output should be destroyed by the caller on failure to trigger cleanup.
|
||||
pub fn init(wlr_output: *wlr.Output) ?*Output {
|
||||
errdefer Utils.oomPanic();
|
||||
|
|
@ -62,6 +61,7 @@ pub fn init(wlr_output: *wlr.Output) ?*Output {
|
|||
.wlr_output = wlr_output,
|
||||
.tree = try server.root.scene.tree.createSceneTree(),
|
||||
.fullscreen = null,
|
||||
|
||||
.layers = .{
|
||||
.background = 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(),
|
||||
.overlay = try self.tree.createSceneTree(),
|
||||
},
|
||||
|
||||
.layer_scene_node_data = .{
|
||||
.background = .{ .output_layer = self.layers.background },
|
||||
.bottom = .{ .output_layer = self.layers.bottom },
|
||||
.content = .{ .output_layer = self.layers.content },
|
||||
.top = .{ .output_layer = self.layers.top },
|
||||
.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_node_data = SceneNodeData{ .output = self },
|
||||
.state = wlr.Output.State.init()
|
||||
|
|
@ -89,7 +91,7 @@ pub fn init(wlr_output: *wlr.Output) ?*Output {
|
|||
|
||||
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});
|
||||
return null;
|
||||
}
|
||||
|
|
@ -100,7 +102,7 @@ pub fn init(wlr_output: *wlr.Output) ?*Output {
|
|||
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});
|
||||
return null;
|
||||
}
|
||||
|
|
@ -142,7 +144,7 @@ pub fn deinit(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;
|
||||
}
|
||||
|
||||
|
|
@ -172,21 +174,18 @@ pub fn configureLayers(self: *Output) void {
|
|||
};
|
||||
|
||||
var it = tree.children.iterator(.forward);
|
||||
while(it.next()) |node| {
|
||||
if(node.data == null) continue;
|
||||
while (it.next()) |node| {
|
||||
if (node.data == null) continue;
|
||||
|
||||
const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?));
|
||||
switch (scene_node_data.*) {
|
||||
.layer_surface => {
|
||||
_ = scene_node_data.layer_surface.wlr_layer_surface.configured(
|
||||
@intCast(output_box.width),
|
||||
@intCast(output_box.height)
|
||||
);
|
||||
_ = scene_node_data.layer_surface.wlr_layer_surface.configured(@intCast(output_box.width), @intCast(output_box.height));
|
||||
},
|
||||
else => {
|
||||
std.log.err("Something other than a layer surface found in layer surface scene trees", .{});
|
||||
unreachable;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -203,18 +202,11 @@ pub fn surfaceAt(self: *Output, lx: f64, ly: f64) ?SurfaceAtResult {
|
|||
var sx: f64 = undefined;
|
||||
var sy: f64 = undefined;
|
||||
|
||||
const layers = [_]*wlr.SceneTree{
|
||||
self.layers.top,
|
||||
self.layers.overlay,
|
||||
self.layers.fullscreen,
|
||||
self.layers.content,
|
||||
self.layers.bottom,
|
||||
self.layers.background
|
||||
};
|
||||
const layers = [_]*wlr.SceneTree{ 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);
|
||||
if(node == null) continue;
|
||||
if (node == null) continue;
|
||||
|
||||
const surface: ?*wlr.Surface = blk: {
|
||||
if (node.?.type == .buffer) {
|
||||
|
|
@ -225,7 +217,7 @@ pub fn surfaceAt(self: *Output, lx: f64, ly: f64) ?SurfaceAtResult {
|
|||
}
|
||||
break :blk null;
|
||||
};
|
||||
if(surface == null) continue;
|
||||
if (surface == null) continue;
|
||||
|
||||
const scene_node_data: *SceneNodeData = blk: {
|
||||
var n = node.?;
|
||||
|
|
@ -250,7 +242,7 @@ pub fn surfaceAt(self: *Output, lx: f64, ly: f64) ?SurfaceAtResult {
|
|||
.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 {
|
||||
if(self.layers.fullscreen.children.length() != 1) {
|
||||
if (self.layers.fullscreen.children.length() != 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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));
|
||||
if(scene_node_data.* == .view) {
|
||||
if (scene_node_data.* == .view) {
|
||||
return scene_node_data.view;
|
||||
}
|
||||
}
|
||||
|
|
@ -286,13 +278,10 @@ fn handleRequestState(
|
|||
server.events.exec("OutputStateChange", .{});
|
||||
}
|
||||
|
||||
fn handleFrame(
|
||||
_: *wl.Listener(*wlr.Output),
|
||||
wlr_output: *wlr.Output
|
||||
) void {
|
||||
fn handleFrame(_: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
|
||||
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", .{});
|
||||
return;
|
||||
}
|
||||
|
|
@ -304,10 +293,7 @@ fn handleFrame(
|
|||
scene_output.?.sendFrameDone(&now);
|
||||
}
|
||||
|
||||
fn handleDestroy(
|
||||
listener: *wl.Listener(*wlr.Output),
|
||||
_: *wlr.Output
|
||||
) void {
|
||||
fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
|
||||
std.log.debug("Handling destroy", .{});
|
||||
const output: *Output = @fieldParentPtr("destroy", listener);
|
||||
|
||||
|
|
@ -336,14 +322,14 @@ pub fn arrangeLayers(self: *Output) void {
|
|||
var it = layer.children.safeIterator(.forward);
|
||||
|
||||
while (it.next()) |node| {
|
||||
if(node.data == null) continue;
|
||||
if (node.data == null) continue;
|
||||
|
||||
// if (@as(?*SceneNodeData, @alignCast(@ptrCast(node.data)))) |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),
|
||||
else => continue
|
||||
else => continue,
|
||||
};
|
||||
|
||||
if (!layer_surface.wlr_layer_surface.initialized) continue;
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@ pub fn create(client: *wl.Client, version: u32, id: u32) !void {
|
|||
}
|
||||
|
||||
fn handleRequest(
|
||||
remote_lua_v1: *mez.RemoteLuaV1,
|
||||
request: mez.RemoteLuaV1.Request,
|
||||
remote: *RemoteLua,
|
||||
remote_lua_v1: *mez.RemoteLuaV1,
|
||||
request: mez.RemoteLuaV1.Request,
|
||||
remote: *RemoteLua,
|
||||
) void {
|
||||
const L = remote.L;
|
||||
switch (request) {
|
||||
|
|
@ -75,7 +75,9 @@ remote: *RemoteLua,
|
|||
return;
|
||||
};
|
||||
|
||||
L.protectedCall(.{ .results = zlua.mult_return, }) catch {
|
||||
L.protectedCall(.{
|
||||
.results = zlua.mult_return,
|
||||
}) catch {
|
||||
catchLuaFail(remote);
|
||||
L.pop(1);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ fn bind(client: *wl.Client, _: ?*anyopaque, version: u32, id: u32) void {
|
|||
}
|
||||
|
||||
fn handleRequest(
|
||||
remote_lua_manager_v1: *mez.RemoteLuaManagerV1,
|
||||
request: mez.RemoteLuaManagerV1.Request,
|
||||
_: ?*anyopaque,
|
||||
remote_lua_manager_v1: *mez.RemoteLuaManagerV1,
|
||||
request: mez.RemoteLuaManagerV1.Request,
|
||||
_: ?*anyopaque,
|
||||
) void {
|
||||
switch (request) {
|
||||
.destroy => remote_lua_manager_v1.destroy(),
|
||||
|
|
|
|||
29
src/Root.zig
29
src/Root.zig
|
|
@ -1,5 +1,4 @@
|
|||
/// The root of Mezzaluna is, you guessed it, the root of many of the systems mez needs:
|
||||
|
||||
const Root = @This();
|
||||
|
||||
const std = @import("std");
|
||||
|
|
@ -50,18 +49,18 @@ pub fn init(self: *Root) void {
|
|||
pub fn deinit(self: *Root) void {
|
||||
var it = self.scene.tree.children.iterator(.forward);
|
||||
|
||||
while(it.next()) |node| {
|
||||
if(node.data == null) continue;
|
||||
while (it.next()) |node| {
|
||||
if (node.data == null) continue;
|
||||
|
||||
const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(node.data.?));
|
||||
switch(scene_node_data.*) {
|
||||
switch (scene_node_data.*) {
|
||||
.output => {
|
||||
scene_node_data.output.deinit();
|
||||
},
|
||||
else => {
|
||||
std.log.debug("The root has a child that is not an output", .{});
|
||||
unreachable;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,8 +72,8 @@ pub fn deinit(self: *Root) void {
|
|||
pub fn viewById(self: *Root, id: u64) ?*View {
|
||||
var output_it = self.output_layout.outputs.iterator(.forward);
|
||||
|
||||
while(output_it.next()) |o| {
|
||||
if(o.output.data == null) {
|
||||
while (output_it.next()) |o| {
|
||||
if (o.output.data == null) {
|
||||
std.log.err("Wlr_output arbitrary data not assigned", .{});
|
||||
unreachable;
|
||||
}
|
||||
|
|
@ -82,21 +81,21 @@ pub fn viewById(self: *Root, id: u64) ?*View {
|
|||
const output: *Output = @ptrCast(@alignCast(o.output.data.?));
|
||||
var node_it = output.layers.content.children.iterator(.forward);
|
||||
|
||||
while(node_it.next()) |node| {
|
||||
if(node.data == null) continue;
|
||||
while (node_it.next()) |node| {
|
||||
if (node.data == null) continue;
|
||||
|
||||
const view_snd: *SceneNodeData = @ptrCast(@alignCast(node.data.?));
|
||||
|
||||
// TODO: Should we assert that we want only views to be here
|
||||
// -- Basically should we use switch statements for snd interactions
|
||||
// -- 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;
|
||||
}
|
||||
}
|
||||
|
||||
if(output.fullscreen) |fullscreen| {
|
||||
if(fullscreen.id == id) return fullscreen;
|
||||
if (output.fullscreen) |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 {
|
||||
var it = self.scene.outputs.iterator(.forward);
|
||||
|
||||
while(it.next()) |scene_output| {
|
||||
if(scene_output.output.data == null) continue;
|
||||
while (it.next()) |scene_output| {
|
||||
if (scene_output.output.data == null) continue;
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -5,10 +5,4 @@ const LayerSurface = @import("LayerSurface.zig");
|
|||
const Output = @import("Output.zig");
|
||||
const Root = @import("Root.zig");
|
||||
|
||||
pub const SceneNodeData = union(enum) {
|
||||
view: *View,
|
||||
layer_surface: *LayerSurface,
|
||||
output: *Output,
|
||||
output_layer: *wlr.SceneTree,
|
||||
root: *Root
|
||||
};
|
||||
pub const SceneNodeData = union(enum) { view: *View, layer_surface: *LayerSurface, output: *Output, output_layer: *wlr.SceneTree, root: *Root };
|
||||
|
|
|
|||
37
src/Seat.zig
37
src/Seat.zig
|
|
@ -101,26 +101,26 @@ pub fn focusSurface(self: *Seat, to_focus: ?FocusData) void {
|
|||
const current_surface = current_focus.getSurface();
|
||||
if (current_surface == surface) return; // Same surface
|
||||
|
||||
if(to_focus != null) {
|
||||
if (to_focus != null) {
|
||||
switch (current_focus) {
|
||||
.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| {
|
||||
if(current_view.*.fullscreen) {
|
||||
if (current_view.*.fullscreen) {
|
||||
switch (to_focus.?) {
|
||||
.layer_surface => |*layer_surface| {
|
||||
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| {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -128,23 +128,18 @@ pub fn focusSurface(self: *Seat, to_focus: ?FocusData) void {
|
|||
switch (current_focus) {
|
||||
.layer_surface => {}, // IDK if we actually have to clear any focus here
|
||||
else => {
|
||||
if(wlr.XdgSurface.tryFromWlrSurface(current_surface)) |xdg_surface| {
|
||||
if (wlr.XdgSurface.tryFromWlrSurface(current_surface)) |xdg_surface| {
|
||||
_ = xdg_surface.role_data.toplevel.?.setActivated(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
);
|
||||
if(to_focus.? != .layer_surface) {
|
||||
if(to_focus.? == .view) to_focus.?.view.focused = true;
|
||||
if(wlr.XdgSurface.tryFromWlrSurface(surface.?)) |xdg_surface| {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -153,7 +148,7 @@ pub fn focusSurface(self: *Seat, to_focus: ?FocusData) 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -167,18 +167,12 @@ pub fn deinit(self: *Server) noreturn {
|
|||
}
|
||||
|
||||
// --------- Backend event handlers ---------
|
||||
fn handleNewInput(
|
||||
_: *wl.Listener(*wlr.InputDevice),
|
||||
device: *wlr.InputDevice
|
||||
) void {
|
||||
fn handleNewInput(_: *wl.Listener(*wlr.InputDevice), device: *wlr.InputDevice) void {
|
||||
switch (device.type) {
|
||||
.keyboard => _ = Keyboard.init(device),
|
||||
.pointer => server.cursor.wlr_cursor.attachInputDevice(device),
|
||||
else => {
|
||||
std.log.err(
|
||||
"New input request for input that is not a keyboard or pointer: {s}",
|
||||
.{device.name orelse "(null)"}
|
||||
);
|
||||
std.log.err("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(
|
||||
_: *wl.Listener(*wlr.Output),
|
||||
wlr_output: *wlr.Output
|
||||
) void {
|
||||
fn handleNewOutput(_: *wl.Listener(*wlr.Output), wlr_output: *wlr.Output) void {
|
||||
_ = Output.init(wlr_output);
|
||||
}
|
||||
|
||||
fn handleNewXdgToplevel(
|
||||
_: *wl.Listener(*wlr.XdgToplevel),
|
||||
xdg_toplevel: *wlr.XdgToplevel
|
||||
) void {
|
||||
fn handleNewXdgToplevel(_: *wl.Listener(*wlr.XdgToplevel), xdg_toplevel: *wlr.XdgToplevel) void {
|
||||
_ = View.init(xdg_toplevel);
|
||||
}
|
||||
|
||||
fn handleNewXdgToplevelDecoration(
|
||||
_: *wl.Listener(*wlr.XdgToplevelDecorationV1),
|
||||
decoration: *wlr.XdgToplevelDecorationV1
|
||||
) void {
|
||||
if(server.root.viewById(@intFromPtr(decoration.toplevel))) |view| {
|
||||
fn handleNewXdgToplevelDecoration(_: *wl.Listener(*wlr.XdgToplevelDecorationV1), decoration: *wlr.XdgToplevelDecorationV1) void {
|
||||
if (server.root.viewById(@intFromPtr(decoration.toplevel))) |view| {
|
||||
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", .{});
|
||||
}
|
||||
|
||||
fn handleNewLayerSurface(
|
||||
_: *wl.Listener(*wlr.LayerSurfaceV1),
|
||||
layer_surface: *wlr.LayerSurfaceV1
|
||||
) void {
|
||||
fn handleNewLayerSurface(_: *wl.Listener(*wlr.LayerSurfaceV1), layer_surface: *wlr.LayerSurfaceV1) void {
|
||||
std.log.debug("requested layer shell\n", .{});
|
||||
if (layer_surface.output == null) {
|
||||
if (server.seat.focused_output == null) {
|
||||
|
|
@ -238,13 +220,13 @@ fn handleRequestActivate(
|
|||
_: *wl.Listener(*wlr.XdgActivationV1.event.RequestActivate),
|
||||
event: *wlr.XdgActivationV1.event.RequestActivate,
|
||||
) void {
|
||||
if(event.surface.data == null) return;
|
||||
if (event.surface.data == null) return;
|
||||
|
||||
const scene_node_data: *SceneNodeData = @ptrCast(@alignCast(event.surface.data.?));
|
||||
|
||||
if(scene_node_data.* == .view) {
|
||||
if(server.seat.focused_output) |output| {
|
||||
if(output.fullscreen) |fullscreen| {
|
||||
if (scene_node_data.* == .view) {
|
||||
if (server.seat.focused_output) |output| {
|
||||
if (output.fullscreen) |fullscreen| {
|
||||
server.seat.focusSurface(.{ .view = fullscreen });
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
42
src/View.zig
42
src/View.zig
|
|
@ -68,19 +68,17 @@ pub fn init(xdg_toplevel: *wlr.XdgToplevel) *View {
|
|||
.id = @intFromPtr(xdg_toplevel),
|
||||
.output = null,
|
||||
.geometry = .{ .width = 0, .height = 0, .x = 0, .y = 0 },
|
||||
|
||||
.xdg_toplevel = xdg_toplevel,
|
||||
.scene_tree = undefined,
|
||||
.surface_tree = undefined,
|
||||
.xdg_toplevel_decoration = null,
|
||||
.borders = undefined,
|
||||
.border_width = 0,
|
||||
|
||||
.scene_node_data = .{ .view = self }
|
||||
.scene_node_data = .{ .view = self },
|
||||
};
|
||||
|
||||
// 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.surface_tree = try self.scene_tree.createSceneXdgSurface(xdg_toplevel.base);
|
||||
self.output = output;
|
||||
|
|
@ -117,10 +115,10 @@ pub fn setBorderColor(self: *View, color: *const [4]f32) void {
|
|||
|
||||
pub fn toggleFullscreen(self: *View) void {
|
||||
self.fullscreen = !self.fullscreen;
|
||||
if(self.output) |output| {
|
||||
if(self.fullscreen and output.fullscreen != self) {
|
||||
if (self.output) |output| {
|
||||
if (self.fullscreen and output.fullscreen != self) {
|
||||
// Check to see if another fullscreened view exists, if so replace it
|
||||
if(output.getFullscreenedView()) |view| {
|
||||
if (output.getFullscreenedView()) |view| {
|
||||
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
|
||||
if (view.xdg_toplevel.base.client.shell.version >= 5) {
|
||||
// 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
|
||||
|
|
@ -285,18 +285,12 @@ fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), xdg_popup: *wlr.XdgPopu
|
|||
_ = Popup.init(xdg_popup, view.scene_tree);
|
||||
}
|
||||
|
||||
fn handleRequestMove(
|
||||
listener: *wl.Listener(*wlr.XdgToplevel.event.Move),
|
||||
_: *wlr.XdgToplevel.event.Move
|
||||
) void {
|
||||
fn handleRequestMove(listener: *wl.Listener(*wlr.XdgToplevel.event.Move), _: *wlr.XdgToplevel.event.Move) void {
|
||||
const view: *View = @fieldParentPtr("request_move", listener);
|
||||
server.events.exec("ViewRequestMove", .{view.id});
|
||||
}
|
||||
|
||||
fn handleRequestResize(
|
||||
listener: *wl.Listener(*wlr.XdgToplevel.event.Resize),
|
||||
_: *wlr.XdgToplevel.event.Resize
|
||||
) void {
|
||||
fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), _: *wlr.XdgToplevel.event.Resize) void {
|
||||
const view: *View = @fieldParentPtr("request_resize", listener);
|
||||
server.events.exec("ViewRequestResize", .{view.id});
|
||||
}
|
||||
|
|
@ -310,32 +304,24 @@ fn handleAckConfigure(
|
|||
std.log.err("Unimplemented ack configure", .{});
|
||||
}
|
||||
|
||||
fn handleRequestFullscreen(
|
||||
listener: *wl.Listener(void)
|
||||
) void {
|
||||
fn handleRequestFullscreen(listener: *wl.Listener(void)) void {
|
||||
const view: *View = @fieldParentPtr("request_fullscreen", listener);
|
||||
server.events.exec("ViewRequestFullscreen", .{view.id});
|
||||
}
|
||||
|
||||
fn handleRequestMinimize(
|
||||
listener: *wl.Listener(void)
|
||||
) void {
|
||||
fn handleRequestMinimize(listener: *wl.Listener(void)) void {
|
||||
const view: *View = @fieldParentPtr("request_minimize", listener);
|
||||
server.events.exec("ViewRequestMinimize", .{view.id});
|
||||
std.log.debug("request_minimize unimplemented", .{});
|
||||
}
|
||||
|
||||
fn handleSetAppId(
|
||||
listener: *wl.Listener(void)
|
||||
) void {
|
||||
fn handleSetAppId(listener: *wl.Listener(void)) void {
|
||||
const view: *View = @fieldParentPtr("set_app_id", listener);
|
||||
server.events.exec("ViewAppIdUpdate", .{view.id});
|
||||
std.log.debug("request_set_app_id unimplemented", .{});
|
||||
}
|
||||
|
||||
fn handleSetTitle(
|
||||
listener: *wl.Listener(void)
|
||||
) void {
|
||||
fn handleSetTitle(listener: *wl.Listener(void)) void {
|
||||
const view: *View = @fieldParentPtr("set_title", listener);
|
||||
server.events.exec("ViewTitleUpdate", .{view.id});
|
||||
std.log.debug("request_set_title unimplemented", .{});
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ pub fn setBaseConfig(self: *zlua.Lua, path: []const u8) !void {
|
|||
_ = try self.getGlobal("mez");
|
||||
_ = self.getField(-1, "path");
|
||||
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);
|
||||
_ = self.pushString(new_path);
|
||||
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 {
|
||||
self.state = try zlua.Lua.init(gpa);
|
||||
errdefer self.state.deinit();
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ pub fn toStringEx(L: *zlua.Lua) [:0]const u8 {
|
|||
|
||||
pub fn viewById(view_id: u64) ?*View {
|
||||
if (view_id == 0) {
|
||||
if(server.seat.focused_surface) |fs| {
|
||||
if(fs == .view) return fs.view;
|
||||
if (server.seat.focused_surface) |fs| {
|
||||
if (fs == .view) return fs.view;
|
||||
}
|
||||
} else {
|
||||
return server.root.viewById(view_id);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ fn output_id_err(L: *zlua.Lua) noreturn {
|
|||
}
|
||||
|
||||
/// ---@alias output_id integer
|
||||
|
||||
/// ---Get the ids for all available outputs
|
||||
/// ---@return output_id[]?
|
||||
pub fn get_all_ids(L: *zlua.Lua) i32 {
|
||||
|
|
@ -20,8 +19,8 @@ pub fn get_all_ids(L: *zlua.Lua) i32 {
|
|||
|
||||
L.newTable();
|
||||
|
||||
while(it.next()) |scene_output| : (index += 1) {
|
||||
if(scene_output.output.data == null) continue;
|
||||
while (it.next()) |scene_output| : (index += 1) {
|
||||
if (scene_output.output.data == null) continue;
|
||||
|
||||
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
|
||||
/// ---@return output_id?
|
||||
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));
|
||||
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: ?*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));
|
||||
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: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
|
||||
if(output) |o| {
|
||||
if (output) |o| {
|
||||
L.newTable();
|
||||
|
||||
_ = 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: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
|
||||
if(output) |o| {
|
||||
if(o.wlr_output.serial == null) {
|
||||
if (output) |o| {
|
||||
if (o.wlr_output.serial == null) {
|
||||
L.pushNil();
|
||||
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: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
|
||||
if(output) |o| {
|
||||
if(o.wlr_output.make == null) {
|
||||
if (output) |o| {
|
||||
if (o.wlr_output.make == null) {
|
||||
L.pushNil();
|
||||
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: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
|
||||
if(output) |o| {
|
||||
if(o.wlr_output.model == null) {
|
||||
if (output) |o| {
|
||||
if (o.wlr_output.model == null) {
|
||||
L.pushNil();
|
||||
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: ?*Output = if (output_id == 0) server.seat.focused_output else server.root.outputById(output_id);
|
||||
if(output) |o| {
|
||||
if(o.wlr_output.description == null) {
|
||||
if (output) |o| {
|
||||
if (o.wlr_output.description == null) {
|
||||
L.pushNil();
|
||||
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: ?*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));
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ pub fn get_all_ids(L: *zlua.Lua) i32 {
|
|||
var index: i32 = 1;
|
||||
L.newTable();
|
||||
|
||||
while(output_it.next()) |o| {
|
||||
if(o.output.data == null) {
|
||||
while (output_it.next()) |o| {
|
||||
if (o.output.data == null) {
|
||||
std.log.err("Output arbitrary data not assigned", .{});
|
||||
unreachable;
|
||||
}
|
||||
|
|
@ -40,26 +40,25 @@ pub fn get_all_ids(L: *zlua.Lua) i32 {
|
|||
output.layers.fullscreen,
|
||||
};
|
||||
|
||||
for(layers) |layer| {
|
||||
if(layer.children.length() == 0) continue; // No children
|
||||
for (layers) |layer| {
|
||||
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", .{});
|
||||
unreachable;
|
||||
}
|
||||
|
||||
var view_it = layer.children.iterator(.forward);
|
||||
|
||||
while(view_it.next()) |v| {
|
||||
|
||||
if(v.data == null) {
|
||||
while (view_it.next()) |v| {
|
||||
if (v.data == null) {
|
||||
std.log.err("Unassigned arbitrary data in scene graph", .{});
|
||||
unreachable;
|
||||
}
|
||||
|
||||
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(scene_node_data.view.id));
|
||||
L.setTable(-3);
|
||||
|
|
@ -76,8 +75,8 @@ pub fn get_all_ids(L: *zlua.Lua) i32 {
|
|||
// ---Get the id for the focused view
|
||||
// ---@return view_id?
|
||||
pub fn get_focused_id(L: *zlua.Lua) i32 {
|
||||
if(server.seat.focused_surface) |fs| {
|
||||
if(fs == .view) {
|
||||
if (server.seat.focused_surface) |fs| {
|
||||
if (fs == .view) {
|
||||
L.pushInteger(@intCast(fs.view.id));
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -92,7 +91,7 @@ pub fn get_focused_id(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);
|
||||
|
||||
if(LuaUtils.viewById(view_id)) |v| {
|
||||
if (LuaUtils.viewById(view_id)) |v| {
|
||||
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 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);
|
||||
}
|
||||
|
||||
|
|
@ -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 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));
|
||||
}
|
||||
|
||||
|
|
@ -189,9 +188,9 @@ pub fn get_size(L: *zlua.Lua) i32 {
|
|||
pub fn set_focused(L: *zlua.Lua) i32 {
|
||||
const view_id: ?c_longlong = L.optInteger(1);
|
||||
|
||||
if(view_id == null) {
|
||||
if (view_id == 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 });
|
||||
}
|
||||
|
||||
|
|
@ -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);
|
||||
|
||||
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", .{});
|
||||
v.toggleFullscreen();
|
||||
}
|
||||
|
|
@ -221,8 +220,8 @@ pub fn toggle_fullscreen(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);
|
||||
|
||||
if(LuaUtils.viewById(view_id)) |v| {
|
||||
if(v.xdg_toplevel.title == null) {
|
||||
if (LuaUtils.viewById(view_id)) |v| {
|
||||
if (v.xdg_toplevel.title == null) {
|
||||
L.pushNil();
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -241,8 +240,8 @@ pub fn get_title(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);
|
||||
|
||||
if(LuaUtils.viewById(view_id)) |v| {
|
||||
if(v.xdg_toplevel.app_id == null) {
|
||||
if (LuaUtils.viewById(view_id)) |v| {
|
||||
if (v.xdg_toplevel.app_id == null) {
|
||||
L.pushNil();
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -280,7 +279,7 @@ pub fn set_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);
|
||||
|
||||
if(LuaUtils.viewById(view_id)) |v| {
|
||||
if (LuaUtils.viewById(view_id)) |v| {
|
||||
_ = L.pushBoolean(v.xdg_toplevel.current.activated);
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -314,7 +313,7 @@ pub fn set_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);
|
||||
|
||||
if(LuaUtils.viewById(view_id)) |v| {
|
||||
if (LuaUtils.viewById(view_id)) |v| {
|
||||
_ = L.pushBoolean(v.xdg_toplevel.current.resizing);
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -346,10 +345,10 @@ pub fn set_border(L: *zlua.Lua) i32 {
|
|||
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 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 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 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 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;
|
||||
|
||||
break :color .{ r, g, b, a };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ pub fn callback(self: *const Mousemap, state: MousemapState, args: anytype) bool
|
|||
@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,
|
||||
.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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue