diff --git a/river/InputMethodPopup.zig b/river/InputPopup.zig similarity index 55% rename from river/InputMethodPopup.zig rename to river/InputPopup.zig index 8719b1c..57ea2d9 100644 --- a/river/InputMethodPopup.zig +++ b/river/InputPopup.zig @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -const InputMethodPopup = @This(); +const InputPopup = @This(); const build_options = @import("build_options"); const std = @import("std"); @@ -34,8 +34,6 @@ const LayerSurface = @import("LayerSurface.zig"); const XdgToplevel = @import("XdgToplevel.zig"); const XwaylandView = @import("XwaylandView.zig"); -const log = std.log.scoped(.input_method_popup); - link: wl.list.Link, scene_tree: ?*wlr.SceneTree = null, parent_scene_tree: ?*wlr.SceneTree = null, @@ -43,80 +41,79 @@ scene_surface: ?*wlr.SceneTree = null, view: ?*View = null, input_relay: *InputRelay, -wlr_input_popup_surface: *wlr.InputPopupSurfaceV2, +wlr_popup: *wlr.InputPopupSurfaceV2, -popup_surface_commit: wl.Listener(*wlr.Surface) = - wl.Listener(*wlr.Surface).init(handlePopupSurfaceCommit), +destroy: wl.Listener(void) = + wl.Listener(void).init(handleDestroy), +map: wl.Listener(void) = + wl.Listener(void).init(handleMap), +unmap: wl.Listener(void) = + wl.Listener(void).init(handleUnmap), +commit: wl.Listener(*wlr.Surface) = + wl.Listener(*wlr.Surface).init(handleCommit), -popup_surface_map: wl.Listener(void) = - wl.Listener(void).init(handlePopupSurfaceMap), +pub fn create(wlr_popup: *wlr.InputPopupSurfaceV2, input_relay: *InputRelay) !void { + const input_popup = try util.gpa.create(InputPopup); + errdefer util.gpa.destroy(input_popup); -popup_surface_unmap: wl.Listener(void) = - wl.Listener(void).init(handlePopupSurfaceUnmap), -popup_destroy: wl.Listener(void) = - wl.Listener(void).init(handlePopupDestroy), - -pub fn create(wlr_input_popup_surface: *wlr.InputPopupSurfaceV2, input_relay: *InputRelay) !void { - const input_method_popup = try util.gpa.create(InputMethodPopup); - errdefer util.gpa.destroy(input_method_popup); - log.debug("new input_method_pupup", .{}); - input_method_popup.* = .{ + input_popup.* = .{ .link = undefined, .input_relay = input_relay, - .wlr_input_popup_surface = wlr_input_popup_surface, + .wlr_popup = wlr_popup, }; - input_method_popup.wlr_input_popup_surface.events.destroy.add(&input_method_popup.popup_destroy); - input_method_popup.wlr_input_popup_surface.surface.events.map.add(&input_method_popup.popup_surface_map); - input_method_popup.wlr_input_popup_surface.surface.events.unmap.add(&input_method_popup.popup_surface_unmap); - input_method_popup.wlr_input_popup_surface.surface.events.commit.add(&input_method_popup.popup_surface_commit); - input_relay.input_method_popups.append(input_method_popup); - input_method_popup.updatePopup(); + input_popup.wlr_popup.events.destroy.add(&input_popup.destroy); + input_popup.wlr_popup.surface.events.map.add(&input_popup.map); + input_popup.wlr_popup.surface.events.unmap.add(&input_popup.unmap); + input_popup.wlr_popup.surface.events.commit.add(&input_popup.commit); + + input_relay.input_popups.append(input_popup); + input_popup.update(); } -fn handlePopupDestroy(listener: *wl.Listener(void)) void { - log.debug("destroy ime_popup", .{}); - const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_destroy", listener); - input_method_popup.popup_surface_map.link.remove(); - input_method_popup.popup_surface_unmap.link.remove(); - input_method_popup.popup_surface_commit.link.remove(); - input_method_popup.popup_destroy.link.remove(); - input_method_popup.link.remove(); - util.gpa.destroy(input_method_popup); +fn handleDestroy(listener: *wl.Listener(void)) void { + const input_popup = @fieldParentPtr(InputPopup, "destroy", listener); + + input_popup.map.link.remove(); + input_popup.unmap.link.remove(); + input_popup.commit.link.remove(); + input_popup.destroy.link.remove(); + input_popup.link.remove(); + + util.gpa.destroy(input_popup); } -fn handlePopupSurfaceCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { - log.debug("popup surface commit", .{}); - const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_commit", listener); - input_method_popup.updatePopup(); +fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { + const input_popup = @fieldParentPtr(InputPopup, "commit", listener); + + input_popup.update(); } -fn handlePopupSurfaceMap(listener: *wl.Listener(void)) void { - log.debug("popup surface map", .{}); - const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_map", listener); - input_method_popup.updatePopup(); +fn handleMap(listener: *wl.Listener(void)) void { + const input_popup = @fieldParentPtr(InputPopup, "map", listener); + + input_popup.update(); } -fn handlePopupSurfaceUnmap(listener: *wl.Listener(void)) void { - log.debug("popup surface unmap", .{}); - const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_unmap", listener); - input_method_popup.scene_tree.?.node.destroy(); - input_method_popup.scene_tree = null; +fn handleUnmap(listener: *wl.Listener(void)) void { + const input_popup = @fieldParentPtr(InputPopup, "unmap", listener); + + input_popup.scene_tree.?.node.destroy(); + input_popup.scene_tree = null; } -pub fn updatePopup(input_method_popup: *InputMethodPopup) void { - log.debug("update ime_popup", .{}); - var text_input = input_method_popup.getTextInputFocused() orelse return; +pub fn update(input_popup: *InputPopup) void { + var text_input = input_popup.getTextInputFocused() orelse return; const focused_surface = text_input.wlr_text_input.focused_surface orelse return; - if (!input_method_popup.wlr_input_popup_surface.surface.mapped) { + if (!input_popup.wlr_popup.surface.mapped) { return; } var output_box: wlr.Box = undefined; var parent: wlr.Box = undefined; - input_method_popup.getParentAndOutputBox(focused_surface, &parent, &output_box); + input_popup.getParentAndOutputBox(focused_surface, &parent, &output_box); var cursor_rect = if (text_input.wlr_text_input.current.features.cursor_rectangle) text_input.wlr_text_input.current.cursor_rectangle @@ -128,8 +125,8 @@ pub fn updatePopup(input_method_popup: *InputMethodPopup) void { .height = parent.height, }; - const popup_width = input_method_popup.wlr_input_popup_surface.surface.current.width; - const popup_height = input_method_popup.wlr_input_popup_surface.surface.current.height; + const popup_width = input_popup.wlr_popup.surface.current.width; + const popup_height = input_popup.wlr_popup.surface.current.height; const cursor_rect_left = parent.x + cursor_rect.x; const popup_anchor_left = blk: { @@ -162,29 +159,29 @@ pub fn updatePopup(input_method_popup: *InputMethodPopup) void { .width = cursor_rect.width, .height = cursor_rect.height, }; - input_method_popup.wlr_input_popup_surface.sendTextInputRectangle(&box); + input_popup.wlr_popup.sendTextInputRectangle(&box); } - if (input_method_popup.scene_tree == null) { - input_method_popup.scene_tree = input_method_popup.parent_scene_tree.?.createSceneTree() catch { - log.err("out of memory", .{}); + if (input_popup.scene_tree == null) { + input_popup.scene_tree = input_popup.parent_scene_tree.?.createSceneTree() catch { + std.log.err("out of memory", .{}); return; }; - input_method_popup.scene_surface = input_method_popup.scene_tree.? + input_popup.scene_surface = input_popup.scene_tree.? .createSceneSubsurfaceTree( - input_method_popup.wlr_input_popup_surface.surface, + input_popup.wlr_popup.surface, ) catch { - log.err("failed to create subsurface tree", .{}); - input_method_popup.wlr_input_popup_surface.surface.resource.getClient().postNoMemory(); + std.log.err("out of memory", .{}); + input_popup.wlr_popup.surface.resource.getClient().postNoMemory(); return; }; } - input_method_popup.scene_tree.?.node.setPosition(popup_anchor_left - parent.x, popup_anchor_up - parent.y); + input_popup.scene_tree.?.node.setPosition(popup_anchor_left - parent.x, popup_anchor_up - parent.y); } -pub fn getTextInputFocused(input_method_popup: *InputMethodPopup) ?*TextInput { - var it = input_method_popup.input_relay.text_inputs.iterator(.forward); +pub fn getTextInputFocused(input_popup: *InputPopup) ?*TextInput { + var it = input_popup.input_relay.text_inputs.iterator(.forward); while (it.next()) |text_input| { if (text_input.wlr_text_input.focused_surface != null) return text_input; } @@ -192,20 +189,20 @@ pub fn getTextInputFocused(input_method_popup: *InputMethodPopup) ?*TextInput { } pub fn getParentAndOutputBox( - input_method_popup: *InputMethodPopup, + input_popup: *InputPopup, focused_surface: *wlr.Surface, parent: *wlr.Box, output_box: *wlr.Box, ) void { if (wlr.LayerSurfaceV1.tryFromWlrSurface(focused_surface)) |wlr_layer_surface| { const layer_surface: *LayerSurface = @ptrFromInt(wlr_layer_surface.data); - input_method_popup.parent_scene_tree = layer_surface.popup_tree; + input_popup.parent_scene_tree = layer_surface.popup_tree; const output = layer_surface.output.wlr_output; server.root.output_layout.getBox(output, output_box); _ = layer_surface.popup_tree.node.coords(&parent.x, &parent.y); } else { const view = getViewFromWlrSurface(focused_surface) orelse return; - input_method_popup.parent_scene_tree = view.tree; + input_popup.parent_scene_tree = view.tree; _ = view.tree.node.coords(&parent.x, &parent.y); const output = view.current.output orelse return; server.root.output_layout.getBox(output.wlr_output, output_box); diff --git a/river/InputRelay.zig b/river/InputRelay.zig index 6bfcf27..ae84582 100644 --- a/river/InputRelay.zig +++ b/river/InputRelay.zig @@ -26,7 +26,7 @@ const wl = @import("wayland").server.wl; const util = @import("util.zig"); const TextInput = @import("TextInput.zig"); -const InputMethodPopup = @import("InputMethodPopup.zig"); +const InputPopup = @import("InputPopup.zig"); const Seat = @import("Seat.zig"); const log = std.log.scoped(.input_relay); @@ -41,7 +41,7 @@ text_inputs: wl.list.Head(TextInput, .link), /// already in use new input methods are ignored. /// If this is null, no text input enter events will be sent. input_method: ?*wlr.InputMethodV2 = null, -input_method_popups: wl.list.Head(InputMethodPopup, .link), +input_popups: wl.list.Head(InputPopup, .link), /// The currently enabled text input for the currently focused surface. /// Always null if there is no input method. text_input: ?*TextInput = null, @@ -59,10 +59,10 @@ grab_keyboard_destroy: wl.Listener(*wlr.InputMethodV2.KeyboardGrab) = wl.Listener(*wlr.InputMethodV2.KeyboardGrab).init(handleInputMethodGrabKeyboardDestroy), pub fn init(relay: *InputRelay) void { - relay.* = .{ .text_inputs = undefined, .input_method_popups = undefined }; + relay.* = .{ .text_inputs = undefined, .input_popups = undefined }; relay.text_inputs.init(); - relay.input_method_popups.init(); + relay.input_popups.init(); } pub fn newInputMethod(relay: *InputRelay, input_method: *wlr.InputMethodV2) void { @@ -160,7 +160,7 @@ fn handleInputMethodNewPopupSurface( ) void { log.debug("new input_method_popup_surface", .{}); const relay = @fieldParentPtr(InputRelay, "input_method_new_popup_surface", listener); - InputMethodPopup.create(input_method_new_popup_surface, relay) catch { + InputPopup.create(input_method_new_popup_surface, relay) catch { log.err("out of memory", .{}); return; }; @@ -216,9 +216,9 @@ pub fn sendInputMethodState(relay: *InputRelay) void { } // Update input popups - var it = relay.input_method_popups.iterator(.forward); + var it = relay.input_popups.iterator(.forward); while (it.next()) |popup| { - popup.updatePopup(); + popup.update(); } input_method.sendDone(); }