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 ea17374
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 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
10 changes: 8 additions & 2 deletions test/testxim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ class XIMTest {
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);
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 ea17374

Please sign in to comment.