diff options
author | Mavridis Philippe <mavridisf@gmail.com> | 2024-10-28 14:40:20 +0200 |
---|---|---|
committer | Mavridis Philippe <mavridisf@gmail.com> | 2024-11-12 22:29:51 +0200 |
commit | 71068b3b258a340be30a91c3a5af92718da70cdd (patch) | |
tree | 6ba4afb1b1b254f21cef141321a51b5605ba54c4 | |
parent | 1afb78e598cc0d8c320e98c963cb98ab7935435f (diff) | |
download | tdebase-71068b3b258a340be30a91c3a5af92718da70cdd.tar.gz tdebase-71068b3b258a340be30a91c3a5af92718da70cdd.zip |
Kxkb: improve system tray code and fix various switching-related bugs
- Improved layout change logic (indicator is now always updated when the actual switch occurs). This fixes layout switching triggered by the X11 shortcut not being synchronized with layout switching from the tray icon click and the TDE shortcut.
- Kxkb will ignore XkbStateNotify events not related to XkbGroupState which caused strange behaviour with the system tray context menu.
- Merged KxkbLabelController into KxkbSystemTray
This resolves #547.
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-rw-r--r-- | kxkb/eventsrc | 5 | ||||
-rw-r--r-- | kxkb/extension.cpp | 16 | ||||
-rw-r--r-- | kxkb/extension.h | 4 | ||||
-rw-r--r-- | kxkb/kxkb.cpp | 258 | ||||
-rw-r--r-- | kxkb/kxkb.h | 7 | ||||
-rw-r--r-- | kxkb/kxkbtraywindow.cpp | 125 | ||||
-rw-r--r-- | kxkb/kxkbtraywindow.h | 81 |
7 files changed, 222 insertions, 274 deletions
diff --git a/kxkb/eventsrc b/kxkb/eventsrc index ce25f3979..1e06d70c3 100644 --- a/kxkb/eventsrc +++ b/kxkb/eventsrc @@ -5,4 +5,9 @@ Comment=TDE Keyboard Tool [LayoutChange] Name=Keyboard layout switch Comment=The keyboard layout was switched +default_presentation=16 + +[Error] +Name=Keyboard layout switching error +Comment=Error while attempting to switch the keyboard layout default_presentation=16
\ No newline at end of file diff --git a/kxkb/extension.cpp b/kxkb/extension.cpp index 870ee7eb4..ca812b011 100644 --- a/kxkb/extension.cpp +++ b/kxkb/extension.cpp @@ -32,7 +32,7 @@ XKBExtension::XKBExtension(Display *d) if ( d == NULL ) d = tqt_xdisplay(); m_dpy = d; - + // TQStringList dirs = TDEGlobal::dirs()->findDirs ( "tmp", "" ); // m_tempDir = dirs.count() == 0 ? "/tmp/" : dirs[0]; m_tempDir = locateLocal("tmp", ""); @@ -44,7 +44,7 @@ bool XKBExtension::init() int major = XkbMajorVersion; int minor = XkbMinorVersion; - + if (!XkbLibraryVersion(&major, &minor)) { kdError() << "[kxkb-extension] Xlib XKB extension " << major << '.' << minor << @@ -101,7 +101,7 @@ bool XKBExtension::setXkbOptions(const XkbOptions options) p << "-variant"; p << options.variants; } - + if (!options.model.isEmpty()) { p << "-model"; p << options.model; @@ -160,7 +160,7 @@ bool XKBExtension::setGroup(unsigned int group) return XkbLockGroup( m_dpy, XkbUseCoreKbd, group ); } -unsigned int XKBExtension::getGroup() const +uint XKBExtension::getGroup() const { XkbStateRec xkbState; XkbGetState( m_dpy, XkbUseCoreKbd, &xkbState ); @@ -170,9 +170,11 @@ unsigned int XKBExtension::getGroup() const /** Examines an X Event passed to it and takes actions if the event is of * interest to KXkb */ void XKBExtension::processXEvent(XEvent *event) { - XkbEvent* xkb_event = (XkbEvent*)event; - if (xkb_event->any.xkb_type == XkbStateNotify) { - emit groupChanged(xkb_event->state.group); + XkbEvent* xkb_event = (XkbEvent*)event; + if (xkb_event->any.xkb_type == XkbStateNotify && + xkb_event->state.changed & XkbGroupStateMask) + { + emit groupChanged(xkb_event->state.group); } } diff --git a/kxkb/extension.h b/kxkb/extension.h index 9a3d2da8e..091cce582 100644 --- a/kxkb/extension.h +++ b/kxkb/extension.h @@ -17,8 +17,8 @@ public: static bool setXkbOptions(const XkbOptions options); static TQString getServerOptions(); - bool setGroup(unsigned int group); - unsigned int getGroup() const; + bool setGroup(uint group); + uint getGroup() const; void processXEvent(XEvent *ev); private: diff --git a/kxkb/kxkb.cpp b/kxkb/kxkb.cpp index 1d899299f..bbfa4d87e 100644 --- a/kxkb/kxkb.cpp +++ b/kxkb/kxkb.cpp @@ -86,7 +86,6 @@ KXKBApp::KXKBApp(bool allowStyles, bool GUIenabled) addKipcEventMask( KIPC::SettingsChanged ); } - KXKBApp::~KXKBApp() { delete m_tray; @@ -100,9 +99,8 @@ KXKBApp::~KXKBApp() int KXKBApp::newInstance() { if (settingsRead()) { - layoutApply(); + setLayout(m_currentLayout); } - return 0; } @@ -117,9 +115,9 @@ bool KXKBApp::settingsRead() kapp->quit(); return false; } - + m_prevWinId = X11Helper::UNKNOWN_WINDOW_ID; - + if( kxkbConfig.m_switchingPolicy == SWITCH_POLICY_GLOBAL ) { delete kWinModule; kWinModule = NULL; @@ -130,7 +128,7 @@ bool KXKBApp::settingsRead() kdWarning() << "With non-virtual desktop only global switching policy supported on non-primary screens" << endl; //TODO: find out how to handle that } - + if( kWinModule == NULL ) { kWinModule = new KWinModule(0, KWinModule::INFO_DESKTOP); connect(kWinModule, TQ_SIGNAL(activeWindowChanged(WId)), TQ_SLOT(windowChanged(WId))); @@ -138,27 +136,27 @@ bool KXKBApp::settingsRead() m_prevWinId = kWinModule->activeWindow(); kdDebug() << "Active window " << m_prevWinId << endl; } - + m_layoutOwnerMap->reset(); m_layoutOwnerMap->setCurrentWindow( m_prevWinId ); if( m_rules == NULL ) m_rules = new XkbRules(false); - + for(int ii=0; ii<(int)kxkbConfig.m_layouts.count(); ii++) { LayoutUnit& layoutUnit = kxkbConfig.m_layouts[ii]; } - + m_currentLayout = kxkbConfig.m_layouts[0]; kdDebug() << "default layout is " << m_currentLayout.toPair() << endl; - + if( kxkbConfig.m_layouts.count() == 1 && !kxkbConfig.m_showSingle) { kapp->quit(); return false; } initTray(); - + TDEGlobal::config()->reparseConfiguration(); // kcontrol modified kdeglobals keys->readSettings(); keys->updateConnections(); @@ -168,162 +166,164 @@ bool KXKBApp::settingsRead() void KXKBApp::initTray() { - if( !m_tray ) - { - KSystemTray* sysTray = new KxkbSystemTray(); - TDEPopupMenu* popupMenu = sysTray->contextMenu(); - // popupMenu->insertTitle( kapp->miniIcon(), kapp->caption() ); - - m_tray = new KxkbLabelController(sysTray, popupMenu); - 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); - m_tray->initLayoutList(kxkbConfig.m_layouts, *m_rules); - m_tray->setCurrentLayout(m_currentLayout); - m_tray->show(); -} + if (!m_tray) + { + m_tray = new KxkbSystemTray(); + connect(m_tray, TQ_SIGNAL(menuActivated(int)), this, TQ_SLOT(menuActivated(int))); + connect(m_tray, TQ_SIGNAL(toggled()), this, TQ_SLOT(nextLayout())); + } -// This function activates the keyboard layout specified by the -// configuration members (m_currentLayout) -void KXKBApp::layoutApply() -{ - setLayout(m_currentLayout); + m_tray->initLayoutList(kxkbConfig.m_layouts, *m_rules); + m_tray->setCurrentLayout(m_currentLayout); + m_tray->show(); } // kdcop bool KXKBApp::setLayout(const TQString& layoutPair) { - const LayoutUnit layoutUnitKey(layoutPair); - if( kxkbConfig.m_layouts.contains(layoutUnitKey) ) { - return setLayout( *kxkbConfig.m_layouts.find(layoutUnitKey) ); - } - return false; + return setLayout((LayoutUnit)layoutPair); } // Activates the keyboard layout specified by 'layoutUnit' bool KXKBApp::setLayout(const LayoutUnit& 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) { - m_tray->setCurrentLayout(layoutUnit); - } else { - m_tray->setError(layoutUnit.toPair()); - } - } - - return res; + const int group = kxkbConfig.m_layouts.findIndex(layoutUnit); + if (group >= 0) { + return setLayout(group); + } + return false; } + // 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 this group is already set, just show the notification and return + if (m_extension->getGroup() == group) { + if (kxkbConfig.m_enableNotify) { + showLayoutNotification(); + } + return true; + } - if (m_tray) { - if (res) - m_tray->setCurrentLayout(m_currentLayout); - else - m_tray->setError(m_currentLayout.toPair()); - } + bool ok = m_extension->setGroup(group); + if (!ok) { + TQString layout = kxkbConfig.m_layouts[group].toPair(); + if (m_tray) { + m_tray->setError(layout); + } - return res; + if (kxkbConfig.m_enableNotify) { + showErrorNotification(layout); + } + } + return ok; } - void KXKBApp::nextLayout() { - const LayoutUnit& layout = m_layoutOwnerMap->getNextLayout().layoutUnit; - setLayout(layout); + const LayoutUnit& layout = m_layoutOwnerMap->getNextLayout().layoutUnit; + setLayout(layout); } void KXKBApp::prevLayout() { - const LayoutUnit& layout = m_layoutOwnerMap->getPrevLayout().layoutUnit; - setLayout(layout); + const LayoutUnit& layout = m_layoutOwnerMap->getPrevLayout().layoutUnit; + setLayout(layout); } void KXKBApp::menuActivated(int id) { - if( KxkbLabelController::START_MENU_ID <= id - && id < KxkbLabelController::START_MENU_ID + (int)kxkbConfig.m_layouts.count() ) - { - const LayoutUnit& layout = kxkbConfig.m_layouts[id - KxkbLabelController::START_MENU_ID]; - m_layoutOwnerMap->setCurrentLayout( layout ); - setLayout( layout ); - } - else if (id == KxkbLabelController::CONFIG_MENU_ID) + if (id >= KxkbSystemTray::START_MENU_ID && + id < KxkbSystemTray::START_MENU_ID + kxkbConfig.m_layouts.count()) + { + setLayout(id - KxkbSystemTray::START_MENU_ID); + } + else if (id == KxkbSystemTray::CONFIG_MENU_ID) { TDEProcess p; p << "tdecmshell" << "keyboard_layout"; p.start(TDEProcess::DontCare); - } - else if (id == KxkbLabelController::HELP_MENU_ID) - { - TDEApplication::kApplication()->invokeHelp(0, "kxkb"); - } -// else -// { -// quit(); -// } + } + else if (id == KxkbSystemTray::HELP_MENU_ID) + { + TDEApplication::kApplication()->invokeHelp(0, "kxkb"); + } } void KXKBApp::slotGroupChanged(uint group) { - if (group >= kxkbConfig.m_layouts.count()) - { - group = 0; - } - m_currentLayout = kxkbConfig.m_layouts[group]; - m_tray->setCurrentLayout(m_currentLayout); - maybeShowLayoutNotification(); + if (group < 0 || group >= kxkbConfig.m_layouts.count()) { + if (m_tray) { + m_tray->setError(i18n("Unknown")); + } + + if (kxkbConfig.m_enableNotify) { + showErrorNotification(i18n("Unknown")); + } + + return; + } + + m_currentLayout = kxkbConfig.m_layouts[group]; + m_layoutOwnerMap->setCurrentLayout(m_currentLayout); + + if (m_tray) { + m_tray->setCurrentLayout(m_currentLayout); + } + + if (kxkbConfig.m_enableNotify) { + showLayoutNotification(); + } } -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; - } - } - } - } +void KXKBApp::showLayoutNotification() { + bool useKMilo = kxkbConfig.m_notifyUseKMilo && isKMiloAvailable(), + notificationSent = false; - if (useKMilo) { - DCOPRef kmilo("kded", "kmilod"); - if (kmilo.send("displayText(TQString,TQPixmap)", layoutName, kapp->miniIcon())) - notificationSent = true; - } + TQString layoutName(m_rules->getLayoutName(m_currentLayout)); - if (!notificationSent) { - KNotifyClient::event(m_tray->winId(), "LayoutChange", layoutName); - } + 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); + } +} + +void KXKBApp::showErrorNotification(TQString layout) { + bool useKMilo = kxkbConfig.m_notifyUseKMilo && isKMiloAvailable(), + notificationSent = false; + + if (useKMilo) { + DCOPRef kmilo("kded", "kmilod"); + if (kmilo.send("displayText(TQString,TQPixmap)", i18n("Error changing keyboard layout to '%1'").arg(layout), kapp->miniIcon())) { + notificationSent = true; + } + } + + if (!notificationSent) { + KNotifyClient::event(m_tray->winId(), "Error"); + } +} + +bool KXKBApp::isKMiloAvailable() { + 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; + return modules.contains("kmilod"); + } + } + return false; } // TODO: we also have to handle deleted windows @@ -336,18 +336,18 @@ void KXKBApp::windowChanged(WId winId) } kdDebug() << "old WinId: " << m_prevWinId << ", new WinId: " << winId << endl; - + if( m_prevWinId != X11Helper::UNKNOWN_WINDOW_ID ) { // saving layout from previous window // m_layoutOwnerMap->setCurrentWindow(m_prevWinId); m_layoutOwnerMap->setCurrentLayout(m_currentLayout); } - + m_prevWinId = winId; if( winId != X11Helper::UNKNOWN_WINDOW_ID ) { m_layoutOwnerMap->setCurrentWindow(winId); const LayoutState& layoutState = m_layoutOwnerMap->getCurrentLayout(); - + if( layoutState.layoutUnit != m_currentLayout ) { kdDebug() << "switching to " << layoutState.layoutUnit.toPair() << " for " << winId << endl; setLayout(layoutState.layoutUnit); diff --git a/kxkb/kxkb.h b/kxkb/kxkb.h index ddde9a6c4..143b68301 100644 --- a/kxkb/kxkb.h +++ b/kxkb/kxkb.h @@ -72,11 +72,11 @@ public slots: protected slots: void menuActivated(int id); void windowChanged(WId winId); - void layoutApply(); void slotGroupChanged(uint group); void slotSettingsChanged(int category); - void maybeShowLayoutNotification(); + void showLayoutNotification(); + void showErrorNotification(TQString layout); protected: // Read settings, and apply them. @@ -85,6 +85,7 @@ protected: private: void initTray(); bool x11EventFilter(XEvent *e); + bool isKMiloAvailable(); private: KxkbConfig kxkbConfig; @@ -96,7 +97,7 @@ private: XKBExtension *m_extension; XkbRules *m_rules; - KxkbLabelController *m_tray; + KxkbSystemTray *m_tray; TDEGlobalAccel *keys; KWinModule* kWinModule; bool m_forceSetXKBMap; diff --git a/kxkb/kxkbtraywindow.cpp b/kxkb/kxkbtraywindow.cpp index 573b0b4ef..da0c7c0b4 100644 --- a/kxkb/kxkbtraywindow.cpp +++ b/kxkb/kxkbtraywindow.cpp @@ -24,109 +24,90 @@ #include "rules.h" #include "kxkbconfig.h" - -KxkbLabelController::KxkbLabelController(TQLabel* label_, TDEPopupMenu* contextMenu_) : - label(label_), - contextMenu(contextMenu_), - m_menuStartIndex(contextMenu_->count()), - m_prevLayoutCount(0) +KxkbSystemTray::KxkbSystemTray() + : KSystemTray(nullptr), + m_prevLayoutCount(0) { -// kdDebug() << "Creating KxkbLabelController with " << label_ << ", " << contextMenu_ << endl; -// kdDebug() << "Creating KxkbLabelController with startMenuIndex " << m_menuStartIndex << endl; } -void KxkbLabelController::setToolTip(const TQString& tip) +void KxkbSystemTray::setToolTip(const TQString& tip) { - TQToolTip::remove(label); - TQToolTip::add(label, tip); + TQToolTip::remove(this); + TQToolTip::add(this, tip); } -void KxkbLabelController::setPixmap(const TQPixmap& pixmap) +void KxkbSystemTray::setPixmap(const TQPixmap& pix) { - TDEIconEffect iconeffect; - label->setPixmap( iconeffect.apply(pixmap, TDEIcon::Panel, TDEIcon::DefaultState) ); + TDEIconEffect iconeffect; + KSystemTray::setPixmap(iconeffect.apply(pix, TDEIcon::Panel, TDEIcon::DefaultState)); } - -void KxkbLabelController::setCurrentLayout(const LayoutUnit& layoutUnit) +void KxkbSystemTray::setCurrentLayout(const LayoutUnit& layoutUnit) { - setToolTip(m_descriptionMap[layoutUnit.toPair()]); - setPixmap( LayoutIcon::getInstance().findPixmap(layoutUnit.layout, PIXMAP_STYLE_INDICATOR, layoutUnit.displayName) ); + setToolTip(m_descriptionMap[layoutUnit.toPair()]); + setPixmap(LayoutIcon::getInstance().findPixmap(layoutUnit.layout, PIXMAP_STYLE_INDICATOR, layoutUnit.displayName)); } - -void KxkbLabelController::setError(const TQString& layoutInfo) +void KxkbSystemTray::setError(const TQString& layoutInfo) { - TQString msg = i18n("Error changing keyboard layout to '%1'").arg(layoutInfo); - setToolTip(msg); + TQString layout(layoutInfo); + if (layout.isNull()) { + layout = i18n("Unknown"); + } - label->setPixmap(LayoutIcon::getInstance().findPixmap("error", PIXMAP_STYLE_NORMAL)); + TQString msg = i18n("Error changing keyboard layout to '%1'").arg(layoutInfo); + setToolTip(msg); + setPixmap(LayoutIcon::getInstance().findPixmap("error", PIXMAP_STYLE_NORMAL)); } - -void KxkbLabelController::initLayoutList(const TQValueList<LayoutUnit>& layouts, const XkbRules& rules) +void KxkbSystemTray::initLayoutList(const TQValueList<LayoutUnit>& layouts, const XkbRules& rules) { - TDEPopupMenu* menu = contextMenu; -// TQPopupMenu* menu = contextMenu; -// int index = menu->indexOf(0); - m_descriptionMap.clear(); -// menu->clear(); -// menu->insertTitle( kapp->miniIcon(), kapp->caption() ); - for(int ii=0; ii<m_prevLayoutCount; ++ii) { - menu->removeItem(START_MENU_ID + ii); - kdDebug() << "remove item: " << START_MENU_ID + ii << endl; - } -/* menu->removeItem(CONFIG_MENU_ID); - menu->removeItem(HELP_MENU_ID);*/ + int i; + for (i = 0; i < m_prevLayoutCount; ++i) { + contextMenu()->removeItem(START_MENU_ID + i); + } TDEIconEffect iconeffect; - int cnt = 0; + i = 0; TQValueList<LayoutUnit>::ConstIterator it; - for (it=layouts.begin(); it != layouts.end(); ++it) + for (it = layouts.begin(); it != layouts.end(); ++it) { - const TQString layoutName = (*it).layout; - const TQString variantName = (*it).variant; + const TQString layoutName = (*it).layout; + const TQString variantName = (*it).variant; + + const TQPixmap& layoutPixmap = LayoutIcon::getInstance().findPixmap((*it).layout, PIXMAP_STYLE_CONTEXTMENU, (*it).displayName); + const TQPixmap pix = iconeffect.apply(layoutPixmap, TDEIcon::Small, TDEIcon::DefaultState); + + TQString fullName = rules.getLayoutName((*it)); + contextMenu()->insertItem(pix, fullName, START_MENU_ID + i, i + 1); - const TQPixmap& layoutPixmap = LayoutIcon::getInstance().findPixmap( - (*it).layout, PIXMAP_STYLE_CONTEXTMENU, (*it).displayName); - const TQPixmap pix = iconeffect.apply(layoutPixmap, TDEIcon::Small, - TDEIcon::DefaultState); + m_descriptionMap.insert((*it).toPair(), fullName); - TQString fullName = rules.getLayoutName((*it)); - contextMenu->insertItem(pix, fullName, START_MENU_ID + cnt, - m_menuStartIndex + cnt); + ++i; + } + + m_prevLayoutCount = i; - m_descriptionMap.insert((*it).toPair(), fullName); + if (contextMenu()->indexOf(CONFIG_MENU_ID) == -1) { + contextMenu()->insertSeparator(); + contextMenu()->insertItem(SmallIcon("configure"), i18n("Configure..."), CONFIG_MENU_ID); - cnt++; + if (contextMenu()->indexOf(HELP_MENU_ID) == -1) { + contextMenu()->insertItem(SmallIcon("help"), i18n("Help"), HELP_MENU_ID); + } } - m_prevLayoutCount = cnt; - - // if show config, if show help - if( menu->indexOf(CONFIG_MENU_ID) == -1 ) { - contextMenu->insertSeparator(); - contextMenu->insertItem(SmallIcon("configure"), i18n("Configure..."), CONFIG_MENU_ID); - if( menu->indexOf(HELP_MENU_ID) == -1 ) - contextMenu->insertItem(SmallIcon("help"), i18n("Help"), HELP_MENU_ID); - } - -/* if( index != -1 ) { //not first start - menu->insertSeparator(); - TDEAction* quitAction = KStdAction::quit(this, TQ_SIGNAL(quitSelected()), actionCollection()); - if (quitAction) - quitAction->plug(menu); - }*/ + connect(contextMenu(), TQ_SIGNAL(activated(int)), this, TQ_SIGNAL(menuActivated(int))); } -// void KxkbLabelController::mouseReleaseEvent(TQMouseEvent *ev) -// { -// if (ev->button() == TQMouseEvent::LeftButton) -// emit toggled(); -// KSystemTray::mouseReleaseEvent(ev); -// } +void KxkbSystemTray::mouseReleaseEvent(TQMouseEvent *ev) { + if (ev->button() == TQt::LeftButton) { + emit toggled(); + } + KSystemTray::mouseReleaseEvent(ev); +} #include "kxkbtraywindow.moc" diff --git a/kxkb/kxkbtraywindow.h b/kxkb/kxkbtraywindow.h index 46d66c44b..484bae632 100644 --- a/kxkb/kxkbtraywindow.h +++ b/kxkb/kxkbtraywindow.h @@ -1,7 +1,7 @@ // // C++ Interface: kxkbtraywindow // -// Description: +// Description: // // // Author: Andriy Rysin <rysin@kde.org>, (C) 2006 @@ -19,75 +19,34 @@ #include "kxkbconfig.h" - -class TQLabel; -class TDEPopupMenu; class XkbRules; -/* This class is responsible for displaying flag/label for the layout, - catching keyboard/mouse events and displaying menu when selected -*/ - -class KxkbLabelController: public TQObject +class KxkbSystemTray : public KSystemTray { -// TQ_OBJECT - -public: - enum { START_MENU_ID = 100, CONFIG_MENU_ID = 130, HELP_MENU_ID = 131 }; - - KxkbLabelController(TQLabel *label, TDEPopupMenu* contextMenu); + TQ_OBJECT - void initLayoutList(const TQValueList<LayoutUnit>& layouts, const XkbRules& rule); - void setCurrentLayout(const LayoutUnit& layout); -// void setCurrentLayout(const TQString& layout, const TQString &variant); - void setError(const TQString& layoutInfo=""); - void setShowFlag(bool showFlag) { m_showFlag = showFlag; } - void show() { label->show(); } + public: + KxkbSystemTray(); + void initLayoutList(const TQValueList<LayoutUnit>& layouts, const XkbRules& rule); + void setCurrentLayout(const LayoutUnit& layout); + void setError(const TQString& layoutInfo = TQString::null); - WId winId() { return label->winId(); } - -// signals: -// -// void menuActivated(int); -// void toggled(); + enum { START_MENU_ID = 100, CONFIG_MENU_ID = 130, HELP_MENU_ID = 131 }; -// protected: -// -// void mouseReleaseEvent(TQMouseEvent *); - -private: - TQLabel* label; - TDEPopupMenu* contextMenu; - - const int m_menuStartIndex; - bool m_showFlag; - int m_prevLayoutCount; - TQMap<TQString, TQString> m_descriptionMap; - - void setToolTip(const TQString& tip); - void setPixmap(const TQPixmap& pixmap); -}; + protected: + void mouseReleaseEvent(TQMouseEvent *ev); + private slots: + void setToolTip(const TQString& tip); + void setPixmap(const TQPixmap& pix); -class KxkbSystemTray : public KSystemTray -{ - TQ_OBJECT - - public: - KxkbSystemTray(): - KSystemTray(NULL) - {} - - void mouseReleaseEvent(TQMouseEvent *ev) - { - if (ev->button() == TQt::LeftButton) - emit toggled(); - KSystemTray::mouseReleaseEvent(ev); - } + signals: + void menuActivated(int); + void toggled(); - signals: - void menuActivated(int); - void toggled(); + private: + int m_prevLayoutCount; + TQMap<TQString, TQString> m_descriptionMap; }; |