From 6c4dc4c1fdad9293456bcd64473db830b5ade519 Mon Sep 17 00:00:00 2001 From: Aaron Muir Hamilton Date: Mon, 28 Oct 2024 18:25:42 -0400 Subject: [PATCH] Allow XIM XNArea for client preedit area in OnTheSpot mode. --- src/frontend/xim/xim.cpp | 20 +++++++++++++++----- test/testxim.cpp | 14 ++++++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/frontend/xim/xim.cpp b/src/frontend/xim/xim.cpp index c9b81a0b..2dc60dc9 100644 --- a/src/frontend/xim/xim.cpp +++ b/src/frontend/xim/xim.cpp @@ -303,10 +303,7 @@ class XIMInputContext final : public InputContext { void updateCursorLocation() { // kinds of like notification for position moving - bool hasSpotLocation = - xcb_im_input_context_get_preedit_attr_mask(xic_) & - XCB_XIM_XNSpotLocation_MASK; - auto p = xcb_im_input_context_get_preedit_attr(xic_)->spot_location; + auto mask = xcb_im_input_context_get_preedit_attr_mask(xic_); auto w = xcb_im_input_context_get_focus_window(xic_); if (!w) { w = xcb_im_input_context_get_client_window(xic_); @@ -314,7 +311,20 @@ class XIMInputContext final : public InputContext { if (!w) { return; } - if (hasSpotLocation) { + if (mask & XCB_XIM_XNArea_MASK) { + auto a = xcb_im_input_context_get_preedit_attr(xic_)->area; + auto trans_cookie = xcb_translate_coordinates( + server_->conn(), w, server_->root(), a.x, a.y); + auto reply = makeUniqueCPtr(xcb_translate_coordinates_reply( + server_->conn(), trans_cookie, nullptr)); + if (!reply) { + return; + } + setCursorRect(Rect() + .setPosition(reply->dst_x, reply->dst_y) + .setSize(a.width, a.height)); + } else if (mask & XCB_XIM_XNSpotLocation_MASK) { + auto p = xcb_im_input_context_get_preedit_attr(xic_)->spot_location; auto trans_cookie = xcb_translate_coordinates( server_->conn(), w, server_->root(), p.x, p.y); auto reply = makeUniqueCPtr(xcb_translate_coordinates_reply( diff --git a/test/testxim.cpp b/test/testxim.cpp index 64e0210b..39ac32bc 100644 --- a/test/testxim.cpp +++ b/test/testxim.cpp @@ -52,10 +52,16 @@ class XIMTest { 1, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen_->root_visual, 0, NULL); uint32_t input_style = XCB_IM_PreeditPosition | XCB_IM_StatusArea; xcb_point_t spot; - spot.x = 0; - spot.y = 0; - xcb_xim_nested_list nested = xcb_xim_create_nested_list( - im.get(), XCB_XIM_XNSpotLocation, &spot, NULL); + spot.x = 5; + spot.y = 10; + xcb_rectangle_t area; + area.x = 0; + area.y = 0; + area.width = 5; + area.height = 10; + xcb_xim_nested_list nested = + xcb_xim_create_nested_list(im.get(), XCB_XIM_XNSpotLocation, &spot, + XCB_XIM_XNArea, &area, NULL); xcb_xim_create_ic(im.get(), create_ic_callback, this, XCB_XIM_XNInputStyle, &input_style, XCB_XIM_XNClientWindow, &w_, XCB_XIM_XNFocusWindow,