gtk: simplify code when creating new split

This commit is contained in:
Thorsten Ball
2023-10-20 07:03:41 +02:00
committed by Mitchell Hashimoto
parent 601eed24c4
commit 98a5016598

View File

@ -347,46 +347,36 @@ pub fn toggleFullscreen(self: *Surface, mac_non_native: configpkg.NonNativeFulls
} }
pub fn newSplit(self: *Surface, direction: input.SplitDirection) !void { pub fn newSplit(self: *Surface, direction: input.SplitDirection) !void {
log.info("surface.newSplit. direction={}", .{direction}); log.debug("new split, direction: {}", .{direction});
switch (self.parent) { switch (self.parent) {
.none => { .none => return,
log.info("no parent\n", .{});
},
.paned => { .paned => {
log.info("parent is paned \n", .{}); // TODO: Implement this
log.info("parent is paned", .{});
}, },
.tab => |tab| { .tab => |tab| {
const tab_idx = for (self.window.tabs.items, 0..) |t, i| { const label_text: *c.GtkWidget = switch (self.title) {
if (t == tab) break i; .none => return,
} else null;
const label_text: ?*c.GtkWidget = switch (self.title) {
.none => null,
.label => |label| l: { .label => |label| l: {
const widget = @as(*c.GtkWidget, @ptrCast(@alignCast(label))); const widget = @as(*c.GtkWidget, @ptrCast(@alignCast(label)));
break :l widget; break :l widget;
}, },
}; };
if (label_text) |text| { tab.removeChild();
tab.removeChild();
const paned = try Paned.create(self.app.core_app.alloc, self.window, text); const paned = try Paned.create(self.app.core_app.alloc, self.window, label_text);
const new_surface = try paned.newSurface(tab, &self.core_surface);
// This sets .parent on each surface
paned.addChild1Surface(self);
paned.addChild2Surface(new_surface);
const new_surface = try paned.newSurface(tab, &self.core_surface); tab.setChild(.{ .paned = paned });
// // This sets .parent on each surface
paned.addChild1Surface(self);
paned.addChild2Surface(new_surface);
tab.setChild(.{ .paned = paned }); // FOCUS ON NEW SURFACE
const widget = @as(*c.GtkWidget, @ptrCast(new_surface.gl_area));
// FOCUS ON NEW SURFACE _ = c.gtk_widget_grab_focus(widget);
const widget = @as(*c.GtkWidget, @ptrCast(new_surface.gl_area));
_ = c.gtk_widget_grab_focus(widget);
} else {
log.info("no label text: {?}\n", .{tab_idx});
}
}, },
} }
} }