mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
gtk: cleanup code in *Paned
This commit is contained in:

committed by
Mitchell Hashimoto

parent
d88898fc61
commit
2d7a81c0db
@ -44,8 +44,8 @@ pub fn init(self: *Paned, window: *Window, label_text: *c.GtkWidget) !void {
|
|||||||
.window = window,
|
.window = window,
|
||||||
.label_text = label_text,
|
.label_text = label_text,
|
||||||
.paned = undefined,
|
.paned = undefined,
|
||||||
.child1 = .empty,
|
.child1 = .none,
|
||||||
.child2 = .empty,
|
.child2 = .none,
|
||||||
.parent = undefined,
|
.parent = undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -53,14 +53,6 @@ pub fn init(self: *Paned, window: *Window, label_text: *c.GtkWidget) !void {
|
|||||||
const gtk_paned: *c.GtkPaned = @ptrCast(paned);
|
const gtk_paned: *c.GtkPaned = @ptrCast(paned);
|
||||||
errdefer c.gtk_widget_destroy(paned);
|
errdefer c.gtk_widget_destroy(paned);
|
||||||
self.paned = gtk_paned;
|
self.paned = gtk_paned;
|
||||||
|
|
||||||
// const surface = try self.newSurface(self.window.actionSurface());
|
|
||||||
// // We know that both panels are currently empty, so we maximize the 1st
|
|
||||||
// c.gtk_paned_set_position(self.paned, 100);
|
|
||||||
// const child_widget: *c.GtkWidget = @ptrCast(surface.gl_area);
|
|
||||||
// const child = Child{ .surface = surface };
|
|
||||||
// c.gtk_paned_pack1(self.paned, child_widget, 1, 1);
|
|
||||||
// self.child1 = child;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn newSurface(self: *Paned, tab: *Tab, parent_: ?*CoreSurface) !*Surface {
|
pub fn newSurface(self: *Paned, tab: *Tab, parent_: ?*CoreSurface) !*Surface {
|
||||||
@ -87,7 +79,7 @@ pub fn newSurface(self: *Paned, tab: *Tab, parent_: ?*CoreSurface) !*Surface {
|
|||||||
.tab = tab,
|
.tab = tab,
|
||||||
.parent = .{ .paned = .{
|
.parent = .{ .paned = .{
|
||||||
self,
|
self,
|
||||||
Position.end,
|
.end,
|
||||||
} },
|
} },
|
||||||
.gl_area = @ptrCast(gl_area),
|
.gl_area = @ptrCast(gl_area),
|
||||||
.title_label = @ptrCast(self.label_text),
|
.title_label = @ptrCast(self.label_text),
|
||||||
@ -97,36 +89,28 @@ pub fn newSurface(self: *Paned, tab: *Tab, parent_: ?*CoreSurface) !*Surface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn removeChildren(self: *Paned) void {
|
pub fn removeChildren(self: *Paned) void {
|
||||||
|
assert(self.child1 != .none);
|
||||||
|
assert(self.child2 != .none);
|
||||||
|
self.child1 = .none;
|
||||||
|
self.child2 = .none;
|
||||||
c.gtk_paned_set_start_child(@ptrCast(self.paned), null);
|
c.gtk_paned_set_start_child(@ptrCast(self.paned), null);
|
||||||
c.gtk_paned_set_end_child(@ptrCast(self.paned), null);
|
c.gtk_paned_set_end_child(@ptrCast(self.paned), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addChild1Surface(self: *Paned, surface: *Surface) void {
|
pub fn addChild1Surface(self: *Paned, surface: *Surface) void {
|
||||||
assert(self.child1.is_empty());
|
assert(self.child1 == .none);
|
||||||
self.child1 = Tab.Child{ .surface = surface };
|
self.child1 = Tab.Child{ .surface = surface };
|
||||||
surface.setParent(Parent{ .paned = .{ self, Position.start } });
|
surface.setParent(Parent{ .paned = .{ self, .start } });
|
||||||
c.gtk_paned_set_start_child(@ptrCast(self.paned), @ptrCast(surface.gl_area));
|
c.gtk_paned_set_start_child(@ptrCast(self.paned), @ptrCast(surface.gl_area));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addChild2Surface(self: *Paned, surface: *Surface) void {
|
pub fn addChild2Surface(self: *Paned, surface: *Surface) void {
|
||||||
assert(self.child2.is_empty());
|
assert(self.child2 == .none);
|
||||||
self.child2 = Tab.Child{ .surface = surface };
|
self.child2 = Tab.Child{ .surface = surface };
|
||||||
surface.setParent(Parent{ .paned = .{ self, Position.end } });
|
surface.setParent(Parent{ .paned = .{ self, .end } });
|
||||||
c.gtk_paned_set_end_child(@ptrCast(self.paned), @ptrCast(surface.gl_area));
|
c.gtk_paned_set_end_child(@ptrCast(self.paned), @ptrCast(surface.gl_area));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn removeChild1(self: *Paned) void {
|
|
||||||
assert(!self.child1.is_empty());
|
|
||||||
self.child1 = .empty;
|
|
||||||
c.gtk_paned_set_start_child(@ptrCast(self.paned), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn removeChild2(self: *Paned) void {
|
|
||||||
assert(!self.child2.is_empty());
|
|
||||||
self.child2 = .empty;
|
|
||||||
c.gtk_paned_set_end_child(@ptrCast(self.paned), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn splitStartPosition(self: *Paned, orientation: c.GtkOrientation) !void {
|
pub fn splitStartPosition(self: *Paned, orientation: c.GtkOrientation) !void {
|
||||||
_ = orientation;
|
_ = orientation;
|
||||||
_ = self;
|
_ = self;
|
||||||
|
@ -18,17 +18,7 @@ pub const GHOSTTY_TAB = "ghostty_tab";
|
|||||||
pub const Child = union(enum) {
|
pub const Child = union(enum) {
|
||||||
surface: *Surface,
|
surface: *Surface,
|
||||||
paned: *Paned,
|
paned: *Paned,
|
||||||
|
none,
|
||||||
empty,
|
|
||||||
|
|
||||||
const Self = @This();
|
|
||||||
|
|
||||||
pub fn is_empty(self: Self) bool {
|
|
||||||
switch (self) {
|
|
||||||
Child.empty => return true,
|
|
||||||
else => return false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
window: *Window,
|
window: *Window,
|
||||||
@ -163,10 +153,10 @@ pub fn removeChild(self: *Tab) void {
|
|||||||
const widget = switch (self.child) {
|
const widget = switch (self.child) {
|
||||||
.surface => |surface| @as(*c.GtkWidget, @ptrCast(surface.gl_area)),
|
.surface => |surface| @as(*c.GtkWidget, @ptrCast(surface.gl_area)),
|
||||||
.paned => |paned| @as(*c.GtkWidget, @ptrCast(@alignCast(paned.paned))),
|
.paned => |paned| @as(*c.GtkWidget, @ptrCast(@alignCast(paned.paned))),
|
||||||
.empty => return,
|
.none => return,
|
||||||
};
|
};
|
||||||
c.gtk_box_remove(self.box, widget);
|
c.gtk_box_remove(self.box, widget);
|
||||||
self.child = .empty;
|
self.child = .none;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setChild(self: *Tab, newChild: Child) void {
|
pub fn setChild(self: *Tab, newChild: Child) void {
|
||||||
@ -183,23 +173,15 @@ pub fn setChild(self: *Tab, newChild: Child) void {
|
|||||||
const widget = @as(*c.GtkWidget, @ptrCast(@alignCast(paned.paned)));
|
const widget = @as(*c.GtkWidget, @ptrCast(@alignCast(paned.paned)));
|
||||||
c.gtk_box_append(self.box, widget);
|
c.gtk_box_append(self.box, widget);
|
||||||
},
|
},
|
||||||
.empty => return,
|
.none => return,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.child = newChild;
|
self.child = newChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setChildSurface(self: *Tab, surface: *Surface, gl_area: *c.GtkWidget) !void {
|
|
||||||
c.gtk_box_append(self.box, gl_area);
|
|
||||||
|
|
||||||
const parent = Parent{ .tab = self };
|
|
||||||
surface.setParent(parent);
|
|
||||||
|
|
||||||
self.child = .{ .surface = surface };
|
|
||||||
}
|
|
||||||
|
|
||||||
fn gtkTabCloseClick(_: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {
|
fn gtkTabCloseClick(_: *c.GtkButton, ud: ?*anyopaque) callconv(.C) void {
|
||||||
const tab: *Tab = @ptrCast(@alignCast(ud));
|
const tab: *Tab = @ptrCast(@alignCast(ud));
|
||||||
_ = tab;
|
_ = tab;
|
||||||
|
// TODO: Fix tab closing logic
|
||||||
log.info("tab close click\n", .{});
|
log.info("tab close click\n", .{});
|
||||||
}
|
}
|
||||||
|
@ -195,13 +195,26 @@ pub fn deinit(self: *Window) void {
|
|||||||
|
|
||||||
/// Add a new tab to this window.
|
/// Add a new tab to this window.
|
||||||
pub fn newTab(self: *Window, parentSurface: ?*CoreSurface) !void {
|
pub fn newTab(self: *Window, parentSurface: ?*CoreSurface) !void {
|
||||||
const tab = try Tab.create(self.app.core_app.alloc, self, parentSurface);
|
const alloc = self.app.core_app.alloc;
|
||||||
try self.tabs.append(self.app.core_app.alloc, tab);
|
const tab = try Tab.create(alloc, self, parentSurface);
|
||||||
|
try self.tabs.append(alloc, tab);
|
||||||
|
|
||||||
log.info("\n\n\nnewTab. New tabs len={}\n", .{self.tabs.items.len});
|
|
||||||
// TODO: When this is triggered through a GTK action, the new surface
|
// TODO: When this is triggered through a GTK action, the new surface
|
||||||
// redraws correctly. When it's triggered through keyboard shortcuts, it
|
// redraws correctly. When it's triggered through keyboard shortcuts, it
|
||||||
// does not (cursor doesn't blink).
|
// does not (cursor doesn't blink) unless reactivated by refocusing.
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn removeTab(self: *Window, tab: *Tab) !void {
|
||||||
|
// Remove the tab from our stored tabs.
|
||||||
|
const tab_idx = for (self.tabs.items, 0..) |t, i| {
|
||||||
|
if (t == tab) break i;
|
||||||
|
} else null;
|
||||||
|
|
||||||
|
// TODO: Shrink capacity?
|
||||||
|
if (tab_idx) |idx| _ = self.tabs.orderedRemove(idx) else return error.TabNotFound;
|
||||||
|
|
||||||
|
// Deallocate the tab
|
||||||
|
self.app.core_app.alloc.destroy(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close the tab for the given notebook page. This will automatically
|
/// Close the tab for the given notebook page. This will automatically
|
||||||
@ -215,20 +228,10 @@ fn closeTab(self: *Window, page: *c.GtkNotebookPage) void {
|
|||||||
));
|
));
|
||||||
|
|
||||||
// Remove the tab from our stored tabs.
|
// Remove the tab from our stored tabs.
|
||||||
const tab_idx = for (self.tabs.items, 0..) |t, i| {
|
self.removeTab(tab) catch |err| {
|
||||||
if (t == tab) break i;
|
log.warn("tab {} not removable: {}", .{ page_idx, err });
|
||||||
} else null;
|
|
||||||
// TODO: Shrink capacity?
|
|
||||||
if (tab_idx) |idx| {
|
|
||||||
_ = self.tabs.orderedRemove(idx);
|
|
||||||
} else {
|
|
||||||
log.info("tab of page {} not found in managed tabs list\n", .{page_idx});
|
|
||||||
return;
|
return;
|
||||||
}
|
};
|
||||||
// Deallocate the tab
|
|
||||||
self.app.core_app.alloc.destroy(tab);
|
|
||||||
|
|
||||||
log.info("\n\n\ncloseTab. New tabs len={}\n", .{self.tabs.items.len});
|
|
||||||
|
|
||||||
// Now remove the page
|
// Now remove the page
|
||||||
c.gtk_notebook_remove_page(self.notebook, page_idx);
|
c.gtk_notebook_remove_page(self.notebook, page_idx);
|
||||||
@ -293,8 +296,7 @@ pub fn closeSurface(self: *Window, surface: *Surface) void {
|
|||||||
defer c.g_object_unref(sibling_object);
|
defer c.g_object_unref(sibling_object);
|
||||||
|
|
||||||
// Remove children and kill Paned.
|
// Remove children and kill Paned.
|
||||||
paned.removeChild1();
|
paned.removeChildren();
|
||||||
paned.removeChild2();
|
|
||||||
defer alloc.destroy(paned);
|
defer alloc.destroy(paned);
|
||||||
|
|
||||||
// Remove children from Paned we were part of.
|
// Remove children from Paned we were part of.
|
||||||
@ -478,7 +480,6 @@ fn gtkCloseRequest(v: *c.GtkWindow, ud: ?*anyopaque) callconv(.C) bool {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("WE ARE HERE", .{});
|
|
||||||
// Setup our basic message
|
// Setup our basic message
|
||||||
const alert = c.gtk_message_dialog_new(
|
const alert = c.gtk_message_dialog_new(
|
||||||
self.window,
|
self.window,
|
||||||
|
Reference in New Issue
Block a user