mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
gtk: close tabs with middle-click
Follow the behaviour of other tabbed interfaces like browsers, editors, and file-managers. GTK code is based on `/src/apprt/gtk/ImguiWidget.zig`
This commit is contained in:
@ -132,9 +132,15 @@ pub fn init(self: *Tab, window: *Window, parent_: ?*CoreSurface) !void {
|
|||||||
// Set the userdata of the box to point to this tab.
|
// Set the userdata of the box to point to this tab.
|
||||||
c.g_object_set_data(@ptrCast(box_widget), GHOSTTY_TAB, self);
|
c.g_object_set_data(@ptrCast(box_widget), GHOSTTY_TAB, self);
|
||||||
|
|
||||||
|
// Clicks
|
||||||
|
const gesture_tab_click = c.gtk_gesture_click_new();
|
||||||
|
c.gtk_gesture_single_set_button(@ptrCast(gesture_tab_click), 0);
|
||||||
|
c.gtk_widget_add_controller(label_box_widget, @ptrCast(gesture_tab_click));
|
||||||
|
|
||||||
// Attach all events
|
// Attach all events
|
||||||
_ = c.g_signal_connect_data(label_close, "clicked", c.G_CALLBACK(>kTabCloseClick), self, null, c.G_CONNECT_DEFAULT);
|
_ = c.g_signal_connect_data(label_close, "clicked", c.G_CALLBACK(>kTabCloseClick), self, null, c.G_CONNECT_DEFAULT);
|
||||||
_ = c.g_signal_connect_data(box_widget, "destroy", c.G_CALLBACK(>kDestroy), self, null, c.G_CONNECT_DEFAULT);
|
_ = c.g_signal_connect_data(box_widget, "destroy", c.G_CALLBACK(>kDestroy), self, null, c.G_CONNECT_DEFAULT);
|
||||||
|
_ = c.g_signal_connect_data(gesture_tab_click, "pressed", c.G_CALLBACK(>kTabClick), self, null, c.G_CONNECT_DEFAULT);
|
||||||
|
|
||||||
// Switch to the new tab
|
// Switch to the new tab
|
||||||
c.gtk_notebook_set_current_page(window.notebook, page_idx);
|
c.gtk_notebook_set_current_page(window.notebook, page_idx);
|
||||||
@ -185,3 +191,17 @@ fn gtkDestroy(v: *c.GtkWidget, ud: ?*anyopaque) callconv(.C) void {
|
|||||||
const tab: *Tab = @ptrCast(@alignCast(ud));
|
const tab: *Tab = @ptrCast(@alignCast(ud));
|
||||||
tab.destroy(tab.window.app.core_app.alloc);
|
tab.destroy(tab.window.app.core_app.alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gtkTabClick(
|
||||||
|
gesture: *c.GtkGestureClick,
|
||||||
|
_: c.gint,
|
||||||
|
_: c.gdouble,
|
||||||
|
_: c.gdouble,
|
||||||
|
ud: ?*anyopaque,
|
||||||
|
) callconv(.C) void {
|
||||||
|
const self: *Tab = @ptrCast(@alignCast(ud));
|
||||||
|
const gtk_button = c.gtk_gesture_single_get_current_button(@ptrCast(gesture));
|
||||||
|
if (gtk_button == c.GDK_BUTTON_MIDDLE) {
|
||||||
|
self.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user