Skip to content

Commit

Permalink
Do not set style to something that we don't declare.
Browse files Browse the repository at this point in the history
winit doesn't negotiate the style, so it might always over on the spot.

Fix #590
  • Loading branch information
wengxt committed Aug 30, 2022
1 parent affc1ac commit 1d69497
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/frontend/xim/xim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@ class XIMServer {
conn, XCB_COPY_FROM_PARENT, serverWindow_, screen->root, 0, 0, 1, 1,
1, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, 0, nullptr);

auto inputStyles =
(*parent_->config().useOnTheSpot ? &onthespot_styles : &styles);
for (uint32_t i = 0; i < inputStyles->nStyles; i++) {
supportedStyles_.insert(inputStyles->styles[i]);
}
im_.reset(xcb_im_create(
conn, defaultScreen, serverWindow_, guess_server_name().c_str(),
XCB_IM_ALL_LOCALES,
(*parent_->config().useOnTheSpot ? &onthespot_styles : &styles),
nullptr, nullptr, &encodings,
XCB_IM_ALL_LOCALES, inputStyles, nullptr, nullptr, &encodings,
XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE,
&XIMServer::callback, this));

Expand Down Expand Up @@ -139,6 +142,7 @@ class XIMServer {
}

Instance *instance() { return parent_->instance(); }
const auto &supportedStyles() { return supportedStyles_; }

~XIMServer() {
if (im_) {
Expand Down Expand Up @@ -178,6 +182,7 @@ class XIMServer {
std::unique_ptr<HandlerTableEntry<XCBEventFilter>> filter_;
// bool value: isUtf8
std::unordered_map<xcb_im_client_t *, bool> clientEncodingMapping_;
std::unordered_set<uint32_t> supportedStyles_;
};

pid_t getWindowPid(xcb_ewmh_connection_t *ewmh, xcb_window_t w) {
Expand Down Expand Up @@ -224,10 +229,10 @@ class XIMInputContext final : public InputContext {
server_(server), xic_(ic), useUtf8_(useUtf8) {
setFocusGroup(server->focusGroup());
xcb_im_input_context_set_data(xic_, this, nullptr);
auto style = xcb_im_input_context_get_input_style(ic);

created();
CapabilityFlags flags = CapabilityFlag::ReportKeyRepeat;
if (style & XCB_IM_PreeditCallbacks) {
if (validatedInputStyle() & XCB_IM_PreeditCallbacks) {
flags = flags | CapabilityFlag::Preedit;
flags = flags | CapabilityFlag::FormattedPreedit;
}
Expand All @@ -238,11 +243,28 @@ class XIMInputContext final : public InputContext {
destroy();
}

uint32_t validatedInputStyle() {
auto style = xcb_im_input_context_get_input_style(xic_);
if (server_->supportedStyles().count(style)) {
return style;
}
auto preeditStyle = (style & 0xff) | XCB_IM_StatusNothing;
if (server_->supportedStyles().count(preeditStyle)) {
return preeditStyle;
}
auto statusStyle = (style & 0xff00) | XCB_IM_PreeditNothing;
if (server_->supportedStyles().count(statusStyle)) {
return statusStyle;
}

return XCB_IM_StatusNothing | XCB_IM_PreeditNothing;
}

const char *frontend() const override { return "xim"; }

void maybeUpdateCursorLocationForRootStyle() {
auto style = xcb_im_input_context_get_input_style(xic_);
if ((style & XCB_IM_PreeditPosition) == XCB_IM_PreeditPosition) {
if ((validatedInputStyle() & XCB_IM_PreeditPosition) ==
XCB_IM_PreeditPosition) {
return;
}
updateCursorLocation();
Expand Down

0 comments on commit 1d69497

Please sign in to comment.