Skip to content

Commit

Permalink
Allow XIM XNArea for client preedit area in OnTheSpot mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
xorgy committed Oct 28, 2024
1 parent 452672a commit 6c4dc4c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
20 changes: 15 additions & 5 deletions src/frontend/xim/xim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,28 @@ 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_);
}
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(
Expand Down
14 changes: 10 additions & 4 deletions test/testxim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6c4dc4c

Please sign in to comment.