summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2014-12-08 14:45:50 +0800
committerPeng Wu <alexepico@gmail.com>2014-12-08 14:45:50 +0800
commit1f68a74635ab683263e275ba63b77f4007ba6634 (patch)
tree8053ff4099918214e328b06e0300a68a03e96622 /src
parent76d62fd53b46fe6935eec9c0eefe0617d5d7f0b7 (diff)
downloadibus-libpinyin-1f68a74635ab683263e275ba63b77f4007ba6634.tar.gz
ibus-libpinyin-1f68a74635ab683263e275ba63b77f4007ba6634.tar.xz
ibus-libpinyin-1f68a74635ab683263e275ba63b77f4007ba6634.zip
support four customized shortcut keys
Diffstat (limited to 'src')
-rw-r--r--src/PYFallbackEditor.cc5
-rw-r--r--src/PYPBopomofoEngine.cc60
-rw-r--r--src/PYPBopomofoEngine.h2
-rw-r--r--src/PYPPinyinEngine.cc57
-rw-r--r--src/PYPPinyinEngine.h2
5 files changed, 90 insertions, 36 deletions
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);