From 22994bd8eec1206f0393ff3ca7af7351b0d3d9c5 Mon Sep 17 00:00:00 2001 From: Riey Date: Sun, 17 Jan 2021 23:27:42 +0900 Subject: [PATCH 01/14] Update xim-rs for utf-8 --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3189c446..39553ba0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -805,7 +805,7 @@ checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" [[package]] name = "xim" version = "0.1.0" -source = "git+https://github.com/Riey/xim-rs#02f7e0000fd5d915aa274f21691777fa6ff84ed0" +source = "git+https://github.com/Riey/xim-rs#3377de7a0af10e9ac79ea401980170d21caadd1e" dependencies = [ "ahash", "ctext", @@ -818,7 +818,7 @@ dependencies = [ [[package]] name = "xim-parser" version = "0.1.0" -source = "git+https://github.com/Riey/xim-rs#02f7e0000fd5d915aa274f21691777fa6ff84ed0" +source = "git+https://github.com/Riey/xim-rs#3377de7a0af10e9ac79ea401980170d21caadd1e" dependencies = [ "bitflags", "thiserror", From ed2fd15923a870daa08a4494b7864a589a41d1c9 Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 00:32:09 +0900 Subject: [PATCH 02/14] Remove on-the-spot codes --- xim/src/handler.rs | 50 +++++++++------------------------------------- 1 file changed, 9 insertions(+), 41 deletions(-) diff --git a/xim/src/handler.rs b/xim/src/handler.rs index 83a90832..4013cb48 100644 --- a/xim/src/handler.rs +++ b/xim/src/handler.rs @@ -17,7 +17,6 @@ use kime_engine_cffi::{ pub struct KimeData { engine: InputEngine, - callback_started: bool, pe: Option, } @@ -25,7 +24,6 @@ impl KimeData { pub fn new() -> Self { Self { engine: InputEngine::new(), - callback_started: false, pe: None, } } @@ -70,20 +68,11 @@ impl KimeHandler { ic: &mut xim::InputContext, ch: char, ) -> Result<(), xim::ServerError> { - if ic.input_style().contains(InputStyle::PREEDIT_CALLBACKS) { - log::trace!("Preedit callback"); - // on-the-spot send preedit callback - if !ic.user_data.callback_started { - server.preedit_start(ic)?; - } else { - let mut b = [0; 4]; - server.preedit_draw(ic, ch.encode_utf8(&mut b))?; - } - } else if let Some(pe) = ic.user_data.pe.as_mut() { - // over-the-spot draw in server (already have pe_window) + if let Some(pe) = ic.user_data.pe.as_mut() { + // draw in server (already have pe_window) self.preedit_windows.get_mut(pe).unwrap().set_preedit(ch); } else { - // over-the-spot draw in server + // draw in server let mut pe = PeWindow::new( server.conn(), self.config.xim_font_name(), @@ -120,10 +109,7 @@ impl KimeHandler { server: &mut X11rbServer, ic: &mut xim::InputContext, ) -> Result<(), xim::ServerError> { - if ic.input_style().contains(InputStyle::PREEDIT_CALLBACKS) { - ic.user_data.callback_started = false; - server.preedit_done(ic)?; - } else if let Some(pe) = ic.user_data.pe.take() { + if let Some(pe) = ic.user_data.pe.take() { // off-the-spot draw in server if let Some(w) = self.preedit_windows.remove(&pe) { log::trace!("Destory PeWindow: {}", w.window()); @@ -148,7 +134,7 @@ impl KimeHandler { } impl ServerHandler> for KimeHandler { - type InputStyleArray = [InputStyle; 7]; + type InputStyleArray = [InputStyle; 3]; type InputContextData = KimeData; fn new_ic_data( @@ -163,13 +149,9 @@ impl ServerHandler> for KimeHandler { [ // over-spot InputStyle::PREEDIT_NOTHING | InputStyle::STATUS_NOTHING, - InputStyle::PREEDIT_POSITION | InputStyle::STATUS_AREA, InputStyle::PREEDIT_POSITION | InputStyle::STATUS_NOTHING, InputStyle::PREEDIT_POSITION | InputStyle::STATUS_NONE, - // on-the-spot - InputStyle::PREEDIT_CALLBACKS | InputStyle::STATUS_NOTHING, - InputStyle::PREEDIT_CALLBACKS | InputStyle::STATUS_NONE, - InputStyle::PREEDIT_CALLBACKS | InputStyle::STATUS_AREA, + // // on-the-spot when enable this java awt doesn't work I don't know why ] } @@ -200,12 +182,7 @@ impl ServerHandler> for KimeHandler { input_context.input_style(), input_context.preedit_spot() ); - server.set_event_mask( - input_context, - EventMask::KeyPress | EventMask::KeyRelease, - 0, - // EventMask::KeyPress | EventMask::KeyRelease, - )?; + server.set_event_mask(input_context, EventMask::KeyPress.into(), 0)?; Ok(()) } @@ -316,18 +293,9 @@ impl ServerHandler> for KimeHandler { fn handle_preedit_start( &mut self, - server: &mut X11rbServer, - input_context: &mut xim::InputContext, + _server: &mut X11rbServer, + _input_context: &mut xim::InputContext, ) -> Result<(), xim::ServerError> { - log::trace!("preedit started"); - input_context.user_data.callback_started = true; - let mut b = [0; 4]; - let s = input_context - .user_data - .engine - .preedit_char() - .encode_utf8(&mut b); - server.preedit_draw(input_context, s)?; Ok(()) } From 22b4c84aa8a077d9860204efacd8f3bbc33d153c Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 13:51:31 +0900 Subject: [PATCH 03/14] Don't skip MOD4 mask --- gtk3/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gtk3/src/lib.rs b/gtk3/src/lib.rs index bfc08395..e3c47263 100644 --- a/gtk3/src/lib.rs +++ b/gtk3/src/lib.rs @@ -1,7 +1,7 @@ use gdk_sys::{ gdk_event_copy, gdk_event_put, gdk_keyval_to_unicode, gdk_window_get_user_data, GdkColor, GdkEvent, GdkEventKey, GdkWindow, GDK_CONTROL_MASK, GDK_KEY_PRESS, GDK_MOD1_MASK, - GDK_MOD2_MASK, GDK_MOD3_MASK, GDK_MOD4_MASK, GDK_MOD5_MASK, GDK_SHIFT_MASK, GDK_SUPER_MASK, + GDK_MOD2_MASK, GDK_MOD3_MASK, GDK_MOD4_MASK, GDK_MOD5_MASK, GDK_SHIFT_MASK, }; use glib_sys::{g_malloc0, g_strcmp0, g_strdup, gboolean, gpointer, GType, GFALSE, GTRUE}; use gobject_sys::{ @@ -34,7 +34,7 @@ use kime_engine_cffi::{ const FORWARDED_MASK: c_uint = 1 << 25; const SKIP_MASK: c_uint = - GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK; + GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD5_MASK; #[repr(transparent)] struct TypeInfoWrapper(GTypeInfo); @@ -158,7 +158,7 @@ impl KimeIMContext { state |= MODIFIER_CONTROL; } - if key.state & GDK_SUPER_MASK != 0 { + if key.state & GDK_MOD4_MASK != 0 { state |= MODIFIER_SUPER; } From e4e40cb17b7e2ae83b3893f56017a2b7b14b9c0a Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 13:53:38 +0900 Subject: [PATCH 04/14] Don't commit Super-{} Only commit english when modifier is empty or shift --- gtk3/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk3/src/lib.rs b/gtk3/src/lib.rs index e3c47263..34cd778b 100644 --- a/gtk3/src/lib.rs +++ b/gtk3/src/lib.rs @@ -216,7 +216,7 @@ impl KimeIMContext { } pub fn commit_event(&mut self, key: &GdkEventKey) -> gboolean { - if self.shared.config.gtk_commit_english() && key.state & GDK_CONTROL_MASK == 0 { + if self.shared.config.gtk_commit_english() && (key.state == 0 || key.state == GDK_SHIFT_MASK) { let c = unsafe { std::char::from_u32_unchecked(gdk_keyval_to_unicode(key.keyval)) }; if !c.is_control() { From e7af33304706f638d3305008d564ca458853a26e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 18 Jan 2021 04:56:49 +0000 Subject: [PATCH 05/14] Format Rust code using rustfmt --- gtk3/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gtk3/src/lib.rs b/gtk3/src/lib.rs index 34cd778b..09fd7982 100644 --- a/gtk3/src/lib.rs +++ b/gtk3/src/lib.rs @@ -33,8 +33,7 @@ use kime_engine_cffi::{ }; const FORWARDED_MASK: c_uint = 1 << 25; -const SKIP_MASK: c_uint = - GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD5_MASK; +const SKIP_MASK: c_uint = GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD5_MASK; #[repr(transparent)] struct TypeInfoWrapper(GTypeInfo); @@ -216,7 +215,9 @@ impl KimeIMContext { } pub fn commit_event(&mut self, key: &GdkEventKey) -> gboolean { - if self.shared.config.gtk_commit_english() && (key.state == 0 || key.state == GDK_SHIFT_MASK) { + if self.shared.config.gtk_commit_english() + && (key.state == 0 || key.state == GDK_SHIFT_MASK) + { let c = unsafe { std::char::from_u32_unchecked(gdk_keyval_to_unicode(key.keyval)) }; if !c.is_control() { From 0d466af6780d08efa643a378a4f98eb830efdc07 Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 14:27:02 +0900 Subject: [PATCH 06/14] Generate config.yaml from build script --- Cargo.lock | 1 + engine/capi/Cargo.toml | 5 +++++ engine/capi/build.rs | 7 +++++++ engine/{core => capi}/data/config.yaml | 4 ++-- engine/core/src/keycode.rs | 2 +- pkg/release-7z.sh | 3 +-- 6 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 engine/capi/build.rs rename engine/{core => capi}/data/config.yaml (100%) diff --git a/Cargo.lock b/Cargo.lock index 39553ba0..dbdb5358 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -340,6 +340,7 @@ name = "kime-engine-capi" version = "0.5.0" dependencies = [ "kime-engine-core", + "serde_yaml", ] [[package]] diff --git a/engine/capi/Cargo.toml b/engine/capi/Cargo.toml index f0c6db10..86213eca 100644 --- a/engine/capi/Cargo.toml +++ b/engine/capi/Cargo.toml @@ -13,6 +13,10 @@ crate-type = ["cdylib"] [dependencies] kime-engine-core = { path = "../core" } +[build-dependencies] +kime-engine-core = { path = "../core" } +serde_yaml = "0.8.15" + [package.metadata.deb] name = "kime-engine" maintainer = "Riey" @@ -23,4 +27,5 @@ conflicts = "kime-engine" assets = [ ["target/release/libkime_engine.so", "usr/lib", "755"], + ["data/config.yaml", "etc/kime", "644"], ] diff --git a/engine/capi/build.rs b/engine/capi/build.rs new file mode 100644 index 00000000..b386b8d1 --- /dev/null +++ b/engine/capi/build.rs @@ -0,0 +1,7 @@ +fn main() { + std::fs::write( + "data/config.yaml", + serde_yaml::to_string(&kime_engine_core::RawConfig::default()).unwrap(), + ) + .unwrap(); +} diff --git a/engine/core/data/config.yaml b/engine/capi/data/config.yaml similarity index 100% rename from engine/core/data/config.yaml rename to engine/capi/data/config.yaml index 1c073baa..29137f75 100644 --- a/engine/core/data/config.yaml +++ b/engine/capi/data/config.yaml @@ -2,10 +2,10 @@ layout: dubeolsik esc_turn_off: true hangul_keys: - - Hangul + - AltR - Henkan + - Hangul - Super-Space - - AltR xim_preedit_font: D2Coding gtk_commit_english: true compose: diff --git a/engine/core/src/keycode.rs b/engine/core/src/keycode.rs index 2e183fd9..afce5d0e 100644 --- a/engine/core/src/keycode.rs +++ b/engine/core/src/keycode.rs @@ -197,7 +197,7 @@ impl fmt::Display for Key { f.write_str("C-")?; } - if self.state.contains(ModifierState::SUPER) { + if self.state.contains(ModifierState::SHIFT) { f.write_str("S-")?; } diff --git a/pkg/release-7z.sh b/pkg/release-7z.sh index 10c7abb0..ba446bdb 100755 --- a/pkg/release-7z.sh +++ b/pkg/release-7z.sh @@ -4,10 +4,9 @@ cp target/release/kime-xim build/7z/kime-xim cp target/release/libkime_gtk3.so build/7z/im-kime.so cp target/release/libkime_engine.so build/7z/libkime_engine.so +cp engine/capi/data/config.yaml build/7z cp engine/cffi/kime_engine.h build/7z -# cp engine/data/config.yaml build/ - strip -s build/7z/kime-xim strip -s build/7z/libkime_engine.so strip -s build/7z/im-kime.so From 628ff1f3fbc5e3485e2cafcb092fe4783e82c153 Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 14:29:02 +0900 Subject: [PATCH 07/14] Don't write default config file on core --- engine/core/src/config.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/engine/core/src/config.rs b/engine/core/src/config.rs index 66217ef7..e027b875 100644 --- a/engine/core/src/config.rs +++ b/engine/core/src/config.rs @@ -133,17 +133,10 @@ impl Config { pub fn load_from_config_dir() -> Option { let dir = xdg::BaseDirectories::with_prefix("kime").ok()?; - let config = match dir.find_config_file("config.yaml") { - Some(config) => config, - None => { - let path = dir.place_config_file("config.yaml").ok()?; - std::fs::write(&path, serde_yaml::to_string(&RawConfig::default()).ok()?).ok()?; - path - } - }; - - let raw: RawConfig = - serde_yaml::from_reader(std::fs::File::open(config).ok()?).unwrap_or_default(); + let raw = dir + .find_config_file("config.yaml") + .and_then(|config| serde_yaml::from_reader(std::fs::File::open(config).ok()?).ok()) + .unwrap_or_default(); Some(Self::from_raw_config(raw, Some(dir))) } From 9341c2274b268c9bb8e38a2d074c2e1bda0272ce Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 14:33:10 +0900 Subject: [PATCH 08/14] Find layout files from config dir --- engine/core/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/core/src/config.rs b/engine/core/src/config.rs index e027b875..3621e43d 100644 --- a/engine/core/src/config.rs +++ b/engine/core/src/config.rs @@ -94,7 +94,7 @@ impl Config { pub fn from_raw_config(raw: RawConfig, dir: Option) -> Self { let layout = dir .and_then(|dir| { - dir.list_data_files("layouts") + dir.list_config_files("layouts") .into_iter() .find_map(|layout| { if layout.file_stem()?.to_str()? == raw.layout { From 95afb0d76248851653d1525f33d9af90695eb89b Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 14:54:50 +0900 Subject: [PATCH 09/14] Remove 7z pkg build/7z path prefix --- pkg/release-7z.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/release-7z.sh b/pkg/release-7z.sh index ba446bdb..6d3ae99c 100755 --- a/pkg/release-7z.sh +++ b/pkg/release-7z.sh @@ -11,7 +11,7 @@ strip -s build/7z/kime-xim strip -s build/7z/libkime_engine.so strip -s build/7z/im-kime.so -7z a build/kime.7z build/7z/* +7z a build/kime.7z ./build/7z/* rm build/7z/* From a9bc6d2510cd7edbe2ad1d95a4a8822fad4eafe7 Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 15:25:41 +0900 Subject: [PATCH 10/14] Remove release.sh --- Dockerfile | 3 +-- pkg/release-7z.sh | 6 ++++++ pkg/release-deb.sh | 4 ++++ release.sh | 8 -------- 4 files changed, 11 insertions(+), 10 deletions(-) delete mode 100755 release.sh diff --git a/Dockerfile b/Dockerfile index 8ce6c1b4..c162a815 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,5 @@ RUN cargo install -f cargo-deb COPY LICENSE . COPY pkg ./pkg -COPY release.sh ./release.sh -CMD ./release.sh +CMD ./pkg/release-deb.sh diff --git a/pkg/release-7z.sh b/pkg/release-7z.sh index 6d3ae99c..512b2838 100755 --- a/pkg/release-7z.sh +++ b/pkg/release-7z.sh @@ -1,3 +1,9 @@ +#!/bin/sh + +set -e + +cargo build --release + mkdir -pv build/7z cp target/release/kime-xim build/7z/kime-xim diff --git a/pkg/release-deb.sh b/pkg/release-deb.sh index 2be328e7..0df48ea5 100755 --- a/pkg/release-deb.sh +++ b/pkg/release-deb.sh @@ -1,5 +1,9 @@ #!/bin/sh +set -e + +cargo build --release + mkdir -pv build/deb cargo deb -p kime-engine-capi diff --git a/release.sh b/release.sh deleted file mode 100755 index 50abb5bd..00000000 --- a/release.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -set -e - -cargo build --release - -pkg/release-7z.sh -pkg/release-deb.sh From 94eaaed31962904a36adf99f3bb1598834fd4a56 Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 15:34:43 +0900 Subject: [PATCH 11/14] Add release workflow --- .github/workflows/ci.yaml | 3 ++- .github/workflows/release.yaml | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 257ed137..ad18ff6f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,10 +14,11 @@ env: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 + - uses: Swatinem/rust-cache@v1 - name: Update apt run: sudo apt-get update -y - name: Install packages diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..151bd334 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,39 @@ +name: Release + +on: + push: + branches: + - 'releases/*' + - 'master' + +env: + CARGO_TERM_COLOR: always + +jobs: + packaging: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + - uses: Swatinem/rust-cache@v1 + - name: Update apt + run: sudo apt-get update -y + - name: Install packages + run: sudo apt-get install -y pkg-config libpango1.0-dev libcairo2-dev libgtk-3-dev libglib2.0 libxcb1 + + - name: Generate 7z package... + run: pkg/release-7z.sh + - name: Upload 7z package + uses: actions/upload-artifact@v2 + with: + name: pkg-7z + path: build/7z + + - name: Generate deb package... + run: pkg/release-deb.sh + - name: Upload deb package + uses: actions/upload-artifact@v2 + with: + name: pkg-deb + path: build/deb + \ No newline at end of file From ef67de0c9fcda314cb8efed2fd7f855c85c69a31 Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 15:40:15 +0900 Subject: [PATCH 12/14] Install cargo-deb on release --- .github/workflows/release.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 151bd334..2e91aef7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,6 +20,8 @@ jobs: run: sudo apt-get update -y - name: Install packages run: sudo apt-get install -y pkg-config libpango1.0-dev libcairo2-dev libgtk-3-dev libglib2.0 libxcb1 + - name: Install cargo-deb + run: cargo install cargo-deb - name: Generate 7z package... run: pkg/release-7z.sh From 8d3a1935a4526a45033860cbb1133ff7415b0ed2 Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 15:42:41 +0900 Subject: [PATCH 13/14] Remove rust-cache workflow --- .github/workflows/ci.yaml | 1 - .github/workflows/release.yaml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ad18ff6f..60812292 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,6 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: Swatinem/rust-cache@v1 - name: Update apt run: sudo apt-get update -y - name: Install packages diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2e91aef7..fb1ad6b4 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -15,7 +15,6 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: Swatinem/rust-cache@v1 - name: Update apt run: sudo apt-get update -y - name: Install packages From d8a65c65c6662255eeb817043e89ab295f651ae2 Mon Sep 17 00:00:00 2001 From: Riey Date: Mon, 18 Jan 2021 15:51:25 +0900 Subject: [PATCH 14/14] Update workflows --- .github/workflows/ci.yaml | 2 +- .github/workflows/release.yaml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 60812292..41124e36 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,10 +4,10 @@ on: push: branches-ignore: - 'master' + - 'releases/*' pull_request: branches: - 'develop' - - 'master' env: CARGO_TERM_COLOR: always diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index fb1ad6b4..92bf635a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -4,7 +4,6 @@ on: push: branches: - 'releases/*' - - 'master' env: CARGO_TERM_COLOR: always