From 4e428e11c5858b5a2485af135cbb2fabd8a3522f Mon Sep 17 00:00:00 2001 From: Mavridis Philippe Date: Thu, 1 Jun 2023 12:53:38 +0300 Subject: [PATCH] kxkb: re-add custom TDE switching shortcut This commit fixes issue #342. Signed-off-by: Mavridis Philippe (cherry picked from commit 22bb398b3ba83142bf49f6abf47081e5e9e11bef) --- kcontrol/keys/keyconfig.cpp | 2 + kcontrol/keys/main.cpp | 1 + kcontrol/keys/shortcuts.cpp | 1 + kxkb/CMakeL10n.txt | 2 + kxkb/kcmlayout.cpp | 24 ++++++++++- kxkb/kcmlayout.h | 3 ++ kxkb/kcmlayoutwidget.ui | 84 ++++++++++++++++++++++++------------- kxkb/kxkb.cpp | 32 ++++++++++---- kxkb/kxkb.h | 1 + kxkb/kxkbbindings.cpp | 13 ++++++ kxkb/kxkbconfig.cpp | 4 +- kxkb/layoutmap.cpp | 13 ++++++ kxkb/layoutmap.h | 1 + 13 files changed, 139 insertions(+), 42 deletions(-) create mode 100644 kxkb/kxkbbindings.cpp diff --git a/kcontrol/keys/keyconfig.cpp b/kcontrol/keys/keyconfig.cpp index 4ba5951dd..ee39447a1 100644 --- a/kcontrol/keys/keyconfig.cpp +++ b/kcontrol/keys/keyconfig.cpp @@ -66,6 +66,7 @@ void KKeyModule::init( bool isGlobal, bool _bSeriesOnly, bool bSeriesNone ) #include "../../kicker/taskbar/taskbarbindings.cpp" #include "../../kdesktop/kdesktopbindings.cpp" #include "../../klipper/klipperbindings.cpp" +#include "../../kxkb/kxkbbindings.cpp" #undef TDEShortcuts KeyScheme = "Global Key Scheme"; KeySet = "Global Keys"; @@ -488,6 +489,7 @@ void KKeyModule::init() #include "../../kicker/kicker/core/kickerbindings.cpp" #include "../../kicker/taskbar/taskbarbindings.cpp" #include "../../kdesktop/kdesktopbindings.cpp" +#include "../../kxkb/kxkbbindings.cpp" #undef TDEShortcuts kdDebug(125) << "KKeyModule::init() - Read Config Bindings\n"; diff --git a/kcontrol/keys/main.cpp b/kcontrol/keys/main.cpp index 53daa462e..d002b667f 100644 --- a/kcontrol/keys/main.cpp +++ b/kcontrol/keys/main.cpp @@ -190,6 +190,7 @@ extern "C" #include "../../kicker/kicker/core/kickerbindings.cpp" #include "../../kicker/taskbar/taskbarbindings.cpp" #include "../../kdesktop/kdesktopbindings.cpp" +#include "../../kxkb/kxkbbindings.cpp" // Write all the global keys to kdeglobals. // This is needed to be able to check for conflicts with global keys in app's keyconfig diff --git a/kcontrol/keys/shortcuts.cpp b/kcontrol/keys/shortcuts.cpp index e350b1e22..e7f599dda 100644 --- a/kcontrol/keys/shortcuts.cpp +++ b/kcontrol/keys/shortcuts.cpp @@ -116,6 +116,7 @@ void ShortcutsModule::initGUI() #include "../../kicker/taskbar/taskbarbindings.cpp" #include "../../kdesktop/kdesktopbindings.cpp" #include "../../klipper/klipperbindings.cpp" +#include "../../kxkb/kxkbbindings.cpp" kdDebug(125) << "B-----------" << endl; m_actionsSequence.init( m_actionsGeneral ); diff --git a/kxkb/CMakeL10n.txt b/kxkb/CMakeL10n.txt index 908f4d080..0238bd7e3 100644 --- a/kxkb/CMakeL10n.txt +++ b/kxkb/CMakeL10n.txt @@ -5,6 +5,7 @@ tde_l10n_create_template( SOURCES kcmlayout.cpp kcmmisc.cpp + kxkbbindings.cpp pixmap.cpp rules.cpp *.ui @@ -15,6 +16,7 @@ tde_l10n_create_template( SOURCES extension.cpp kxkb.cpp + kxkbbindings.cpp kxkbtraywindow.cpp pixmap.cpp rules.cpp diff --git a/kxkb/kcmlayout.cpp b/kxkb/kcmlayout.cpp index a2b5d8e12..9499d8efc 100644 --- a/kxkb/kcmlayout.cpp +++ b/kxkb/kcmlayout.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,7 @@ #include #include #include +#include #include #include @@ -168,9 +170,14 @@ LayoutConfig::LayoutConfig(TQWidget *parent, const char *name) //Read rules - we _must_ read _before_ creating xkb-options comboboxes loadRules(); - makeOptionsTab(); + // Load global shortcuts +#define NOSLOTS + keys = new TDEGlobalAccel(TQT_TQOBJECT(this)); +#include "kxkbbindings.cpp" + makeOptionsTab(); load(); + makeShortcutsTab(); } @@ -184,6 +191,8 @@ void LayoutConfig::load() { m_kxkbConfig.load(KxkbConfig::LOAD_ALL); + keys->readSettings(); + initUI(); } @@ -419,6 +428,10 @@ void LayoutConfig::save() m_forceGrpOverwrite = false; } + // Save and apply global shortcuts + m_keyChooser->commitChanges(); + keys->writeSettings(0, true); + // Get current layout from Kxkb if (!kapp->dcopClient()->isAttached()) kapp->dcopClient()->attach(); @@ -715,6 +728,13 @@ TQWidget* LayoutConfig::makeOptionsTab() return listView; } +TQWidget* LayoutConfig::makeShortcutsTab() { + m_keyChooser = new KKeyChooser(keys, widget->tabShortcuts, false, false); + connect(m_keyChooser, SIGNAL(keyChange()), this, SLOT(changed())); + widget->tabShortcuts->layout()->add(m_keyChooser); + return m_keyChooser; +} + void LayoutConfig::updateOptionsCommand() { TQString setxkbmap; @@ -1064,7 +1084,7 @@ void LayoutConfig::hotkeyComboChanged() { } if (widget->comboHotkey->currentItem() == other) { - widget->tabWidget->setCurrentPage(3); + widget->tabWidget->setCurrentPage(4); widget->listOptions->ensureItemVisible(grpItem); widget->listOptions->setFocus(); } diff --git a/kxkb/kcmlayout.h b/kxkb/kcmlayout.h index cfb748c10..23a1e0791 100644 --- a/kxkb/kcmlayout.h +++ b/kxkb/kcmlayout.h @@ -58,8 +58,11 @@ private: KxkbConfig m_kxkbConfig; TQDict m_optionGroups; bool m_forceGrpOverwrite; + KKeyChooser *m_keyChooser; + TDEGlobalAccel *keys; TQWidget* makeOptionsTab(); + TQWidget* makeShortcutsTab(); void updateStickyLimit(); static LayoutUnit getLayoutUnitKey(TQListViewItem *sel); void checkConflicts(OptionListItem *current, TQStringList conflicting, diff --git a/kxkb/kcmlayoutwidget.ui b/kxkb/kcmlayoutwidget.ui index aab21c2cf..c35df0921 100644 --- a/kxkb/kcmlayoutwidget.ui +++ b/kxkb/kcmlayoutwidget.ui @@ -76,7 +76,7 @@ unnamed - + textLabel1_4 @@ -92,33 +92,6 @@ Active layouts: - - - labelHotkey - - - Key combination to &switch layout: - - - comboHotkey - - - - - comboHotkey - - - - 7 - 0 - 0 - 0 - - - - Here you can choose the key combination you want to use to switch to the next layout. This list includes only the most common variants. If you choose "Other...", then you will be redirected to the "Options" tab where you can pick from all the available variants. Note that if you have selected Append Mode in the Xkb Options tab this option is not available; you have to use the Xkb Options tab instead. - - labelModel @@ -282,7 +255,7 @@ editCmdLine - + @@ -423,6 +396,59 @@ + + + tabShortcuts + + + Keyboard Shortcuts + + + + + labelHotkey + + + <qt><b>Key combination to switch layout (X11):</b></qt> + + + comboHotkey + + + + + comboHotkey + + + + 7 + 0 + 0 + 0 + + + + Here you can choose the key combination you want to use to switch to the next layout. This list includes only the most common variants. If you choose "Other...", then you will be redirected to the "Options" tab where you can pick from all the available variants. Note that if you have selected Append Mode in the Xkb Options tab this option is not available; you have to use the Xkb Options tab instead. + + + + + switchingGrpSeparator + + + + + labelHotkey + + + <qt><b>TDE shortcuts to switch layout:</b></qt> + + + comboHotkey + + + + tab diff --git a/kxkb/kxkb.cpp b/kxkb/kxkb.cpp index 0764aff41..4bc5bdbd7 100644 --- a/kxkb/kxkb.cpp +++ b/kxkb/kxkb.cpp @@ -74,6 +74,10 @@ KXKBApp::KXKBApp(bool allowStyles, bool GUIenabled) m_layoutOwnerMap = new LayoutMap(kxkbConfig); + // keep in sync with kcmlayout.cpp + keys = new TDEGlobalAccel(TQT_TQOBJECT(this)); +#include "kxkbbindings.cpp" + connect( this, TQT_SIGNAL(settingsChanged(int)), TQT_SLOT(slotSettingsChanged(int)) ); addKipcEventMask( KIPC::SettingsChanged ); } @@ -81,11 +85,12 @@ KXKBApp::KXKBApp(bool allowStyles, bool GUIenabled) KXKBApp::~KXKBApp() { - delete m_tray; - delete m_rules; - delete m_extension; + delete m_tray; + delete m_rules; + delete m_extension; delete m_layoutOwnerMap; delete kWinModule; + delete keys; } int KXKBApp::newInstance() @@ -151,6 +156,8 @@ bool KXKBApp::settingsRead() initTray(); TDEGlobal::config()->reparseConfiguration(); // kcontrol modified kdeglobals + keys->readSettings(); + keys->updateConnections(); return true; } @@ -235,6 +242,13 @@ void KXKBApp::nextLayout() setLayout(layout); } +void KXKBApp::prevLayout() +{ + const LayoutUnit& layout = m_layoutOwnerMap->getPrevLayout().layoutUnit; + setLayout(layout); +} + + void KXKBApp::menuActivated(int id) { if( KxkbLabelController::START_MENU_ID <= id @@ -297,10 +311,11 @@ void KXKBApp::windowChanged(WId winId) void KXKBApp::slotSettingsChanged(int category) { - if ( category != TDEApplication::SETTINGS_SHORTCUTS) - return; - - TDEGlobal::config()->reparseConfiguration(); // kcontrol modified kdeglobals + if (category == TDEApplication::SETTINGS_SHORTCUTS) { + TDEGlobal::config()->reparseConfiguration(); // kcontrol modified kdeglobals + keys->readSettings(); + keys->updateConnections(); + } } bool KXKBApp::x11EventFilter(XEvent *e) { @@ -309,8 +324,7 @@ bool KXKBApp::x11EventFilter(XEvent *e) { return TDEApplication::x11EventFilter(e); } -const char * DESCRIPTION = - I18N_NOOP("A utility to switch keyboard maps"); +const char *DESCRIPTION = I18N_NOOP("A utility to switch keyboard maps"); extern "C" KDE_EXPORT int kdemain(int argc, char *argv[]) { diff --git a/kxkb/kxkb.h b/kxkb/kxkb.h index 06c45d834..5a54babdb 100644 --- a/kxkb/kxkb.h +++ b/kxkb/kxkb.h @@ -67,6 +67,7 @@ k_dcop: public slots: void nextLayout(); + void prevLayout(); protected slots: void menuActivated(int id); diff --git a/kxkb/kxkbbindings.cpp b/kxkb/kxkbbindings.cpp new file mode 100644 index 000000000..f4a0fb5c3 --- /dev/null +++ b/kxkb/kxkbbindings.cpp @@ -0,0 +1,13 @@ +#ifndef NOSLOTS +# define DEF( name, key3, key4, fnSlot ) \ + keys->insert( name, i18n(name), TQString(), key3, key4, TQT_TQOBJECT(this), TQT_SLOT(fnSlot) ) +#else +# define DEF( name, key3, key4, fnSlot ) \ + keys->insert( name, i18n(name), TQString(), key3, key4, 0, 0 ) +#endif + + keys->insert( "Program:kxkb", i18n("Keyboard") ); + DEF( I18N_NOOP("Switch to Next Keyboard Layout"), TDEShortcut(), TDEShortcut(), nextLayout() ); + DEF( I18N_NOOP("Switch to Previous Keyboard Layout"), TDEShortcut(), TDEShortcut(), prevLayout() ); + +#undef DEF \ No newline at end of file diff --git a/kxkb/kxkbconfig.cpp b/kxkb/kxkbconfig.cpp index b1b428fa9..52ba6941b 100644 --- a/kxkb/kxkbconfig.cpp +++ b/kxkb/kxkbconfig.cpp @@ -36,7 +36,7 @@ bool KxkbConfig::load(int loadMode) config->setGroup("Layout"); if( loadMode == LOAD_ALL ) { - m_resetOldOptions = config->readBoolEntry("ResetOldOptions", false); + m_resetOldOptions = config->readBoolEntry("ResetOldOptions", true); m_options = config->readEntry("Options", ""); } @@ -205,7 +205,7 @@ void KxkbConfig::setDefaults() { m_model = DEFAULT_MODEL; - m_resetOldOptions = false; + m_resetOldOptions = true; m_options = ""; m_layouts.clear(); diff --git a/kxkb/layoutmap.cpp b/kxkb/layoutmap.cpp index 636911199..62b44da10 100644 --- a/kxkb/layoutmap.cpp +++ b/kxkb/layoutmap.cpp @@ -93,6 +93,19 @@ LayoutState& LayoutMap::getNextLayout() { return *layoutQueue.head(); } +LayoutState& LayoutMap::getPrevLayout() { + LayoutQueue& layoutQueue = getCurrentLayoutQueue(m_currentWinId); + for (int i = 1; i < layoutQueue.count(); ++i) { + LayoutState* layoutState = layoutQueue.dequeue(); + layoutQueue.enqueue(layoutState); + } + + kdDebug() << "map: Next layout: " << layoutQueue.head()->layoutUnit.toPair() + << " for " << m_currentWinId << endl; + + return *layoutQueue.head(); +} + void LayoutMap::setCurrentLayout(const LayoutUnit& layoutUnit) { LayoutQueue& layoutQueue = getCurrentLayoutQueue(m_currentWinId); kdDebug() << "map: Storing layout: " << layoutUnit.toPair() diff --git a/kxkb/layoutmap.h b/kxkb/layoutmap.h index 38e6251ad..812814fff 100644 --- a/kxkb/layoutmap.h +++ b/kxkb/layoutmap.h @@ -48,6 +48,7 @@ public: void setCurrentLayout(const LayoutUnit& layoutUnit); LayoutState& getNextLayout(); + LayoutState& getPrevLayout(); LayoutState& getCurrentLayout(); void setCurrentWindow(WId winId);