From 2f27dd9940e700f6e58a2267e8ad621c46a0efa3 Mon Sep 17 00:00:00 2001 From: Mavridis Philippe Date: Thu, 1 Jun 2023 13:19:53 +0300 Subject: Added global shortcuts for switching to previous/next group This resolves issue #6. Signed-off-by: Mavridis Philippe --- kkbswitch/kbconfig.cpp | 10 ++++++++++ kkbswitch/kbconfig.h | 5 ++++- kkbswitch/kbswitchapp.cpp | 16 +++++++++++++--- kkbswitch/kbswitchapp.h | 4 +++- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/kkbswitch/kbconfig.cpp b/kkbswitch/kbconfig.cpp index 0113d1d..8dd270e 100644 --- a/kkbswitch/kbconfig.cpp +++ b/kkbswitch/kbconfig.cpp @@ -109,6 +109,16 @@ void KBConfig::load(TDEConfig *config){ TQString::null, TQt::ALT+TQt::CTRL+TQt::Key_1 + i, KKey::QtWIN+TQt::CTRL+TQt::Key_1 + i, kapp, SLOT(slotGroupSelected(int))); } + m_keys->insert("NextGroup", i18n("Cycle keyboard layouts"), + i18n("Activates the next keyboard layout or, if the current layout is the last one, " + "activates the first layout."), + TQt::SHIFT+TQt::CTRL+TQt::Key_Plus, TQt::SHIFT+TQt::CTRL+TQt::Key_Plus, + kapp, SLOT(slotSelectNextGroup())); + m_keys->insert("PrevGroup", i18n("Cycle keyboard layouts (reverse)"), + i18n("Activates the previous keyboard layout or, if the current layout is the first one, " + "activates the last layout."), + TQt::SHIFT+TQt::CTRL+TQt::Key_Minus, TQt::SHIFT+TQt::CTRL+TQt::Key_Minus, + kapp, SLOT(slotSelectPrevGroup())); m_keys->readSettings(config); checkKeysEnabled(); } diff --git a/kkbswitch/kbconfig.h b/kkbswitch/kbconfig.h index 5ff3936..93fd13c 100644 --- a/kkbswitch/kbconfig.h +++ b/kkbswitch/kbconfig.h @@ -85,9 +85,12 @@ public: void drawIcons(IconStyle icon_style, TQValueVector *icons, TQStringList *iconpaths); void checkKeysEnabled(); + int getPrevGroup(int groupno) { + return groupno == 0 ? groupCount() - 1 : groupno - 1; + } int getNextGroup(int groupno) { return groupno >= groupCount() - 1 ? 0 : groupno + 1; - } + } private: // Private methods /** No descriptions */ //void guessGroupPixmaps(); diff --git a/kkbswitch/kbswitchapp.cpp b/kkbswitch/kbswitchapp.cpp index 5e53487..0c9f675 100644 --- a/kkbswitch/kbswitchapp.cpp +++ b/kkbswitch/kbswitchapp.cpp @@ -130,15 +130,25 @@ void KBSwitchApp::forceSetGroup(int groupno) m_xkb.setGroupNo(groupno); } -/** No descriptions */ +/** Select the next keyboard layout (wraps around) */ void KBSwitchApp::slotSelectNextGroup() { #ifdef HAVE_LIBXKLAVIER m_xkb.setGroupNo(XklGetNextGroup()); -#else +#else //forceSetGroup(m_next_groupno); m_xkb.setGroupNo(m_next_groupno); -#endif +#endif +} + +/** Select the previous keyboard layout (wraps around) */ +void KBSwitchApp::slotSelectPrevGroup() +{ +#ifdef HAVE_LIBXKLAVIER + m_xkb.setGroupNo(XklGetPrevGroup()); +#else + m_xkb.setGroupNo(m_kbconf.getPrevGroup(m_cur_groupno)); +#endif } /** No descriptions */ diff --git a/kkbswitch/kbswitchapp.h b/kkbswitch/kbswitchapp.h index b730252..ccebdf6 100644 --- a/kkbswitch/kbswitchapp.h +++ b/kkbswitch/kbswitchapp.h @@ -110,8 +110,10 @@ private: // Private methods private slots: // Private slots /** No descriptions */ void slotGroupSelected(int groupno); - /** No descriptions */ + /** Select the next keyboard layout (wraps around) */ void slotSelectNextGroup(); + /** Select the previous keyboard layout (wraps around) */ + void slotSelectPrevGroup(); /** No descriptions */ void slotPreferences(); /** No descriptions */ -- cgit v1.2.3