summaryrefslogtreecommitdiffstats
path: root/kxkb/kxkbtraywindow.cpp
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2024-10-28 14:40:20 +0200
committerMavridis Philippe <mavridisf@gmail.com>2025-04-03 11:47:21 +0000
commitaed24cdf3fd4615b0ac42fad074f20c0427cc3ac (patch)
tree21f348286454071ffbf35ae475b9b041695a19b5 /kxkb/kxkbtraywindow.cpp
parent1686be58c6c34303f33803db2bc8688e634bf6cd (diff)
downloadtdebase-aed24cdf3fd4615b0ac42fad074f20c0427cc3ac.tar.gz
tdebase-aed24cdf3fd4615b0ac42fad074f20c0427cc3ac.zip
Kxkb: layout switching and UI bugfixes and minor refactoring
* Layout switching - 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. - Reapply Xkb settings when a keyboard device changes state - Do not run setxkbmap without arguments - Catch and process changes to Xkb layouts and options - Always check for Xkb opcode in X11 events, this fixes invalid group issue (Michele Calgaro) * Tray indicator - Do not reload all Kxkb settings every time we are requested to get a pixmap! - Tray indicator pixmap manager improvements - Fix Quit tray icon menu item * Configuration - Optimize settings reloading - Do not reload settings every time getKxkbOptions() is called; if settings actually need to be re-read, it must be done maunally before calling this function - Use pointer to global KxkbConfig instance instead of keeping own copy - Fixed optimized loading of initial settings using KxkbConfig::LOAD_INIT_OPTIONS (I had sort of broken it in the past) - Removed unused KxkbConfig::LOAD_ACTIVE_OPTIONS - `newInstance()` now delegates calling setLayout() to readSettings() - Merged `initTray()` into `readSettings()` - no reason to exist as separate function * Refactoring - Merged KxkbLabelController into KxkbSystemTray - Rename LayoutIcon to LayoutIconManager for clarity - Minor code cleanup in LayoutIconManager - Remove use of singleton pattern for LayoutIconManager - Make XKBExtension a singleton. - Add mutex to XKBExtension to prevent it from processing configuration changes likely caused by KXkb - `XKBExtension::getServerOptions()` now also returns layout and variant information in a XkbOptions struct - New `KxkbConfig::setFromXkbOptions()` member can update current configuration from a XkbOptions struct - No need to use `tdeApp` pointer in KXKBApp (KUniqueApplication) class - Consistent code style and more appropriate function names and return types - Commented option sections for clarity - Removed superfluous debug messages - Add proper copyright header to extension.* * Settings GUI - Make "Transparent background" checkbox available for theme colors in the GUI - Add customization options "Stretch flag", "Dim flag", "Show indicator bevel" - Disable KMilo checkbox when layout notifications disabled - Fix reading settings for TDE layout hotkeys This resolves #547. Signed-off-by: Mavridis Philippe <mavridisf@gmail.com> Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'kxkb/kxkbtraywindow.cpp')
-rw-r--r--kxkb/kxkbtraywindow.cpp124
1 files changed, 58 insertions, 66 deletions
diff --git a/kxkb/kxkbtraywindow.cpp b/kxkb/kxkbtraywindow.cpp
index 2d45922b6..7871f443a 100644
--- a/kxkb/kxkbtraywindow.cpp
+++ b/kxkb/kxkbtraywindow.cpp
@@ -21,105 +21,97 @@
#include "kxkbtraywindow.h"
#include "pixmap.h"
#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(KxkbConfig *kxkbConfig)
+ : KSystemTray(nullptr),
+ m_prevLayoutCount(0)
{
-// kdDebug() << "Creating KxkbLabelController with " << label_ << ", " << contextMenu_ << endl;
-// kdDebug() << "Creating KxkbLabelController with startMenuIndex " << m_menuStartIndex << endl;
+ m_icoMgr = new LayoutIconManager(kxkbConfig);
}
-void KxkbLabelController::setToolTip(const TQString& tip)
+KxkbSystemTray::~KxkbSystemTray()
{
- TQToolTip::remove(label);
- TQToolTip::add(label, tip);
+ delete m_icoMgr;
}
-void KxkbLabelController::setPixmap(const TQPixmap& pixmap)
+void KxkbSystemTray::setToolTip(const TQString& tip)
{
- TDEIconEffect iconeffect;
- label->setPixmap( iconeffect.apply(pixmap, TDEIcon::Panel, TDEIcon::DefaultState) );
+ TQToolTip::remove(this);
+ TQToolTip::add(this, tip);
}
-
-void KxkbLabelController::setCurrentLayout(const LayoutUnit& layoutUnit)
+void KxkbSystemTray::setPixmap(const TQPixmap& pix)
{
- setToolTip(m_descriptionMap[layoutUnit.toPair()]);
- setPixmap( LayoutIcon::getInstance().findPixmap(layoutUnit.layout, PIXMAP_STYLE_INDICATOR, layoutUnit.displayName) );
+ TDEIconEffect iconeffect;
+ KSystemTray::setPixmap(iconeffect.apply(pix, TDEIcon::Panel, TDEIcon::DefaultState));
}
+void KxkbSystemTray::setCurrentLayout(const LayoutUnit& layoutUnit)
+{
+ setToolTip(m_descriptionMap[layoutUnit.toPair()]);
+ setPixmap(m_icoMgr->find(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(m_icoMgr->find(ERROR_CODE, 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;
-
m_descriptionMap.clear();
- for(int ii=0; ii<m_prevLayoutCount; ++ii) {
- menu->removeItem(START_MENU_ID + ii);
- kdDebug() << "remove item: " << START_MENU_ID + ii << endl;
- }
+ 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 = m_icoMgr->find((*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"