diff options
Diffstat (limited to 'kxkb/kxkb.cpp')
-rw-r--r-- | kxkb/kxkb.cpp | 261 |
1 files changed, 131 insertions, 130 deletions
diff --git a/kxkb/kxkb.cpp b/kxkb/kxkb.cpp index 2db4fb60f..34ed19334 100644 --- a/kxkb/kxkb.cpp +++ b/kxkb/kxkb.cpp @@ -47,6 +47,9 @@ DESCRIPTION #include <tdepopupmenu.h> #include <kdebug.h> #include <tdeconfig.h> +#include <knotifyclient.h> +#include <dcopclient.h> +#include <dcopref.h> #include "x11helper.h" #include "kxkb.h" @@ -63,59 +66,52 @@ KXKBApp::KXKBApp(bool allowStyles, bool GUIenabled) m_prevWinId(X11Helper::UNKNOWN_WINDOW_ID), m_rules(NULL), m_tray(NULL), - kWinModule(NULL), - m_forceSetXKBMap( false ) + kWinModule(NULL) { + X11Helper::initializeTranslations(); m_extension = new XKBExtension(); if( !m_extension->init() ) { kdDebug() << "xkb initialization failed, exiting..." << endl; ::exit(1); } - - // keep in sync with kcmlayout.cpp - keys = new TDEGlobalAccel(TQT_TQOBJECT(this)); -#include "kxkbbindings.cpp" - keys->updateConnections(); + connect(m_extension, TQ_SIGNAL(groupChanged(uint)), this, TQ_SLOT(slotGroupChanged(uint))); m_layoutOwnerMap = new LayoutMap(kxkbConfig); - connect( this, TQT_SIGNAL(settingsChanged(int)), TQT_SLOT(slotSettingsChanged(int)) ); + // keep in sync with kcmlayout.cpp + keys = new TDEGlobalAccel(this); +#include "kxkbbindings.cpp" + + connect( this, TQ_SIGNAL(settingsChanged(int)), TQ_SLOT(slotSettingsChanged(int)) ); addKipcEventMask( KIPC::SettingsChanged ); } KXKBApp::~KXKBApp() { -// deletePrecompiledLayouts(); - - delete keys; - 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() { - m_extension->reset(); - - if( settingsRead() ) - layoutApply(); - + if (settingsRead()) { + layoutApply(); + } + return 0; } bool KXKBApp::settingsRead() { - kxkbConfig.load( KxkbConfig::LOAD_ACTIVE_OPTIONS ); - - if( kxkbConfig.m_enableXkbOptions ) { - kdDebug() << "Setting XKB options " << kxkbConfig.m_options << endl; - if( !m_extension->setXkbOptions(kxkbConfig.m_options, kxkbConfig.m_resetOldOptions) ) { - kdDebug() << "Setting XKB options failed!" << endl; - } - } + XkbOptions options = kxkbConfig.getKXkbOptions(); + if( !m_extension->setXkbOptions(options) ) { + kdDebug() << "Setting XKB options failed!" << endl; + } if ( kxkbConfig.m_useKxkb == false ) { kapp->quit(); @@ -137,7 +133,7 @@ bool KXKBApp::settingsRead() if( kWinModule == NULL ) { kWinModule = new KWinModule(0, KWinModule::INFO_DESKTOP); - connect(kWinModule, TQT_SIGNAL(activeWindowChanged(WId)), TQT_SLOT(windowChanged(WId))); + connect(kWinModule, TQ_SIGNAL(activeWindowChanged(WId)), TQ_SLOT(windowChanged(WId))); } m_prevWinId = kWinModule->activeWindow(); kdDebug() << "Active window " << m_prevWinId << endl; @@ -151,32 +147,15 @@ bool KXKBApp::settingsRead() for(int ii=0; ii<(int)kxkbConfig.m_layouts.count(); ii++) { LayoutUnit& layoutUnit = kxkbConfig.m_layouts[ii]; - layoutUnit.defaultGroup = m_rules->getDefaultGroup(layoutUnit.layout, layoutUnit.includeGroup); - kdDebug() << "default group for " << layoutUnit.toPair() << " is " << layoutUnit.defaultGroup << endl; } - m_currentLayout = kxkbConfig.getDefaultLayout(); - - if( kxkbConfig.m_layouts.count() == 1 ) { - TQString layoutName = m_currentLayout.layout; - TQString variantName = m_currentLayout.variant; - TQString includeName = m_currentLayout.includeGroup; - int group = m_currentLayout.defaultGroup; - - if( !m_extension->setLayout(kxkbConfig.m_model, layoutName, variantName, includeName, false) - || !m_extension->setGroup( group ) ) { - kdDebug() << "Error switching to single layout " << m_currentLayout.toPair() << endl; - // TODO: alert user - } + m_currentLayout = kxkbConfig.m_layouts[0]; + kdDebug() << "default layout is " << m_currentLayout.toPair() << endl; - if( kxkbConfig.m_showSingle == false ) { - kapp->quit(); - return false; - } + if( kxkbConfig.m_layouts.count() == 1 && !kxkbConfig.m_showSingle) { + kapp->quit(); + return false; } - else { -// initPrecompiledLayouts(); - } initTray(); @@ -196,8 +175,8 @@ void KXKBApp::initTray() // popupMenu->insertTitle( kapp->miniIcon(), kapp->caption() ); m_tray = new KxkbLabelController(sysTray, popupMenu); - connect(popupMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(menuActivated(int))); - connect(sysTray, TQT_SIGNAL(toggled()), this, TQT_SLOT(toggled())); + connect(popupMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(menuActivated(int))); + connect(sysTray, TQ_SIGNAL(toggled()), this, TQ_SLOT(nextLayout())); } m_tray->setShowFlag(kxkbConfig.m_showFlag); @@ -223,40 +202,57 @@ bool KXKBApp::setLayout(const TQString& layoutPair) return false; } - // Activates the keyboard layout specified by 'layoutUnit' -bool KXKBApp::setLayout(const LayoutUnit& layoutUnit, int group) +bool KXKBApp::setLayout(const LayoutUnit& layoutUnit) { - bool res = false; - - if( group == -1 ) - group = layoutUnit.defaultGroup; - - res = m_extension->setLayout(kxkbConfig.m_model, - layoutUnit.layout, layoutUnit.variant, - layoutUnit.includeGroup); - if( res ) - m_extension->setGroup(group); // not checking for ret - not important - - if( res ) - m_currentLayout = layoutUnit; + uint group = kxkbConfig.m_layouts.findIndex(layoutUnit); + bool res = m_extension->setGroup(group); + if (res) { + m_currentLayout = layoutUnit; + maybeShowLayoutNotification(); + } - if (m_tray) { - if( res ) + if (m_tray) { + if (res) { m_tray->setCurrentLayout(layoutUnit); - else + } else { m_tray->setError(layoutUnit.toPair()); + } } - return res; + return res; } +// Activates the keyboard layout specified by group number +bool KXKBApp::setLayout(const uint group) +{ + bool res = m_extension->setGroup(group); + if (res) { + m_currentLayout = kxkbConfig.m_layouts[group]; + } + + if (m_tray) { + if (res) + m_tray->setCurrentLayout(m_currentLayout); + else + m_tray->setError(m_currentLayout.toPair()); + } -void KXKBApp::toggled() + return res; +} + + +void KXKBApp::nextLayout() { const LayoutUnit& layout = m_layoutOwnerMap->getNextLayout().layoutUnit; 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 @@ -276,9 +272,57 @@ void KXKBApp::menuActivated(int id) { TDEApplication::kApplication()->invokeHelp(0, "kxkb"); } - else +// else +// { +// quit(); +// } +} + +void KXKBApp::slotGroupChanged(uint group) +{ + if (group >= kxkbConfig.m_layouts.count()) { - quit(); + group = 0; + } + m_currentLayout = kxkbConfig.m_layouts[group]; + m_tray->setCurrentLayout(m_currentLayout); + maybeShowLayoutNotification(); +} + +void KXKBApp::maybeShowLayoutNotification() { + if (!kxkbConfig.m_enableNotify) return; + + TQString layoutName(m_rules->getLayoutName(m_currentLayout)); + bool useKMilo = kxkbConfig.m_notifyUseKMilo; + bool notificationSent = false; + + // Query KDED whether KMiloD is loaded + if (useKMilo) { + QCStringList modules; + TQCString replyType; + TQByteArray replyData; + if (kapp->dcopClient()->call("kded", "kded", "loadedModules()", + TQByteArray(), replyType, replyData)) + { + if (replyType == "QCStringList") { + TQDataStream reply(replyData, IO_ReadOnly); + reply >> modules; + + if (!modules.contains("kmilod")) { + useKMilo = false; + } + } + } + } + + if (useKMilo) { + DCOPRef kmilo("kded", "kmilod"); + if (kmilo.send("displayText(TQString,TQPixmap)", layoutName, kapp->miniIcon())) + notificationSent = true; + } + + if (!notificationSent) { + KNotifyClient::event(m_tray->winId(), "LayoutChange", layoutName); } } @@ -291,15 +335,11 @@ void KXKBApp::windowChanged(WId winId) return; } - int group = m_extension->getGroup(); - kdDebug() << "old WinId: " << m_prevWinId << ", new WinId: " << winId << endl; - if( m_prevWinId != X11Helper::UNKNOWN_WINDOW_ID ) { // saving layout/group from previous window -// kdDebug() << "storing " << m_currentLayout.toPair() << ":" << group << " for " << m_prevWinId << endl; + if( m_prevWinId != X11Helper::UNKNOWN_WINDOW_ID ) { // saving layout from previous window // m_layoutOwnerMap->setCurrentWindow(m_prevWinId); m_layoutOwnerMap->setCurrentLayout(m_currentLayout); - m_layoutOwnerMap->setCurrentGroup(group); } m_prevWinId = winId; @@ -309,11 +349,8 @@ void KXKBApp::windowChanged(WId winId) const LayoutState& layoutState = m_layoutOwnerMap->getCurrentLayout(); if( layoutState.layoutUnit != m_currentLayout ) { - kdDebug() << "switching to " << layoutState.layoutUnit.toPair() << ":" << group << " for " << winId << endl; - setLayout( layoutState.layoutUnit, layoutState.group ); - } - else if( layoutState.group != group ) { // we need to change only the group - m_extension->setGroup(layoutState.group); + kdDebug() << "switching to " << layoutState.layoutUnit.toPair() << " for " << winId << endl; + setLayout(layoutState.layoutUnit); } } } @@ -321,56 +358,20 @@ void KXKBApp::windowChanged(WId winId) void KXKBApp::slotSettingsChanged(int category) { - if ( category != TDEApplication::SETTINGS_SHORTCUTS) - return; - - TDEGlobal::config()->reparseConfiguration(); // kcontrol modified kdeglobals - keys->readSettings(); - keys->updateConnections(); + if (category == TDEApplication::SETTINGS_SHORTCUTS) { + TDEGlobal::config()->reparseConfiguration(); // kcontrol modified kdeglobals + keys->readSettings(); + keys->updateConnections(); + } } -/* - Viki (onscreen keyboard) has problems determining some modifiers states - when kxkb uses precompiled layouts instead of setxkbmap. Probably a bug - in the xkb functions used for the precompiled layouts *shrug*. -*/ -void KXKBApp::forceSetXKBMap( bool set ) -{ - if( m_forceSetXKBMap == set ) - return; - m_forceSetXKBMap = set; - layoutApply(); +bool KXKBApp::x11EventFilter(XEvent *e) { + // let the extension process the event and emit signals if necessary + m_extension->processXEvent(e); + return TDEApplication::x11EventFilter(e); } -/*Precompiles the keyboard layouts for faster activation later. -This is done by loading each one of them and then dumping the compiled -map from the X server into our local buffer.*/ -// void KXKBApp::initPrecompiledLayouts() -// { -// TQStringList dirs = TDEGlobal::dirs()->findDirs ( "tmp", "" ); -// TQString tempDir = dirs.count() == 0 ? "/tmp/" : dirs[0]; -// -// TQValueList<LayoutUnit>::ConstIterator end = kxkbConfig.m_layouts.end(); -// -// for (TQValueList<LayoutUnit>::ConstIterator it = kxkbConfig.m_layouts.begin(); it != end; ++it) -// { -// LayoutUnit layoutUnit(*it); -// // const char* baseGr = m_includes[layout]; -// // int group = m_rules->getGroup(layout, baseGr); -// // if( m_extension->setLayout(m_model, layout, m_variants[layout], group, baseGr) ) { -// TQString compiledLayoutFileName = tempDir + layoutUnit.layout + "." + layoutUnit.variant + ".xkm"; -// // if( m_extension->getCompiledLayout(compiledLayoutFileName) ) -// m_compiledLayoutFileNames[layoutUnit.toPair()] = compiledLayoutFileName; -// // } -// // else { -// // kdDebug() << "Error precompiling layout " << layout << endl; -// // } -// } -// } - - -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[]) { |