From 66ed72f486189d84d23b5c50e01eaf6c1a59a85a Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Fri, 27 Dec 2024 20:39:28 +0100 Subject: [PATCH] gtk: equalize on double clicking the split handle --- src/apprt/gtk/Split.zig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/apprt/gtk/Split.zig b/src/apprt/gtk/Split.zig index 83ba04da0..61c2edece 100644 --- a/src/apprt/gtk/Split.zig +++ b/src/apprt/gtk/Split.zig @@ -111,6 +111,16 @@ pub fn init( // Keep a long-lived reference, which we unref in destroy. _ = c.g_object_ref(paned); + // Clicks + const gesture_click = c.gtk_gesture_click_new(); + errdefer c.g_object_unref(gesture_click); + c.gtk_event_controller_set_propagation_phase(@ptrCast(gesture_click), c.GTK_PHASE_CAPTURE); + c.gtk_gesture_single_set_button(@ptrCast(gesture_click), 1); + c.gtk_widget_add_controller(paned, @ptrCast(gesture_click)); + + // Signals + _ = c.g_signal_connect_data(gesture_click, "pressed", c.G_CALLBACK(>kMouseDown), self, null, c.G_CONNECT_DEFAULT); + // Update all of our containers to point to the right place. // The split has to point to where the sibling pointed to because // we're inheriting its parent. The sibling points to its location @@ -236,6 +246,19 @@ pub fn equalize(self: *Split) f64 { return weight; } +fn gtkMouseDown( + _: *c.GtkGestureClick, + n_press: c.gint, + _: c.gdouble, + _: c.gdouble, + ud: ?*anyopaque, +) callconv(.C) void { + if (n_press == 2) { + const self: *Split = @ptrCast(@alignCast(ud)); + _ = equalize(self); + } +} + // maxPosition returns the maximum position of the GtkPaned, which is the // "max-position" attribute. fn maxPosition(self: *Split) f64 {