From 19f7b37bb393c122a4a66bf40a19b7b23a1bfd69 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Tue, 24 Oct 2023 06:54:41 +0200 Subject: [PATCH] gtk: move Child/Parent/Position into same file --- src/apprt/gtk/Paned.zig | 17 +++++++++-------- src/apprt/gtk/Surface.zig | 3 +-- src/apprt/gtk/Tab.zig | 9 ++------- src/apprt/gtk/{parent.zig => relation.zig} | 9 ++++++++- 4 files changed, 20 insertions(+), 18 deletions(-) rename src/apprt/gtk/{parent.zig => relation.zig} (62%) diff --git a/src/apprt/gtk/Paned.zig b/src/apprt/gtk/Paned.zig index 1c51f7cd8..70905d225 100644 --- a/src/apprt/gtk/Paned.zig +++ b/src/apprt/gtk/Paned.zig @@ -10,8 +10,9 @@ const CoreSurface = @import("../../Surface.zig"); const Window = @import("Window.zig"); const Surface = @import("Surface.zig"); const Tab = @import("Tab.zig"); -const Position = @import("parent.zig").Position; -const Parent = @import("parent.zig").Parent; +const Position = @import("relation.zig").Position; +const Parent = @import("relation.zig").Parent; +const Child = @import("relation.zig").Child; const c = @import("c.zig"); /// We'll need to keep a reference to the Window this belongs to for various reasons @@ -26,8 +27,8 @@ paned: *c.GtkPaned, // We have two children, each of which can be either a Surface, another pane, // or empty. We're going to keep track of which each child is here. -child1: Tab.Child, -child2: Tab.Child, +child1: Child, +child2: Child, // We also hold a reference to our parent widget, so that when we close we can either // maximize the parent pane, or close the tab. @@ -126,28 +127,28 @@ pub fn removeChildInPosition(self: *Paned, position: Position) void { pub fn addChild1Surface(self: *Paned, surface: *Surface) void { assert(self.child1 == .none); - self.child1 = Tab.Child{ .surface = surface }; + self.child1 = Child{ .surface = surface }; surface.setParent(Parent{ .paned = .{ self, .start } }); c.gtk_paned_set_start_child(@ptrCast(self.paned), @ptrCast(surface.gl_area)); } pub fn addChild2Surface(self: *Paned, surface: *Surface) void { assert(self.child2 == .none); - self.child2 = Tab.Child{ .surface = surface }; + self.child2 = Child{ .surface = surface }; surface.setParent(Parent{ .paned = .{ self, .end } }); c.gtk_paned_set_end_child(@ptrCast(self.paned), @ptrCast(surface.gl_area)); } pub fn addChild1Paned(self: *Paned, paned: *Paned) void { assert(self.child1 == .none); - self.child1 = Tab.Child{ .paned = paned }; + self.child1 = Child{ .paned = paned }; paned.setParent(Parent{ .paned = .{ self, .start } }); c.gtk_paned_set_start_child(@ptrCast(self.paned), @ptrCast(@alignCast(paned.paned))); } pub fn addChild2Paned(self: *Paned, paned: *Paned) void { assert(self.child2 == .none); - self.child2 = Tab.Child{ .paned = paned }; + self.child2 = Child{ .paned = paned }; paned.setParent(Parent{ .paned = .{ self, .end } }); c.gtk_paned_set_end_child(@ptrCast(self.paned), @ptrCast(@alignCast(paned.paned))); } diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index e63e6855f..532bba67c 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -16,8 +16,7 @@ const Paned = @import("Paned.zig"); const Tab = @import("Tab.zig"); const Window = @import("Window.zig"); const ClipboardConfirmationWindow = @import("ClipboardConfirmationWindow.zig"); -const Position = @import("parent.zig").Position; -const Parent = @import("parent.zig").Parent; +const Parent = @import("relation.zig").Parent; const inspector = @import("inspector.zig"); const gtk_key = @import("key.zig"); const c = @import("c.zig"); diff --git a/src/apprt/gtk/Tab.zig b/src/apprt/gtk/Tab.zig index 2fde5b373..e076ebee2 100644 --- a/src/apprt/gtk/Tab.zig +++ b/src/apprt/gtk/Tab.zig @@ -6,7 +6,8 @@ const assert = std.debug.assert; const font = @import("../../font/main.zig"); const CoreSurface = @import("../../Surface.zig"); const Paned = @import("Paned.zig"); -const Parent = @import("parent.zig").Parent; +const Parent = @import("relation.zig").Parent; +const Child = @import("relation.zig").Child; const Surface = @import("Surface.zig"); const Window = @import("Window.zig"); const c = @import("c.zig"); @@ -15,12 +16,6 @@ const log = std.log.scoped(.gtk); pub const GHOSTTY_TAB = "ghostty_tab"; -pub const Child = union(enum) { - surface: *Surface, - paned: *Paned, - none, -}; - window: *Window, label_text: *c.GtkLabel, close_button: *c.GtkButton, diff --git a/src/apprt/gtk/parent.zig b/src/apprt/gtk/relation.zig similarity index 62% rename from src/apprt/gtk/parent.zig rename to src/apprt/gtk/relation.zig index 7c4539fa0..8d0e8b5cf 100644 --- a/src/apprt/gtk/parent.zig +++ b/src/apprt/gtk/relation.zig @@ -1,3 +1,4 @@ +const Surface = @import("Surface.zig"); const Paned = @import("Paned.zig"); const Tab = @import("Tab.zig"); @@ -7,10 +8,16 @@ pub const Position = enum { }; pub const Parent = union(enum) { - none: void, + none, tab: *Tab, paned: struct { *Paned, Position, }, }; + +pub const Child = union(enum) { + none, + surface: *Surface, + paned: *Paned, +};