git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commitc5af9fad4f7d8a6c5b54d6aec192808a41b1612a
parent2fcefde897
authorpraschke <[email protected]>
date2023-12-06 15:08
input-method: send text-input enter event after all leave events

 river/InputRelay.zig | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/river/InputRelay.zig b/river/InputRelay.zig
index 59ae8bf..4e42e18 100644
--- a/river/InputRelay.zig
+++ b/river/InputRelay.zig
@@ -185,6 +185,8 @@ pub fn sendInputMethodState(self: *Self, wlr_text_input: *wlr.TextInputV3) void
 
 /// Update the current focused surface. Surface must belong to the same seat.
 pub fn setSurfaceFocus(self: *Self, wlr_surface: ?*wlr.Surface) void {
+    var new_text_input: ?*TextInput = null;
+
     var it = self.text_inputs.first;
     while (it) |node| : (it = node.next) {
         const text_input = &node.data;
@@ -203,14 +205,19 @@ pub fn setSurfaceFocus(self: *Self, wlr_surface: ?*wlr.Surface) void {
                 continue;
             }
         }
+
         if (wlr_surface) |surface| {
             if (text_input.wlr_text_input.resource.getClient() == surface.resource.getClient()) {
-                if (self.input_method != null) {
-                    text_input.wlr_text_input.sendEnter(surface);
-                } else {
-                    text_input.setPendingFocusedSurface(surface);
-                }
+                new_text_input = text_input;
             }
         }
     }
+
+    if (new_text_input) |text_input| {
+        if (self.input_method != null) {
+            text_input.wlr_text_input.sendEnter(wlr_surface.?);
+        } else {
+            text_input.setPendingFocusedSurface(wlr_surface.?);
+        }
+    }
 }