Skip to content

Commit

Permalink
Support PageUp/PageDown
Browse files Browse the repository at this point in the history
  • Loading branch information
tokuhirom committed Jan 12, 2023
1 parent e047c98 commit 96704a3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
6 changes: 6 additions & 0 deletions ibus-akaza/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ pub(crate) fn ibus_akaza_commands_map() -> HashMap<&'static str, IbusAkazaComman
context.commit_string(engine, surface.as_str());
});
register("escape", |context, engine| context.escape(engine));
register("page_up", |context, engine| {
context.page_up(engine);
});
register("page_down", |context, engine| {
context.page_down(engine);
});

register("set_input_mode_hiragana", |context, engine| {
context.set_input_mode(engine, &INPUT_MODE_HIRAGANA)
Expand Down
28 changes: 28 additions & 0 deletions ibus-akaza/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,4 +887,32 @@ impl AkazaContext {
self.preedit.clear();
self.update_candidates(engine)
}

pub fn page_up(&mut self, engine: *mut IBusEngine) -> bool {
if self.lookup_table.page_up() {
self.node_selected.insert(
self.current_clause,
self.lookup_table.get_cursor_pos() as usize,
);
self.cursor_moved = true;
self.refresh(engine);
true
} else {
false
}
}

pub fn page_down(&mut self, engine: *mut IBusEngine) -> bool {
if self.lookup_table.page_up() {
self.node_selected.insert(
self.current_clause,
self.lookup_table.get_cursor_pos() as usize,
);
self.cursor_moved = true;
self.refresh(engine);
true
} else {
false
}
}
}
24 changes: 16 additions & 8 deletions ibus-akaza/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use log::trace;
use ibus_sys::core::{IBusModifierType_IBUS_CONTROL_MASK, IBusModifierType_IBUS_SHIFT_MASK};
use ibus_sys::ibus_key::{
IBUS_KEY_BackSpace, IBUS_KEY_Down, IBUS_KEY_Escape, IBUS_KEY_Hangul, IBUS_KEY_Hangul_Hanja,
IBUS_KEY_Henkan, IBUS_KEY_KP_Down, IBUS_KEY_KP_Enter, IBUS_KEY_KP_Left, IBUS_KEY_KP_Right,
IBUS_KEY_KP_Up, IBUS_KEY_Left, IBUS_KEY_Muhenkan, IBUS_KEY_Return, IBUS_KEY_Right, IBUS_KEY_Up,
IBUS_KEY_Henkan, IBUS_KEY_KP_Down, IBUS_KEY_KP_Enter, IBUS_KEY_KP_Left, IBUS_KEY_KP_Page_Down,
IBUS_KEY_KP_Page_Up, IBUS_KEY_KP_Right, IBUS_KEY_KP_Up, IBUS_KEY_Left, IBUS_KEY_Muhenkan,
IBUS_KEY_Page_Down, IBUS_KEY_Page_Up, IBUS_KEY_Return, IBUS_KEY_Right, IBUS_KEY_Up,
IBUS_KEY_colon, IBUS_KEY_h, IBUS_KEY_j, IBUS_KEY_k, IBUS_KEY_l, IBUS_KEY_space, IBUS_KEY_0,
IBUS_KEY_1, IBUS_KEY_2, IBUS_KEY_3, IBUS_KEY_4, IBUS_KEY_5, IBUS_KEY_6, IBUS_KEY_7, IBUS_KEY_8,
IBUS_KEY_9, IBUS_KEY_F10, IBUS_KEY_F6, IBUS_KEY_F7, IBUS_KEY_F8, IBUS_KEY_F9, IBUS_KEY_KP_0,
Expand Down Expand Up @@ -73,12 +74,6 @@ impl KeyMap {
pub(crate) fn new() -> Self {
let mut builder = KeyMapBuilder::new();

/*
keymap.register([KEY_STATE_CONVERSION], ['Page_Up', 'KP_Page_Up'], 'page_up')
keymap.register([KEY_STATE_CONVERSION], ['Page_Down', 'KP_Page_Down'], 'page_down')
*/

// TODO use IBus.Hotkey

// 入力モードの切り替え
Expand Down Expand Up @@ -254,6 +249,19 @@ impl KeyMap {
"convert_to_half_romaji",
);

builder.insert(
&[KeyState::Conversion],
&[IBUS_KEY_KP_Page_Up, IBUS_KEY_Page_Up],
0,
"page_up",
);
builder.insert(
&[KeyState::Conversion],
&[IBUS_KEY_KP_Page_Down, IBUS_KEY_Page_Down],
0,
"page_down",
);

let mut num = |keyvals: &[u32], n: i32| {
// fn insert(&mut self, key_states: &[KeyState], keyvals: &[u32], modifier: u32, func_name: &str) {
builder.insert(
Expand Down
9 changes: 9 additions & 0 deletions ibus-sys/src/lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ impl IBusLookupTable {
unsafe { ibus_lookup_table_get_page_size(self as *mut _) }
}

pub fn page_up(&mut self) -> bool {
unsafe { 1 == (ibus_lookup_table_page_up(self as *mut _)) }
}
pub fn page_down(&mut self) -> bool {
unsafe { 1 == ibus_lookup_table_page_down(self as *mut _) }
}

pub fn append_candidate(&mut self, text: *mut IBusText) {
unsafe { ibus_lookup_table_append_candidate(self as *mut _, text as *mut _) }
}
Expand All @@ -90,4 +97,6 @@ extern "C" {
pub fn ibus_lookup_table_get_cursor_pos(table: *mut IBusLookupTable) -> guint;
fn ibus_lookup_table_set_cursor_pos(table: *mut IBusLookupTable, cursor_pos: guint);
fn ibus_lookup_table_get_page_size(table: *mut IBusLookupTable) -> guint;
fn ibus_lookup_table_page_up(table: *mut IBusLookupTable) -> gboolean;
fn ibus_lookup_table_page_down(table: *mut IBusLookupTable) -> gboolean;
}

0 comments on commit 96704a3

Please sign in to comment.