From 76df7321690920ff7ee48d6721def6100e2b2042 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Thu, 11 Jul 2024 10:29:40 -0500 Subject: [PATCH] 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. --- src/apprt/gtk/Split.zig | 1 + src/apprt/gtk/Surface.zig | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/apprt/gtk/Split.zig b/src/apprt/gtk/Split.zig index 148651d4b..622db61fe 100644 --- a/src/apprt/gtk/Split.zig +++ b/src/apprt/gtk/Split.zig @@ -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) { diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index f370a05a8..05fce6905 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -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,