From 792bb59788db9b4636e549436c6588020e0025c0 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Tue, 1 Oct 2024 23:49:47 +0800 Subject: [PATCH] input method: try to update popup position on text input commit --- plugins/protocols/input-method-v1.cpp | 4 ++++ src/api/wayfire/plugin.hpp | 2 +- src/api/wayfire/signal-definitions.hpp | 9 +++++++++ .../unstable/wlr-text-input-v3-popup.hpp | 9 ++++++++- src/core/seat/input-method-popup.cpp | 17 +++++++++++++++++ src/core/seat/input-method-relay.cpp | 4 ++++ 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/plugins/protocols/input-method-v1.cpp b/plugins/protocols/input-method-v1.cpp index d5140f992..128825863 100644 --- a/plugins/protocols/input-method-v1.cpp +++ b/plugins/protocols/input-method-v1.cpp @@ -773,6 +773,10 @@ class wayfire_input_method_v1 : public wf::plugin_interface_t, public wf::text_i if (current_im_context && (current_im_context->text_input == im_text_inputs_v3[input].get())) { current_im_context->handle_text_input_v3_commit(); + + wf::text_input_commit_signal data; + data.cursor_rect = input->current.cursor_rectangle; + emit(&data); } } diff --git a/src/api/wayfire/plugin.hpp b/src/api/wayfire/plugin.hpp index d9c2aabb7..3d4779ac2 100644 --- a/src/api/wayfire/plugin.hpp +++ b/src/api/wayfire/plugin.hpp @@ -105,7 +105,7 @@ class plugin_interface_t using wayfire_plugin_load_func = wf::plugin_interface_t * (*)(); /** The version of Wayfire's API/ABI */ -constexpr uint32_t WAYFIRE_API_ABI_VERSION = 2024'08'26; +constexpr uint32_t WAYFIRE_API_ABI_VERSION = 2024'10'01; /** * Each plugin must also provide a function which returns the Wayfire API/ABI diff --git a/src/api/wayfire/signal-definitions.hpp b/src/api/wayfire/signal-definitions.hpp index 46070397c..d744f5d83 100644 --- a/src/api/wayfire/signal-definitions.hpp +++ b/src/api/wayfire/signal-definitions.hpp @@ -810,6 +810,15 @@ struct view_system_bell_signal { wayfire_view view; }; + +/** + * on: input method relay + * when: A text input commits + */ +struct text_input_commit_signal +{ + wlr_box cursor_rect; +}; } #endif diff --git a/src/api/wayfire/unstable/wlr-text-input-v3-popup.hpp b/src/api/wayfire/unstable/wlr-text-input-v3-popup.hpp index 869767642..094608144 100644 --- a/src/api/wayfire/unstable/wlr-text-input-v3-popup.hpp +++ b/src/api/wayfire/unstable/wlr-text-input-v3-popup.hpp @@ -7,7 +7,7 @@ namespace wf { -class text_input_v3_im_relay_interface_t +class text_input_v3_im_relay_interface_t : public wf::signal::provider_t { public: virtual wlr_text_input_v3 *find_focused_text_input_v3() = 0; @@ -33,10 +33,12 @@ class text_input_v3_popup : public wf::view_interface_t void map(); void unmap(); void update_geometry(); + void update_cursor_rect(wlr_box*); ~text_input_v3_popup(); private: wf::geometry_t geometry{0, 0, 0, 0}; + wlr_box old_cursor_rect{0, 0, 0, 0}; std::shared_ptr main_surface; std::shared_ptr surface_root_node; @@ -45,6 +47,11 @@ class text_input_v3_popup : public wf::view_interface_t return nullptr; } + wf::signal::connection_t on_text_input_commit = [=] (auto s) + { + update_cursor_rect(&s->cursor_rect); + }; + wf::wl_listener_wrapper on_map; wf::wl_listener_wrapper on_unmap; wf::wl_listener_wrapper on_commit; diff --git a/src/core/seat/input-method-popup.cpp b/src/core/seat/input-method-popup.cpp index f523ca555..4eb83cdfa 100644 --- a/src/core/seat/input-method-popup.cpp +++ b/src/core/seat/input-method-popup.cpp @@ -65,6 +65,7 @@ void wf::text_input_v3_popup::map() damage(); emit_view_map(); + relay->connect(&on_text_input_commit); } void wf::text_input_v3_popup::unmap() @@ -82,6 +83,7 @@ void wf::text_input_v3_popup::unmap() priv->set_mapped(nullptr); priv->set_enabled(false); on_commit.disconnect(); + relay->disconnect(&on_text_input_commit); } std::string wf::text_input_v3_popup::get_app_id() @@ -94,6 +96,21 @@ std::string wf::text_input_v3_popup::get_title() return "input-method-popup"; } +void wf::text_input_v3_popup::update_cursor_rect(wlr_box *cursor_rect) +{ + if (old_cursor_rect == *cursor_rect) + { + return; + } + + if (is_mapped()) + { + update_geometry(); + } + + old_cursor_rect = *cursor_rect; +} + void wf::text_input_v3_popup::update_geometry() { auto text_input = this->relay->find_focused_text_input_v3(); diff --git a/src/core/seat/input-method-relay.cpp b/src/core/seat/input-method-relay.cpp index 026fab7d3..b523c1e8d 100644 --- a/src/core/seat/input-method-relay.cpp +++ b/src/core/seat/input-method-relay.cpp @@ -412,6 +412,10 @@ wf::text_input::text_input(wf::input_method_relay *rel, wlr_text_input_v3 *in) : } relay->send_im_state(input); + + wf::text_input_commit_signal sigdata; + sigdata.cursor_rect = input->current.cursor_rectangle; + relay->emit(&sigdata); }); on_text_input_disable.set_callback([&] (void *data)