From aaa6ff8884a3e0494dedb3225c78f5a54b7f5cbd Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Thu, 26 Oct 2023 06:52:47 +0200 Subject: [PATCH] gtk: introduce helper method on Paned --- src/apprt/gtk/Paned.zig | 43 ++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/src/apprt/gtk/Paned.zig b/src/apprt/gtk/Paned.zig index 65a592043..5e8ccec39 100644 --- a/src/apprt/gtk/Paned.zig +++ b/src/apprt/gtk/Paned.zig @@ -110,35 +110,18 @@ pub fn newSurface(self: *Paned, tab: *Tab, parent_: ?*CoreSurface) !*Surface { return surface; } -pub fn focusSurfaceInPosition(self: *Paned, position: Position) void { - const child = switch (position) { - .start => self.child1, - .end => self.child2, - }; - - const surface = switch (child) { - .surface => |surface| surface, - else => return, - }; - - const widget = @as(*c.GtkWidget, @ptrCast(surface.gl_area)); - _ = c.gtk_widget_grab_focus(widget); -} - pub fn setParent(self: *Paned, parent: Parent) void { self.parent = parent; } -pub fn splitSurfaceInPosition(self: *Paned, position: Position, direction: input.SplitDirection) !void { - const child = switch (position) { - .start => self.child1, - .end => self.child2, - }; +pub fn focusSurfaceInPosition(self: *Paned, position: Position) void { + const surface: *Surface = self.surfaceInPosition(position) orelse return; + const widget = @as(*c.GtkWidget, @ptrCast(surface.gl_area)); + _ = c.gtk_widget_grab_focus(widget); +} - const surface: *Surface = switch (child) { - .surface => |surface| surface, - else => return, - }; +pub fn splitSurfaceInPosition(self: *Paned, position: Position, direction: input.SplitDirection) !void { + const surface: *Surface = self.surfaceInPosition(position) orelse return; // Keep explicit reference to surface gl_area before we remove it. const object: *c.GObject = @ptrCast(surface.gl_area); @@ -237,3 +220,15 @@ pub fn deinit(self: *Paned, alloc: Allocator) void { }, } } + +fn surfaceInPosition(self: *Paned, position: Position) ?*Surface { + const child = switch (position) { + .start => self.child1, + .end => self.child2, + }; + + return switch (child) { + .surface => |surface| surface, + else => null, + }; +}