Commit d01b56db authored by Xuetian Weng's avatar Xuetian Weng
Browse files

kimpanel: implement reverse engine navigate with shift

parent 03bb4a02
......@@ -225,12 +225,14 @@ bool App::nativeEvent(xcb_generic_event_t* event)
if (keypress->event == QX11Info::appRootWindow()) {
auto sym = xcb_key_press_lookup_keysym(m_syms, keypress, 0);
uint state = keypress->state & USED_MASK;
if (m_triggersList.contains(qMakePair<uint, uint>(sym, state))) {
bool forward;
if ((forward = m_triggersList.contains(qMakePair<uint, uint>(sym, state)))
|| m_triggersList.contains(qMakePair<uint, uint>(sym, state & (~XCB_MOD_MASK_SHIFT)))) {
if (m_keyboardGrabbed) {
ibus_panel_impanel_navigate(m_impanel, false);
ibus_panel_impanel_navigate(m_impanel, false, forward);
} else {
if (grabXKeyboard()) {
ibus_panel_impanel_navigate(m_impanel, true);
ibus_panel_impanel_navigate(m_impanel, true, forward);
} else {
ibus_panel_impanel_move_next(m_impanel);
}
......@@ -377,6 +379,10 @@ void App::grabKey()
} else {
xcb_grab_key(QX11Info::connection(), true, QX11Info::appRootWindow(),
modifiers, keycode[0], XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
if ((modifiers & XCB_MOD_MASK_SHIFT) == 0) {
xcb_grab_key(QX11Info::connection(), true, QX11Info::appRootWindow(),
modifiers | XCB_MOD_MASK_SHIFT, keycode[0], XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
}
}
free(keycode);
}
......@@ -392,6 +398,9 @@ void App::ungrabKey()
g_warning ("Can not convert keyval=%lu to keycode!", sym);
} else {
xcb_ungrab_key(QX11Info::connection(), keycode[0], QX11Info::appRootWindow(), modifiers);
if ((modifiers & XCB_MOD_MASK_SHIFT) == 0) {
xcb_ungrab_key(QX11Info::connection(), keycode[0], QX11Info::appRootWindow(), modifiers | XCB_MOD_MASK_SHIFT);
}
}
free(keycode);
}
......
......@@ -95,7 +95,7 @@ void EngineManager::setCurrentEngine(const char* name)
}
}
const char* EngineManager::navigate(IBusEngineDesc* engine)
const char* EngineManager::navigate(IBusEngineDesc* engine, bool forward)
{
if (length() == 0) {
return "";
......@@ -108,7 +108,7 @@ const char* EngineManager::navigate(IBusEngineDesc* engine)
break;
}
}
i = (i + 1) % length();
i = (i + (forward ? 1 : (length() - 1))) % length();
return ibus_engine_desc_get_name(m_engines[i]);
}
......
......@@ -40,7 +40,7 @@ public:
QString currentEngine();
bool useGlobalEngine() { return m_useGlobalEngine; }
void setCurrentEngine(const char* name);
const char* navigate(IBusEngineDesc* engine);
const char* navigate(IBusEngineDesc* engine, bool forward);
void moveToFirst(IBusEngineDesc* engine_desc);
QStringList engineOrder();
void setOrder(const gchar** engine_names, size_t len);
......
......@@ -103,7 +103,7 @@ void ibus_panel_impanel_accept(IBusPanelImpanel* impanel)
}
}
void ibus_panel_impanel_navigate(IBusPanelImpanel* impanel, gboolean start)
void ibus_panel_impanel_navigate(IBusPanelImpanel* impanel, gboolean start, gboolean forward)
{
if (start) {
impanel->selected = -1;
......@@ -125,7 +125,7 @@ void ibus_panel_impanel_navigate(IBusPanelImpanel* impanel, gboolean start)
}
if (engine_desc) {
const char* name = impanel->engineManager->navigate(engine_desc);
const char* name = impanel->engineManager->navigate(engine_desc, forward);
impanel->selected = impanel->engineManager->getIndexByName(name);
} else {
return;
......
......@@ -52,7 +52,7 @@ void ibus_panel_impanel_set_bus (IBusPanelImpanel *impanel
void ibus_panel_impanel_set_app (IBusPanelImpanel *impanel,
App *app);
void ibus_panel_impanel_accept (IBusPanelImpanel *impanel);
void ibus_panel_impanel_navigate (IBusPanelImpanel *impanel, gboolean start);
void ibus_panel_impanel_navigate (IBusPanelImpanel *impanel, gboolean start, gboolean forward);
void ibus_panel_impanel_move_next (IBusPanelImpanel *impanel);
G_END_DECLS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment