aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-09-30 00:16:13 +0800
committerYuqian Yang <crupest@crupest.life>2025-10-03 00:13:54 +0800
commit047e0eba34c669ff71535602c09edec587912059 (patch)
treeed1b98bf2c1451f9cc02b96cd45f4eae00163b6d
parente903083732b0d4638ac066fc85b030b121d8e7e6 (diff)
downloadcru-047e0eba34c669ff71535602c09edec587912059.tar.gz
cru-047e0eba34c669ff71535602c09edec587912059.tar.bz2
cru-047e0eba34c669ff71535602c09edec587912059.zip
Impl input method for xim 3.
-rw-r--r--.github/workflows/ci.yml3
-rw-r--r--include/cru/platform/gui/xcb/Keyboard.h2
-rw-r--r--src/platform/gui/xcb/CMakeLists.txt4
-rw-r--r--src/platform/gui/xcb/InputMethod.cpp19
-rw-r--r--src/platform/gui/xcb/Keyboard.cpp6
5 files changed, 10 insertions, 24 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6552f2dc..62eb32c4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -88,7 +88,8 @@ jobs:
- name: Install Libraries
run: |
sudo apt update
- sudo apt install -y libpng-dev libcairo2-dev libpango1.0-dev libxcb1-dev libxcb-cursor-dev libxcb-imdkit-dev
+ sudo apt install -y libpng-dev libcairo2-dev libpango1.0-dev libxcb1-dev libxcb-cursor-dev \
+ libxkbcommon-dev libxcb-imdkit-dev libxkbcommon-x11-dev
- name: Build
run: |
diff --git a/include/cru/platform/gui/xcb/Keyboard.h b/include/cru/platform/gui/xcb/Keyboard.h
index f3650900..a3e66e2b 100644
--- a/include/cru/platform/gui/xcb/Keyboard.h
+++ b/include/cru/platform/gui/xcb/Keyboard.h
@@ -11,7 +11,7 @@ struct XcbUiApplication;
KeyCode XorgKeysymToKeyCode(xcb_keysym_t keysym);
std::vector<xcb_keysym_t> XorgKeycodeToKeysyms(XcbUiApplication* application, xcb_keycode_t keycode);
KeyCode XorgKeycodeToCruKeyCode(XcbUiApplication* application, xcb_keycode_t keycode);
-std::string XorgKeysymToUtf8(xcb_keysym_t keysym);
+std::string XorgKeysymToUtf8(xcb_keysym_t keysym, bool upper = false);
std::unordered_map<KeyCode, bool> GetKeyboardState(XcbUiApplication* application);
KeyModifier GetCurrentKeyModifiers(XcbUiApplication* application);
} // namespace cru::platform::gui::xcb
diff --git a/src/platform/gui/xcb/CMakeLists.txt b/src/platform/gui/xcb/CMakeLists.txt
index 35feb8bc..5adeb923 100644
--- a/src/platform/gui/xcb/CMakeLists.txt
+++ b/src/platform/gui/xcb/CMakeLists.txt
@@ -1,7 +1,7 @@
-find_library(LIBRARY_CAIRO cairo REQUIRED)
find_library(LIBRARY_XCB xcb REQUIRED)
find_library(LIBRARY_XCB_CURSOR xcb-cursor REQUIRED)
find_library(LIBRARY_XCB_IMDKIT xcb-imdkit REQUIRED)
+find_library(LIBRARY_XKBCOMMON xkbcommon REQUIRED)
add_library(CruPlatformGuiXcb
Cursor.cpp
InputMethod.cpp
@@ -11,5 +11,5 @@ add_library(CruPlatformGuiXcb
)
target_link_libraries(CruPlatformGuiXcb PUBLIC
CruPlatformGui CruPlatformGraphicsCairo
- ${LIBRARY_XCB} ${LIBRARY_XCB_CURSOR} ${LIBRARY_XCB_IMDKIT} ${LIBRARY_CAIRO}
+ ${LIBRARY_XCB} ${LIBRARY_XCB_CURSOR} ${LIBRARY_XCB_IMDKIT} ${LIBRARY_XCB_XKBCOMMON}
)
diff --git a/src/platform/gui/xcb/InputMethod.cpp b/src/platform/gui/xcb/InputMethod.cpp
index 49dadbf1..61753bf3 100644
--- a/src/platform/gui/xcb/InputMethod.cpp
+++ b/src/platform/gui/xcb/InputMethod.cpp
@@ -57,23 +57,6 @@ XcbXimInputMethodManager::XcbXimInputMethodManager(
}
}
}
- },
- .preedit_start =
- [](xcb_xim_t *im, xcb_xic_t ic, void *user_data) {
-
- },
- .preedit_draw =
- [](xcb_xim_t *im, xcb_xic_t ic, xcb_im_preedit_draw_fr_t *frame,
- void *user_data) {
- auto manager = static_cast<XcbXimInputMethodManager *>(user_data);
- CompositionText text;
- if (!(frame->status & 1)) {
- text.text = String::FromUtf8(
- reinterpret_cast<const std::byte *>(frame->preedit_string),
- frame->length_of_preedit_string);
- text.selection = frame->caret;
- }
- manager->DispatchComposition(im, ic, std::move(text));
}};
xcb_compound_text_init();
@@ -235,7 +218,7 @@ void XcbXimInputMethodContext::CreateIc(xcb_window_t window) {
};
uint32_t input_style =
- XCB_IM_PreeditArea | XCB_IM_PreeditCallbacks | XCB_IM_StatusNothing;
+ XCB_IM_PreeditArea | XCB_IM_PreeditPosition | XCB_IM_StatusNothing;
xcb_xim_create_ic(manager_->GetXcbXim(), XimCreateIcCallback, this,
XCB_XIM_XNInputStyle, &input_style, XCB_XIM_XNClientWindow,
&window, XCB_XIM_XNFocusWindow, &window, NULL);
diff --git a/src/platform/gui/xcb/Keyboard.cpp b/src/platform/gui/xcb/Keyboard.cpp
index c52f7cc1..f49cac51 100644
--- a/src/platform/gui/xcb/Keyboard.cpp
+++ b/src/platform/gui/xcb/Keyboard.cpp
@@ -7,6 +7,7 @@
#include <xcb/xcb.h>
#include <xcb/xproto.h>
#include <bitset>
+#include <cctype>
#include <climits>
#include <unordered_map>
#include <utility>
@@ -114,9 +115,10 @@ KeyCode XorgKeycodeToCruKeyCode(XcbUiApplication *application,
return KeyCode::Unknown;
}
-std::string XorgKeysymToUtf8(xcb_keysym_t keysym) {
+std::string XorgKeysymToUtf8(xcb_keysym_t keysym, bool upper) {
if (0x20 <= keysym && keysym <= 0x7e || 0xa0 <= keysym && keysym <= 0xff) {
- return std::string{static_cast<char>(keysym)};
+ return std::string{
+ static_cast<char>(upper ? std::toupper(keysym) : keysym)};
}
if (0x01000100 <= keysym && keysym <= 0x0110FFFF) {