mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
fixed adding two scene trees bug
This commit is contained in:
parent
76b9d13798
commit
f9e67a5681
5 changed files with 36 additions and 39 deletions
|
|
@ -4,6 +4,8 @@ const std = @import("std");
|
||||||
const wl = @import("wayland").server.wl;
|
const wl = @import("wayland").server.wl;
|
||||||
const wlr = @import("wlroots");
|
const wlr = @import("wlroots");
|
||||||
|
|
||||||
|
const View = @import("view.zig");
|
||||||
|
|
||||||
const server = &@import("main.zig").server;
|
const server = &@import("main.zig").server;
|
||||||
|
|
||||||
wlr_cursor: *wlr.Cursor,
|
wlr_cursor: *wlr.Cursor,
|
||||||
|
|
@ -17,6 +19,11 @@ frame: wl.Listener(*wlr.Cursor) = .init(handleFrame),
|
||||||
hold_begin: wl.Listener(*wlr.Pointer.event.HoldBegin) = .init(handleHoldBegin),
|
hold_begin: wl.Listener(*wlr.Pointer.event.HoldBegin) = .init(handleHoldBegin),
|
||||||
hold_end: wl.Listener(*wlr.Pointer.event.HoldEnd) = .init(handleHoldEnd),
|
hold_end: wl.Listener(*wlr.Pointer.event.HoldEnd) = .init(handleHoldEnd),
|
||||||
|
|
||||||
|
cursor_mode: enum { passthrough, move, resize } = .passthrough,
|
||||||
|
grabbed_view: ?*View = null,
|
||||||
|
grab_x: f64 = 0,
|
||||||
|
grab_y: f64 = 0,
|
||||||
|
grab_box: wlr.Box = undefined,
|
||||||
|
|
||||||
pub fn init(self: *Cursor) !void {
|
pub fn init(self: *Cursor) !void {
|
||||||
self.* = .{
|
self.* = .{
|
||||||
|
|
@ -83,7 +90,7 @@ fn handleButton(
|
||||||
) void {
|
) void {
|
||||||
_ = server.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state);
|
_ = server.seat.wlr_seat.pointerNotifyButton(event.time_msec, event.button, event.state);
|
||||||
if (server.root.viewAt(server.cursor.wlr_cursor.x, server.cursor.wlr_cursor.y)) |res| {
|
if (server.root.viewAt(server.cursor.wlr_cursor.x, server.cursor.wlr_cursor.y)) |res| {
|
||||||
server.root.focusView(res.toplevel);
|
server.root.focusView(res.view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,6 @@ fn handleFrame(
|
||||||
_: *wl.Listener(*wlr.Output),
|
_: *wl.Listener(*wlr.Output),
|
||||||
wlr_output: *wlr.Output
|
wlr_output: *wlr.Output
|
||||||
) void {
|
) void {
|
||||||
std.log.debug("Handling frame for {s}", .{wlr_output.name});
|
|
||||||
|
|
||||||
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) {
|
||||||
|
|
|
||||||
40
src/root.zig
40
src/root.zig
|
|
@ -47,24 +47,8 @@ pub fn addOutput(self: *Root, new_output: *Output) void {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addView(self: *Root, view: *View) void {
|
|
||||||
// self.all_views.append(gpa, view) catch {
|
|
||||||
// std.log.err("Out of memory to append view", .{});
|
|
||||||
// return;
|
|
||||||
// };
|
|
||||||
|
|
||||||
view.scene_tree = self.scene.tree.createSceneXdgSurface(view.xdg_toplevel.base) catch {
|
|
||||||
std.log.err("Unable to create scene node for new view", .{});
|
|
||||||
|
|
||||||
_ = self.all_views.pop();
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
std.log.debug("View added succesfully", .{});
|
|
||||||
}
|
|
||||||
|
|
||||||
const ViewAtResult = struct {
|
const ViewAtResult = struct {
|
||||||
toplevel: *View,
|
view: *View,
|
||||||
surface: *wlr.Surface,
|
surface: *wlr.Surface,
|
||||||
sx: f64,
|
sx: f64,
|
||||||
sy: f64,
|
sy: f64,
|
||||||
|
|
@ -78,15 +62,21 @@ pub fn viewAt(self: *Root, lx: f64, ly: f64) ?ViewAtResult {
|
||||||
const scene_buffer = wlr.SceneBuffer.fromNode(node);
|
const scene_buffer = wlr.SceneBuffer.fromNode(node);
|
||||||
const scene_surface = wlr.SceneSurface.tryFromBuffer(scene_buffer) orelse return null;
|
const scene_surface = wlr.SceneSurface.tryFromBuffer(scene_buffer) orelse return null;
|
||||||
|
|
||||||
|
std.log.debug("Starting parent walk from buffer node", .{});
|
||||||
var it: ?*wlr.SceneTree = node.parent;
|
var it: ?*wlr.SceneTree = node.parent;
|
||||||
|
|
||||||
while (it) |n| : (it = n.node.parent) {
|
while (it) |n| : (it = n.node.parent) {
|
||||||
if (@as(?*View, @ptrCast(@alignCast(n.node.data)))) |toplevel| {
|
if (n.node.data) |data_ptr| {
|
||||||
return ViewAtResult{
|
if (@as(?*View, @ptrCast(@alignCast(data_ptr)))) |view| {
|
||||||
.toplevel = toplevel,
|
std.log.debug("View found", .{});
|
||||||
.surface = scene_surface.surface,
|
|
||||||
.sx = sx,
|
return ViewAtResult{
|
||||||
.sy = sy,
|
.view = view,
|
||||||
};
|
.surface = scene_surface.surface,
|
||||||
|
.sx = sx,
|
||||||
|
.sy = sy,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -101,7 +91,7 @@ pub fn focusView(_: *Root, view: *View) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
view.scene_tree.?.node.raiseToTop();
|
view.scene_tree.node.raiseToTop();
|
||||||
// view.link.remove();
|
// view.link.remove();
|
||||||
_ = server.root.all_views.append(gpa, view) catch {
|
_ = server.root.all_views.append(gpa, view) catch {
|
||||||
unreachable;
|
unreachable;
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,6 @@ fn handleNewXdgToplevel(
|
||||||
) void {
|
) void {
|
||||||
if(View.initFromTopLevel(xdg_toplevel)) |view| {
|
if(View.initFromTopLevel(xdg_toplevel)) |view| {
|
||||||
std.log.debug("Adding new view {s}", .{view.xdg_toplevel.title orelse "(null)"});
|
std.log.debug("Adding new view {s}", .{view.xdg_toplevel.title orelse "(null)"});
|
||||||
server.root.addView(view);
|
|
||||||
} else {
|
} else {
|
||||||
std.log.err("Unable to allocate new view", .{});
|
std.log.err("Unable to allocate new view", .{});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
src/view.zig
23
src/view.zig
|
|
@ -8,7 +8,7 @@ const gpa = std.heap.c_allocator;
|
||||||
const server = &@import("main.zig").server;
|
const server = &@import("main.zig").server;
|
||||||
|
|
||||||
xdg_toplevel: *wlr.XdgToplevel,
|
xdg_toplevel: *wlr.XdgToplevel,
|
||||||
scene_tree: ?*wlr.SceneTree,
|
scene_tree: *wlr.SceneTree,
|
||||||
|
|
||||||
// XdgTopLevel Listeners
|
// XdgTopLevel Listeners
|
||||||
map: wl.Listener(void) = wl.Listener(void).init(handleMap),
|
map: wl.Listener(void) = wl.Listener(void).init(handleMap),
|
||||||
|
|
@ -25,25 +25,28 @@ pub fn initFromTopLevel(xdg_toplevel: *wlr.XdgToplevel) ?*View {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const xdg_surface = xdg_toplevel.base;
|
||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.xdg_toplevel = xdg_toplevel,
|
.xdg_toplevel = xdg_toplevel,
|
||||||
.scene_tree = null,
|
.scene_tree = server.root.scene.tree.createSceneXdgSurface(xdg_surface) catch {
|
||||||
|
gpa.destroy(self);
|
||||||
|
std.log.err("failed to allocate new toplevel", .{});
|
||||||
|
return null;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Debug what we have
|
self.scene_tree.node.data = self;
|
||||||
// std.log.debug("xdg_toplevel ptr: {*}", .{xdg_toplevel});
|
std.log.debug("Set scene_tree.node.data = {*} for new View", .{self});
|
||||||
// std.log.debug("xdg_toplevel.base ptr: {*}", .{xdg_toplevel.base});
|
std.log.debug("scene_tree address = {*}", .{self.scene_tree});
|
||||||
// std.log.debug("xdg_toplevel.base type: {}", .{@TypeOf(xdg_toplevel.base)});
|
std.log.debug("Verifying: scene_tree.node.data = {*}", .{self.scene_tree.node.data});
|
||||||
|
|
||||||
const xdg_surface = xdg_toplevel.base;
|
|
||||||
std.log.debug("surface events type: {}", .{@TypeOf(xdg_surface.surface.events)});
|
|
||||||
|
|
||||||
|
xdg_surface.data = self.scene_tree;
|
||||||
// Attach listeners
|
// Attach listeners
|
||||||
xdg_surface.surface.events.map.add(&self.map);
|
xdg_surface.surface.events.map.add(&self.map);
|
||||||
xdg_surface.surface.events.unmap.add(&self.unmap);
|
xdg_surface.surface.events.unmap.add(&self.unmap);
|
||||||
xdg_surface.surface.events.commit.add(&self.commit);
|
xdg_surface.surface.events.commit.add(&self.commit);
|
||||||
xdg_toplevel.events.destroy.add(&self.destroy);
|
xdg_toplevel.events.destroy.add(&self.destroy);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue