mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +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 window = self.container.window() orelse return;
|
||||||
const alloc = window.app.core_app.alloc;
|
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
|
// 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.
|
// destroyed when it's removed from our underlying GtkPaned.
|
||||||
const keep_object: *c.GObject = @ptrCast(keep.widget());
|
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
|
// Our container must become whatever our top left is
|
||||||
self.container.replace(keep);
|
self.container.replace(keep);
|
||||||
|
|
||||||
|
// Grab focus of the left-over side
|
||||||
|
keep.grabFocus();
|
||||||
|
|
||||||
// TODO: is this correct?
|
// TODO: is this correct?
|
||||||
remove.deinit(alloc);
|
remove.deinit(alloc);
|
||||||
alloc.destroy(self);
|
alloc.destroy(self);
|
||||||
@ -149,6 +150,11 @@ pub fn replace(
|
|||||||
self.updateChildren();
|
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.
|
/// Update the paned children to represent the current state.
|
||||||
/// This should be called anytime the top/left or bottom/right
|
/// This should be called anytime the top/left or bottom/right
|
||||||
/// element is changed.
|
/// element is changed.
|
||||||
|
@ -86,11 +86,11 @@ pub const Container = union(enum) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn debugName(self: Elem) []const u8 {
|
pub fn grabFocus(self: Elem) void {
|
||||||
return switch (self) {
|
switch (self) {
|
||||||
.surface => "surface",
|
.surface => |s| s.grabFocus(),
|
||||||
.split => "split",
|
.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
|
/// from a surface to a split or a split back to a surface or
|
||||||
/// a split to a nested split and so on.
|
/// a split to a nested split and so on.
|
||||||
pub fn replace(self: Container, elem: Elem) void {
|
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
|
// Move the element into the container
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.none => {},
|
.none => {},
|
||||||
.tab_ => |t| {
|
.tab_ => |t| t.replaceElem(elem),
|
||||||
t.replaceElem(elem);
|
|
||||||
},
|
|
||||||
inline .split_tl, .split_br => |ptr| {
|
inline .split_tl, .split_br => |ptr| {
|
||||||
const s = self.split().?;
|
const s = self.split().?;
|
||||||
s.replace(ptr, elem);
|
s.replace(ptr, elem);
|
||||||
@ -154,7 +150,6 @@ pub const Container = union(enum) {
|
|||||||
/// children to effectively notify they're containing that
|
/// children to effectively notify they're containing that
|
||||||
/// all children at this level are exiting.
|
/// all children at this level are exiting.
|
||||||
pub fn remove(self: Container) void {
|
pub fn remove(self: Container) void {
|
||||||
log.warn("Container.remove", .{});
|
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.none => {},
|
.none => {},
|
||||||
.tab_ => |t| t.closeElem(),
|
.tab_ => |t| t.closeElem(),
|
||||||
@ -162,15 +157,6 @@ pub const Container = union(enum) {
|
|||||||
.split_br => self.split().?.removeBottomRight(),
|
.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
|
/// 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 {
|
pub fn newSplit(self: *Surface, direction: input.SplitDirection) !void {
|
||||||
log.debug("splitting direction={}", .{direction});
|
|
||||||
const alloc = self.app.core_app.alloc;
|
const alloc = self.app.core_app.alloc;
|
||||||
_ = try Split.create(alloc, self, direction);
|
_ = 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 {
|
pub fn newTab(self: *Surface) !void {
|
||||||
@ -1059,13 +1031,7 @@ fn gtkMouseDown(
|
|||||||
// If we don't have focus, grab it.
|
// If we don't have focus, grab it.
|
||||||
const gl_widget = @as(*c.GtkWidget, @ptrCast(self.gl_area));
|
const gl_widget = @as(*c.GtkWidget, @ptrCast(self.gl_area));
|
||||||
if (c.gtk_widget_has_focus(gl_widget) == 0) {
|
if (c.gtk_widget_has_focus(gl_widget) == 0) {
|
||||||
if (self.container.tab()) |tab| tab.focus_child = self;
|
self.grabFocus();
|
||||||
_ = 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.core_surface.mouseButtonCallback(.press, button, mods) catch |err| {
|
self.core_surface.mouseButtonCallback(.press, button, mods) catch |err| {
|
||||||
|
Reference in New Issue
Block a user