mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-24 12:46:10 +03:00
apprt/gtk: make focusCurrentTab safe to call at any time
This commit is contained in:
@ -35,7 +35,7 @@ elem: Surface.Container.Elem,
|
||||
// We'll update this every time a Surface gains focus, so that we have it
|
||||
// when we switch to another Tab. Then when we switch back to this tab, we
|
||||
// can easily re-focus that terminal.
|
||||
focus_child: *Surface,
|
||||
focus_child: ?*Surface,
|
||||
|
||||
pub fn create(alloc: Allocator, window: *Window, parent_: ?*CoreSurface) !*Tab {
|
||||
var tab = try alloc.create(Tab);
|
||||
@ -52,7 +52,7 @@ pub fn init(self: *Tab, window: *Window, parent_: ?*CoreSurface) !void {
|
||||
.label_text = undefined,
|
||||
.box = undefined,
|
||||
.elem = undefined,
|
||||
.focus_child = undefined,
|
||||
.focus_child = null,
|
||||
};
|
||||
|
||||
// Create a Box in which we'll later keep either Surface or Split.
|
||||
|
@ -476,7 +476,8 @@ pub fn toggleWindowDecorations(self: *Window) void {
|
||||
/// Grabs focus on the currently selected tab.
|
||||
pub fn focusCurrentTab(self: *Window) void {
|
||||
const tab = self.notebook.currentTab() orelse return;
|
||||
const gl_area = @as(*c.GtkWidget, @ptrCast(tab.focus_child.gl_area));
|
||||
const surface = tab.focus_child orelse return;
|
||||
const gl_area = @as(*c.GtkWidget, @ptrCast(surface.gl_area));
|
||||
_ = c.gtk_widget_grab_focus(gl_area);
|
||||
}
|
||||
|
||||
@ -760,7 +761,8 @@ fn gtkActionReset(
|
||||
/// Returns the surface to use for an action.
|
||||
fn actionSurface(self: *Window) ?*CoreSurface {
|
||||
const tab = self.notebook.currentTab() orelse return null;
|
||||
return &tab.focus_child.core_surface;
|
||||
const surface = tab.focus_child orelse return null;
|
||||
return &surface.core_surface;
|
||||
}
|
||||
|
||||
fn userdataSelf(ud: *anyopaque) *Window {
|
||||
|
Reference in New Issue
Block a user