From 1f68a74635ab683263e275ba63b77f4007ba6634 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 8 Dec 2014 14:45:50 +0800 Subject: support four customized shortcut keys --- src/PYFallbackEditor.cc | 5 ---- src/PYPBopomofoEngine.cc | 60 +++++++++++++++++++++++++++++++++++------------- src/PYPBopomofoEngine.h | 2 ++ src/PYPPinyinEngine.cc | 57 +++++++++++++++++++++++++++++++++------------ src/PYPPinyinEngine.h | 2 ++ 5 files changed, 90 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/PYFallbackEditor.cc b/src/PYFallbackEditor.cc index c9583be..d82051d 100644 --- a/src/PYFallbackEditor.cc +++ b/src/PYFallbackEditor.cc @@ -166,11 +166,6 @@ FallbackEditor::processPunct (guint keyval, guint keycode, guint modifiers) { guint cmshm_modifiers = cmshm_filter (modifiers); - if (G_UNLIKELY (keyval == IBUS_period && cmshm_modifiers == IBUS_CONTROL_MASK)) { - m_props.toggleModeFullPunct (); - return TRUE; - } - /* check ctrl, alt, hyper, supper masks */ if (cmshm_modifiers != 0) return FALSE; diff --git a/src/PYPBopomofoEngine.cc b/src/PYPBopomofoEngine.cc index 1d7107e..0dc8eb6 100644 --- a/src/PYPBopomofoEngine.cc +++ b/src/PYPBopomofoEngine.cc @@ -59,13 +59,17 @@ BopomofoEngine::~BopomofoEngine (void) { } +/* keep synced with pinyin engine. */ gboolean -BopomofoEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) +BopomofoEngine::processAccelKeyEvent (guint keyval, guint keycode, + guint modifiers) { - gboolean retval = FALSE; + std::string accel; + pinyin_accelerator_name(keyval, modifiers, accel); - if (contentIsPassword ()) - return retval; + /* Safe Guard for empty key. */ + if ("" == accel) + return FALSE; /* check Shift or Ctrl + Release hotkey, * and then ignore other Release key event */ @@ -74,13 +78,9 @@ BopomofoEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) * and no other key event between the press and release key event */ gboolean triggered = FALSE; - if (m_prev_pressed_key == keyval) { - if (BopomofoConfig::instance ().ctrlSwitch ()) { - if (keyval == IBUS_Control_L || keyval == IBUS_Control_R) - triggered = TRUE; - } else { - if (keyval == IBUS_Shift_L || keyval == IBUS_Shift_R) - triggered = TRUE; + if (m_prev_pressed_key == keyval){ + if (PinyinConfig::instance ().mainSwitch () == accel) { + triggered = TRUE; } } @@ -93,7 +93,7 @@ BopomofoEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) if (m_input_mode == MODE_INIT && m_editors[MODE_INIT]->text ().empty ()) { - /* If it is init mode, and no any previous input text, + /* If it is in init mode, and no any previous input text, * we will let client applications to handle release key event */ return FALSE; } else { @@ -101,13 +101,41 @@ BopomofoEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) } } - /* Toggle simp/trad Chinese Mode when hotkey Ctrl + Shift + F pressed */ - if (keyval == IBUS_F && scmshm_test (modifiers, (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK))) { - m_props.toggleModeSimp(); - m_prev_pressed_key = IBUS_F; + /* Toggle full/half Letter Mode */ + if (PinyinConfig::instance (). letterSwitch () == accel) { + m_props.toggleModeFull (); + m_prev_pressed_key = keyval; + return TRUE; + } + + /* Toggle full/half Punct Mode */ + if (PinyinConfig::instance (). punctSwitch () == accel) { + m_props.toggleModeFullPunct (); + m_prev_pressed_key = keyval; + return TRUE; + } + + /* Toggle simp/trad Chinese Mode */ + if (PinyinConfig::instance ().tradSwitch () == accel) { + m_props.toggleModeSimp (); + m_prev_pressed_key = keyval; return TRUE; } + return FALSE; +} + +gboolean +BopomofoEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) +{ + gboolean retval = FALSE; + + if (contentIsPassword ()) + return retval; + + if (processAccelKeyEvent (keyval, keycode, modifiers)) + return TRUE; + if (m_props.modeChinese ()) { if (G_UNLIKELY (m_input_mode == MODE_INIT && m_editors[MODE_INIT]->text ().empty () && diff --git a/src/PYPBopomofoEngine.h b/src/PYPBopomofoEngine.h index f52de47..7133a55 100644 --- a/src/PYPBopomofoEngine.h +++ b/src/PYPBopomofoEngine.h @@ -34,6 +34,8 @@ public: ~BopomofoEngine (void); // virtual functions + gboolean processAccelKeyEvent (guint keyval, guint keycode, + guint modifiers); gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); void focusIn (void); void focusOut (void); diff --git a/src/PYPPinyinEngine.cc b/src/PYPPinyinEngine.cc index 4171e9a..3d6cba4 100644 --- a/src/PYPPinyinEngine.cc +++ b/src/PYPPinyinEngine.cc @@ -95,13 +95,17 @@ PinyinEngine::~PinyinEngine (void) { } +/* keep synced with bopomofo engine. */ gboolean -PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) +PinyinEngine::processAccelKeyEvent (guint keyval, guint keycode, + guint modifiers) { - gboolean retval = FALSE; + std::string accel; + pinyin_accelerator_name(keyval, modifiers, accel); - if (contentIsPassword ()) - return retval; + /* Safe Guard for empty key. */ + if ("" == accel) + return FALSE; /* check Shift or Ctrl + Release hotkey, * and then ignore other Release key event */ @@ -111,12 +115,8 @@ PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) gboolean triggered = FALSE; if (m_prev_pressed_key == keyval){ - if (PinyinConfig::instance ().ctrlSwitch ()) { - if (keyval == IBUS_Control_L || keyval == IBUS_Control_R) - triggered = TRUE; - } else { - if (keyval == IBUS_Shift_L || keyval == IBUS_Shift_R) - triggered = TRUE; + if (PinyinConfig::instance ().mainSwitch () == accel) { + triggered = TRUE; } } @@ -132,19 +132,46 @@ PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) /* If it is in init mode, and no any previous input text, * we will let client applications to handle release key event */ return FALSE; - } - else { + } else { return TRUE; } } - /* Toggle simp/trad Chinese Mode when hotkey Ctrl + Shift + F pressed */ - if (keyval == IBUS_F && scmshm_test (modifiers, (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK))) { + /* Toggle full/half Letter Mode */ + if (PinyinConfig::instance (). letterSwitch () == accel) { + m_props.toggleModeFull (); + m_prev_pressed_key = keyval; + return TRUE; + } + + /* Toggle full/half Punct Mode */ + if (PinyinConfig::instance (). punctSwitch () == accel) { + m_props.toggleModeFullPunct (); + m_prev_pressed_key = keyval; + return TRUE; + } + + /* Toggle simp/trad Chinese Mode */ + if (PinyinConfig::instance ().tradSwitch () == accel) { m_props.toggleModeSimp (); - m_prev_pressed_key = IBUS_F; + m_prev_pressed_key = keyval; return TRUE; } + return FALSE; +} + +gboolean +PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) +{ + gboolean retval = FALSE; + + if (contentIsPassword ()) + return retval; + + if (processAccelKeyEvent (keyval, keycode, modifiers)) + return TRUE; + if (m_props.modeChinese ()) { if (m_input_mode == MODE_INIT && (cmshm_filter (modifiers) == 0)) { diff --git a/src/PYPPinyinEngine.h b/src/PYPPinyinEngine.h index fa16cc2..5a19cc3 100644 --- a/src/PYPPinyinEngine.h +++ b/src/PYPPinyinEngine.h @@ -32,6 +32,8 @@ public: ~PinyinEngine (void); //virtual functions + gboolean processAccelKeyEvent (guint keyval, guint keycode, + guint modifiers); gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); void focusIn (void); void focusOut (void); -- cgit