InputPopup: fix naming

This commit is contained in:
Isaac Freund 2024-05-15 11:50:58 +02:00
parent 74baf7225a
commit ba6023e38a
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
2 changed files with 72 additions and 75 deletions

View File

@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
const InputMethodPopup = @This(); const InputPopup = @This();
const build_options = @import("build_options"); const build_options = @import("build_options");
const std = @import("std"); const std = @import("std");
@ -34,8 +34,6 @@ const LayerSurface = @import("LayerSurface.zig");
const XdgToplevel = @import("XdgToplevel.zig"); const XdgToplevel = @import("XdgToplevel.zig");
const XwaylandView = @import("XwaylandView.zig"); const XwaylandView = @import("XwaylandView.zig");
const log = std.log.scoped(.input_method_popup);
link: wl.list.Link, link: wl.list.Link,
scene_tree: ?*wlr.SceneTree = null, scene_tree: ?*wlr.SceneTree = null,
parent_scene_tree: ?*wlr.SceneTree = null, parent_scene_tree: ?*wlr.SceneTree = null,
@ -43,80 +41,79 @@ scene_surface: ?*wlr.SceneTree = null,
view: ?*View = null, view: ?*View = null,
input_relay: *InputRelay, input_relay: *InputRelay,
wlr_input_popup_surface: *wlr.InputPopupSurfaceV2, wlr_popup: *wlr.InputPopupSurfaceV2,
popup_surface_commit: wl.Listener(*wlr.Surface) = destroy: wl.Listener(void) =
wl.Listener(*wlr.Surface).init(handlePopupSurfaceCommit), 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) = pub fn create(wlr_popup: *wlr.InputPopupSurfaceV2, input_relay: *InputRelay) !void {
wl.Listener(void).init(handlePopupSurfaceMap), const input_popup = try util.gpa.create(InputPopup);
errdefer util.gpa.destroy(input_popup);
popup_surface_unmap: wl.Listener(void) = input_popup.* = .{
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.* = .{
.link = undefined, .link = undefined,
.input_relay = input_relay, .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_popup.wlr_popup.events.destroy.add(&input_popup.destroy);
input_method_popup.wlr_input_popup_surface.surface.events.map.add(&input_method_popup.popup_surface_map); input_popup.wlr_popup.surface.events.map.add(&input_popup.map);
input_method_popup.wlr_input_popup_surface.surface.events.unmap.add(&input_method_popup.popup_surface_unmap); input_popup.wlr_popup.surface.events.unmap.add(&input_popup.unmap);
input_method_popup.wlr_input_popup_surface.surface.events.commit.add(&input_method_popup.popup_surface_commit); input_popup.wlr_popup.surface.events.commit.add(&input_popup.commit);
input_relay.input_method_popups.append(input_method_popup);
input_method_popup.updatePopup(); input_relay.input_popups.append(input_popup);
input_popup.update();
} }
fn handlePopupDestroy(listener: *wl.Listener(void)) void { fn handleDestroy(listener: *wl.Listener(void)) void {
log.debug("destroy ime_popup", .{}); const input_popup = @fieldParentPtr(InputPopup, "destroy", listener);
const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_destroy", listener);
input_method_popup.popup_surface_map.link.remove(); input_popup.map.link.remove();
input_method_popup.popup_surface_unmap.link.remove(); input_popup.unmap.link.remove();
input_method_popup.popup_surface_commit.link.remove(); input_popup.commit.link.remove();
input_method_popup.popup_destroy.link.remove(); input_popup.destroy.link.remove();
input_method_popup.link.remove(); input_popup.link.remove();
util.gpa.destroy(input_method_popup);
util.gpa.destroy(input_popup);
} }
fn handlePopupSurfaceCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void { fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
log.debug("popup surface commit", .{}); const input_popup = @fieldParentPtr(InputPopup, "commit", listener);
const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_commit", listener);
input_method_popup.updatePopup(); input_popup.update();
} }
fn handlePopupSurfaceMap(listener: *wl.Listener(void)) void { fn handleMap(listener: *wl.Listener(void)) void {
log.debug("popup surface map", .{}); const input_popup = @fieldParentPtr(InputPopup, "map", listener);
const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_map", listener);
input_method_popup.updatePopup(); input_popup.update();
} }
fn handlePopupSurfaceUnmap(listener: *wl.Listener(void)) void { fn handleUnmap(listener: *wl.Listener(void)) void {
log.debug("popup surface unmap", .{}); const input_popup = @fieldParentPtr(InputPopup, "unmap", listener);
const input_method_popup = @fieldParentPtr(InputMethodPopup, "popup_surface_unmap", listener);
input_method_popup.scene_tree.?.node.destroy(); input_popup.scene_tree.?.node.destroy();
input_method_popup.scene_tree = null; input_popup.scene_tree = null;
} }
pub fn updatePopup(input_method_popup: *InputMethodPopup) void { pub fn update(input_popup: *InputPopup) void {
log.debug("update ime_popup", .{}); var text_input = input_popup.getTextInputFocused() orelse return;
var text_input = input_method_popup.getTextInputFocused() orelse return;
const focused_surface = text_input.wlr_text_input.focused_surface 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; return;
} }
var output_box: wlr.Box = undefined; var output_box: wlr.Box = undefined;
var parent: 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) var cursor_rect = if (text_input.wlr_text_input.current.features.cursor_rectangle)
text_input.wlr_text_input.current.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, .height = parent.height,
}; };
const popup_width = input_method_popup.wlr_input_popup_surface.surface.current.width; const popup_width = input_popup.wlr_popup.surface.current.width;
const popup_height = input_method_popup.wlr_input_popup_surface.surface.current.height; const popup_height = input_popup.wlr_popup.surface.current.height;
const cursor_rect_left = parent.x + cursor_rect.x; const cursor_rect_left = parent.x + cursor_rect.x;
const popup_anchor_left = blk: { const popup_anchor_left = blk: {
@ -162,29 +159,29 @@ pub fn updatePopup(input_method_popup: *InputMethodPopup) void {
.width = cursor_rect.width, .width = cursor_rect.width,
.height = cursor_rect.height, .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) { if (input_popup.scene_tree == null) {
input_method_popup.scene_tree = input_method_popup.parent_scene_tree.?.createSceneTree() catch { input_popup.scene_tree = input_popup.parent_scene_tree.?.createSceneTree() catch {
log.err("out of memory", .{}); std.log.err("out of memory", .{});
return; return;
}; };
input_method_popup.scene_surface = input_method_popup.scene_tree.? input_popup.scene_surface = input_popup.scene_tree.?
.createSceneSubsurfaceTree( .createSceneSubsurfaceTree(
input_method_popup.wlr_input_popup_surface.surface, input_popup.wlr_popup.surface,
) catch { ) catch {
log.err("failed to create subsurface tree", .{}); std.log.err("out of memory", .{});
input_method_popup.wlr_input_popup_surface.surface.resource.getClient().postNoMemory(); input_popup.wlr_popup.surface.resource.getClient().postNoMemory();
return; 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 { pub fn getTextInputFocused(input_popup: *InputPopup) ?*TextInput {
var it = input_method_popup.input_relay.text_inputs.iterator(.forward); var it = input_popup.input_relay.text_inputs.iterator(.forward);
while (it.next()) |text_input| { while (it.next()) |text_input| {
if (text_input.wlr_text_input.focused_surface != null) return 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( pub fn getParentAndOutputBox(
input_method_popup: *InputMethodPopup, input_popup: *InputPopup,
focused_surface: *wlr.Surface, focused_surface: *wlr.Surface,
parent: *wlr.Box, parent: *wlr.Box,
output_box: *wlr.Box, output_box: *wlr.Box,
) void { ) void {
if (wlr.LayerSurfaceV1.tryFromWlrSurface(focused_surface)) |wlr_layer_surface| { if (wlr.LayerSurfaceV1.tryFromWlrSurface(focused_surface)) |wlr_layer_surface| {
const layer_surface: *LayerSurface = @ptrFromInt(wlr_layer_surface.data); 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; const output = layer_surface.output.wlr_output;
server.root.output_layout.getBox(output, output_box); server.root.output_layout.getBox(output, output_box);
_ = layer_surface.popup_tree.node.coords(&parent.x, &parent.y); _ = layer_surface.popup_tree.node.coords(&parent.x, &parent.y);
} else { } else {
const view = getViewFromWlrSurface(focused_surface) orelse return; 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); _ = view.tree.node.coords(&parent.x, &parent.y);
const output = view.current.output orelse return; const output = view.current.output orelse return;
server.root.output_layout.getBox(output.wlr_output, output_box); server.root.output_layout.getBox(output.wlr_output, output_box);

View File

@ -26,7 +26,7 @@ const wl = @import("wayland").server.wl;
const util = @import("util.zig"); const util = @import("util.zig");
const TextInput = @import("TextInput.zig"); const TextInput = @import("TextInput.zig");
const InputMethodPopup = @import("InputMethodPopup.zig"); const InputPopup = @import("InputPopup.zig");
const Seat = @import("Seat.zig"); const Seat = @import("Seat.zig");
const log = std.log.scoped(.input_relay); 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. /// already in use new input methods are ignored.
/// If this is null, no text input enter events will be sent. /// If this is null, no text input enter events will be sent.
input_method: ?*wlr.InputMethodV2 = null, 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. /// The currently enabled text input for the currently focused surface.
/// Always null if there is no input method. /// Always null if there is no input method.
text_input: ?*TextInput = null, text_input: ?*TextInput = null,
@ -59,10 +59,10 @@ grab_keyboard_destroy: wl.Listener(*wlr.InputMethodV2.KeyboardGrab) =
wl.Listener(*wlr.InputMethodV2.KeyboardGrab).init(handleInputMethodGrabKeyboardDestroy), wl.Listener(*wlr.InputMethodV2.KeyboardGrab).init(handleInputMethodGrabKeyboardDestroy),
pub fn init(relay: *InputRelay) void { 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.text_inputs.init();
relay.input_method_popups.init(); relay.input_popups.init();
} }
pub fn newInputMethod(relay: *InputRelay, input_method: *wlr.InputMethodV2) void { pub fn newInputMethod(relay: *InputRelay, input_method: *wlr.InputMethodV2) void {
@ -160,7 +160,7 @@ fn handleInputMethodNewPopupSurface(
) void { ) void {
log.debug("new input_method_popup_surface", .{}); log.debug("new input_method_popup_surface", .{});
const relay = @fieldParentPtr(InputRelay, "input_method_new_popup_surface", listener); 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", .{}); log.err("out of memory", .{});
return; return;
}; };
@ -216,9 +216,9 @@ pub fn sendInputMethodState(relay: *InputRelay) void {
} }
// Update input popups // Update input popups
var it = relay.input_method_popups.iterator(.forward); var it = relay.input_popups.iterator(.forward);
while (it.next()) |popup| { while (it.next()) |popup| {
popup.updatePopup(); popup.update();
} }
input_method.sendDone(); input_method.sendDone();
} }