Skip to content

Commit

Permalink
Merge pull request #82 from Riey/releases/0.5.0
Browse files Browse the repository at this point in the history
Release 0.5.0
  • Loading branch information
Riey authored Jan 18, 2021
2 parents 6af076f + d8a65c6 commit ba86ba9
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ on:
push:
branches-ignore:
- 'master'
- 'releases/*'
pull_request:
branches:
- 'develop'
- 'master'

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release

on:
push:
branches:
- 'releases/*'

env:
CARGO_TERM_COLOR: always

jobs:
packaging:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- 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: Install cargo-deb
run: cargo install cargo-deb

- 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

5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions engine/capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,4 +27,5 @@ conflicts = "kime-engine"

assets = [
["target/release/libkime_engine.so", "usr/lib", "755"],
["data/config.yaml", "etc/kime", "644"],
]
7 changes: 7 additions & 0 deletions engine/capi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
std::fs::write(
"data/config.yaml",
serde_yaml::to_string(&kime_engine_core::RawConfig::default()).unwrap(),
)
.unwrap();
}
4 changes: 2 additions & 2 deletions engine/core/data/config.yaml → engine/capi/data/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 5 additions & 12 deletions engine/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Config {
pub fn from_raw_config(raw: RawConfig, dir: Option<xdg::BaseDirectories>) -> 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 {
Expand Down Expand Up @@ -133,17 +133,10 @@ impl Config {
pub fn load_from_config_dir() -> Option<Self> {
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)))
}
Expand Down
2 changes: 1 addition & 1 deletion engine/core/src/keycode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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-")?;
}

Expand Down
11 changes: 6 additions & 5 deletions gtk3/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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_MOD4_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);
Expand Down Expand Up @@ -158,7 +157,7 @@ impl KimeIMContext {
state |= MODIFIER_CONTROL;
}

if key.state & GDK_SUPER_MASK != 0 {
if key.state & GDK_MOD4_MASK != 0 {
state |= MODIFIER_SUPER;
}

Expand Down Expand Up @@ -216,7 +215,9 @@ 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() {
Expand Down
11 changes: 8 additions & 3 deletions pkg/release-7z.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#!/bin/sh

set -e

cargo build --release

mkdir -pv build/7z

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

7z a build/kime.7z build/7z/*
7z a build/kime.7z ./build/7z/*

rm build/7z/*

Expand Down
4 changes: 4 additions & 0 deletions pkg/release-deb.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/sh

set -e

cargo build --release

mkdir -pv build/deb

cargo deb -p kime-engine-capi
Expand Down
8 changes: 0 additions & 8 deletions release.sh

This file was deleted.

50 changes: 9 additions & 41 deletions xim/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ use kime_engine_cffi::{

pub struct KimeData {
engine: InputEngine,
callback_started: bool,
pe: Option<NonZeroU32>,
}

impl KimeData {
pub fn new() -> Self {
Self {
engine: InputEngine::new(),
callback_started: false,
pe: None,
}
}
Expand Down Expand Up @@ -70,20 +68,11 @@ impl KimeHandler {
ic: &mut xim::InputContext<KimeData>,
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(),
Expand Down Expand Up @@ -120,10 +109,7 @@ impl KimeHandler {
server: &mut X11rbServer<XCBConnection>,
ic: &mut xim::InputContext<KimeData>,
) -> 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());
Expand All @@ -148,7 +134,7 @@ impl KimeHandler {
}

impl ServerHandler<X11rbServer<XCBConnection>> for KimeHandler {
type InputStyleArray = [InputStyle; 7];
type InputStyleArray = [InputStyle; 3];
type InputContextData = KimeData;

fn new_ic_data(
Expand All @@ -163,13 +149,9 @@ impl ServerHandler<X11rbServer<XCBConnection>> 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
]
}

Expand Down Expand Up @@ -200,12 +182,7 @@ impl ServerHandler<X11rbServer<XCBConnection>> 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(())
}
Expand Down Expand Up @@ -316,18 +293,9 @@ impl ServerHandler<X11rbServer<XCBConnection>> for KimeHandler {

fn handle_preedit_start(
&mut self,
server: &mut X11rbServer<XCBConnection>,
input_context: &mut xim::InputContext<Self::InputContextData>,
_server: &mut X11rbServer<XCBConnection>,
_input_context: &mut xim::InputContext<Self::InputContextData>,
) -> 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(())
}

Expand Down

0 comments on commit ba86ba9

Please sign in to comment.