gtk: add unfocused_widget when split created from menu

When a split is created from a menu action, the focus is lost before the
split is made which prevents the surface from having the
unfocused_widget. Move the logic to add the unfocused_widget to the
overlay to an exported function which is called when the split is
created.
This commit is contained in:
Tim Culverhouse
2024-07-11 10:29:40 -05:00
parent fc3d885022
commit 76df732169
2 changed files with 12 additions and 7 deletions

View File

@ -77,6 +77,7 @@ pub fn init(
.parent = &sibling.core_surface,
});
errdefer surface.destroy(alloc);
sibling.dimSurface();
// Create the actual GTKPaned, attach the proper children.
const orientation: c_uint = switch (direction) {

View File

@ -1836,16 +1836,11 @@ fn gtkFocusLeave(_: *c.GtkEventControllerFocus, ud: ?*anyopaque) callconv(.C) vo
// Notify our IM context
c.gtk_im_context_focus_out(self.im_context);
// We only add the unfocused-split widget if we are actually a split
// We only dim the surface if we are a split
switch (self.container) {
.split_br,
.split_tl,
=> blk: {
if (self.unfocused_widget != null) break :blk;
self.unfocused_widget = c.gtk_drawing_area_new();
c.gtk_widget_add_css_class(self.unfocused_widget.?, "unfocused-split");
c.gtk_overlay_add_overlay(self.overlay, self.unfocused_widget.?);
},
=> self.dimSurface(),
else => {},
}
@ -1855,6 +1850,15 @@ fn gtkFocusLeave(_: *c.GtkEventControllerFocus, ud: ?*anyopaque) callconv(.C) vo
};
}
/// Adds the unfocused_widget to the overlay. If the unfocused_widget has already been added, this
/// is a no-op
pub fn dimSurface(self: *Surface) void {
if (self.unfocused_widget != null) return;
self.unfocused_widget = c.gtk_drawing_area_new();
c.gtk_widget_add_css_class(self.unfocused_widget.?, "unfocused-split");
c.gtk_overlay_add_overlay(self.overlay, self.unfocused_widget.?);
}
fn gtkCloseConfirmation(
alert: *c.GtkMessageDialog,
response: c.gint,