Skip to content

Commit 7c21217

Browse files
xorgywengxt
authored andcommitted
Allow XIM XNArea for client preedit area in OnTheSpot mode.
1 parent 564b6c9 commit 7c21217

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/frontend/xim/xim.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,28 @@ class XIMInputContext final : public InputContext {
303303

304304
void updateCursorLocation() {
305305
// kinds of like notification for position moving
306-
bool hasSpotLocation =
307-
xcb_im_input_context_get_preedit_attr_mask(xic_) &
308-
XCB_XIM_XNSpotLocation_MASK;
309-
auto p = xcb_im_input_context_get_preedit_attr(xic_)->spot_location;
306+
auto mask = xcb_im_input_context_get_preedit_attr_mask(xic_);
310307
auto w = xcb_im_input_context_get_focus_window(xic_);
311308
if (!w) {
312309
w = xcb_im_input_context_get_client_window(xic_);
313310
}
314311
if (!w) {
315312
return;
316313
}
317-
if (hasSpotLocation) {
314+
if (mask & XCB_XIM_XNArea_MASK) {
315+
auto a = xcb_im_input_context_get_preedit_attr(xic_)->area;
316+
auto trans_cookie = xcb_translate_coordinates(
317+
server_->conn(), w, server_->root(), a.x, a.y);
318+
auto reply = makeUniqueCPtr(xcb_translate_coordinates_reply(
319+
server_->conn(), trans_cookie, nullptr));
320+
if (!reply) {
321+
return;
322+
}
323+
setCursorRect(Rect()
324+
.setPosition(reply->dst_x, reply->dst_y)
325+
.setSize(a.width, a.height));
326+
} else if (mask & XCB_XIM_XNSpotLocation_MASK) {
327+
auto p = xcb_im_input_context_get_preedit_attr(xic_)->spot_location;
318328
auto trans_cookie = xcb_translate_coordinates(
319329
server_->conn(), w, server_->root(), p.x, p.y);
320330
auto reply = makeUniqueCPtr(xcb_translate_coordinates_reply(

test/testxim.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ class XIMTest {
5252
1, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen_->root_visual, 0, NULL);
5353
uint32_t input_style = XCB_IM_PreeditPosition | XCB_IM_StatusArea;
5454
xcb_point_t spot;
55-
spot.x = 0;
56-
spot.y = 0;
57-
xcb_xim_nested_list nested = xcb_xim_create_nested_list(
58-
im.get(), XCB_XIM_XNSpotLocation, &spot, NULL);
55+
spot.x = 5;
56+
spot.y = 10;
57+
xcb_rectangle_t area;
58+
area.x = 0;
59+
area.y = 0;
60+
area.width = 5;
61+
area.height = 10;
62+
xcb_xim_nested_list nested =
63+
xcb_xim_create_nested_list(im.get(), XCB_XIM_XNSpotLocation, &spot,
64+
XCB_XIM_XNArea, &area, NULL);
5965
xcb_xim_create_ic(im.get(), create_ic_callback, this,
6066
XCB_XIM_XNInputStyle, &input_style,
6167
XCB_XIM_XNClientWindow, &w_, XCB_XIM_XNFocusWindow,

0 commit comments

Comments
 (0)