mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 00:36:07 +03:00
gtk: restore focus-grabbing after closing one side in split
This commit is contained in:

committed by
Mitchell Hashimoto

parent
a18fb4a661
commit
236e57a1f4
@ -112,8 +112,6 @@ inline fn removeChild(self: *Split, remove: Surface.Container.Elem, keep: Surfac
|
||||
const window = self.container.window() orelse return;
|
||||
const alloc = window.app.core_app.alloc;
|
||||
|
||||
// TODO: Grab focus
|
||||
|
||||
// Keep a reference to the side that we want to keep, so it doesn't get
|
||||
// destroyed when it's removed from our underlying GtkPaned.
|
||||
const keep_object: *c.GObject = @ptrCast(keep.widget());
|
||||
@ -127,6 +125,9 @@ inline fn removeChild(self: *Split, remove: Surface.Container.Elem, keep: Surfac
|
||||
// Our container must become whatever our top left is
|
||||
self.container.replace(keep);
|
||||
|
||||
// Grab focus of the left-over side
|
||||
keep.grabFocus();
|
||||
|
||||
// TODO: is this correct?
|
||||
remove.deinit(alloc);
|
||||
alloc.destroy(self);
|
||||
@ -149,6 +150,11 @@ pub fn replace(
|
||||
self.updateChildren();
|
||||
}
|
||||
|
||||
// grabFocus grabs the focus of the top-left element.
|
||||
pub fn grabFocus(self: *Split) void {
|
||||
self.top_left.grabFocus();
|
||||
}
|
||||
|
||||
/// Update the paned children to represent the current state.
|
||||
/// This should be called anytime the top/left or bottom/right
|
||||
/// element is changed.
|
||||
|
@ -86,11 +86,11 @@ pub const Container = union(enum) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn debugName(self: Elem) []const u8 {
|
||||
return switch (self) {
|
||||
.surface => "surface",
|
||||
.split => "split",
|
||||
};
|
||||
pub fn grabFocus(self: Elem) void {
|
||||
switch (self) {
|
||||
.surface => |s| s.grabFocus(),
|
||||
.split => |s| s.grabFocus(),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -132,14 +132,10 @@ pub const Container = union(enum) {
|
||||
/// from a surface to a split or a split back to a surface or
|
||||
/// a split to a nested split and so on.
|
||||
pub fn replace(self: Container, elem: Elem) void {
|
||||
log.debug("Container.replace. self={s}, elem={s}", .{ self.debugName(), elem.debugName() });
|
||||
|
||||
// Move the element into the container
|
||||
switch (self) {
|
||||
.none => {},
|
||||
.tab_ => |t| {
|
||||
t.replaceElem(elem);
|
||||
},
|
||||
.tab_ => |t| t.replaceElem(elem),
|
||||
inline .split_tl, .split_br => |ptr| {
|
||||
const s = self.split().?;
|
||||
s.replace(ptr, elem);
|
||||
@ -154,7 +150,6 @@ pub const Container = union(enum) {
|
||||
/// children to effectively notify they're containing that
|
||||
/// all children at this level are exiting.
|
||||
pub fn remove(self: Container) void {
|
||||
log.warn("Container.remove", .{});
|
||||
switch (self) {
|
||||
.none => {},
|
||||
.tab_ => |t| t.closeElem(),
|
||||
@ -162,15 +157,6 @@ pub const Container = union(enum) {
|
||||
.split_br => self.split().?.removeBottomRight(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn debugName(self: Container) []const u8 {
|
||||
return switch (self) {
|
||||
.none => "none",
|
||||
.tab_ => "tab",
|
||||
.split_tl => "split_tl",
|
||||
.split_br => "split_br",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/// Whether the surface has been realized or not yet. When a surface is
|
||||
@ -541,22 +527,8 @@ pub fn getTitleLabel(self: *Surface) ?*c.GtkWidget {
|
||||
}
|
||||
|
||||
pub fn newSplit(self: *Surface, direction: input.SplitDirection) !void {
|
||||
log.debug("splitting direction={}", .{direction});
|
||||
const alloc = self.app.core_app.alloc;
|
||||
_ = try Split.create(alloc, self, direction);
|
||||
|
||||
// switch (self.parent) {
|
||||
// .none => return,
|
||||
// .paned => |parent_paned_tuple| {
|
||||
// const paned = parent_paned_tuple[0];
|
||||
// const position = parent_paned_tuple[1];
|
||||
//
|
||||
// try paned.splitSurfaceInPosition(position, direction);
|
||||
// },
|
||||
// .tab => |tab| {
|
||||
// try tab.splitSurface(direction);
|
||||
// },
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn newTab(self: *Surface) !void {
|
||||
@ -1059,13 +1031,7 @@ fn gtkMouseDown(
|
||||
// If we don't have focus, grab it.
|
||||
const gl_widget = @as(*c.GtkWidget, @ptrCast(self.gl_area));
|
||||
if (c.gtk_widget_has_focus(gl_widget) == 0) {
|
||||
if (self.container.tab()) |tab| tab.focus_child = self;
|
||||
_ = c.gtk_widget_grab_focus(gl_widget);
|
||||
|
||||
// If we have siblings, we also update the title, since it means
|
||||
// another sibling might have updated the title.
|
||||
// TODO: fixme
|
||||
//if (self.parent != Parent.tab) self.updateTitleLabels();
|
||||
self.grabFocus();
|
||||
}
|
||||
|
||||
self.core_surface.mouseButtonCallback(.press, button, mods) catch |err| {
|
||||
|
Reference in New Issue
Block a user