1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
Index: kicker/applets/systemtray/systemtrayapplet.cpp
===================================================================
--- kicker/applets/systemtray/systemtrayapplet.cpp.orig
+++ kicker/applets/systemtray/systemtrayapplet.cpp
@@ -187,6 +187,7 @@ bool SystemTrayApplet::x11Event( XEvent
if( isWinManaged( (WId)e->xclient.data.l[2] ) ) // we already manage it
return true;
embedWindow( e->xclient.data.l[2], false );
+ updateVisibleWins();
layoutTray();
return true;
}
@@ -213,13 +214,12 @@ void SystemTrayApplet::preferences()
connect(m_settingsDialog, SIGNAL(finished()), this, SLOT(settingsDialogFinished()));
m_iconSelector = new KActionSelector(m_settingsDialog);
- m_iconSelector->setAvailableLabel(i18n("Visible icons:"));
- m_iconSelector->setSelectedLabel(i18n("Hidden icons:"));
- m_iconSelector->setShowUpDownButtons(false);
+ m_iconSelector->setAvailableLabel(i18n("Hidden icons:"));
+ m_iconSelector->setSelectedLabel(i18n("Visible icons:"));
m_settingsDialog->setMainWidget(m_iconSelector);
- QListBox *shownListBox = m_iconSelector->availableListBox();
- QListBox *hiddenListBox = m_iconSelector->selectedListBox();
+ QListBox *hiddenListBox = m_iconSelector->availableListBox();
+ QListBox *shownListBox = m_iconSelector->selectedListBox();
TrayEmbedList::const_iterator it = m_shownWins.begin();
TrayEmbedList::const_iterator itEnd = m_shownWins.end();
@@ -261,26 +261,48 @@ void SystemTrayApplet::applySettings()
}
KConfig *conf = config();
- conf->setGroup("HiddenTrayIcons");
- QString name;
- // use the following snippet of code someday to implement ordering
- // of icons
- /*
- m_visibleIconList.clear();
- QListBoxItem* item = m_iconSelector->availableListBox()->firstItem();
- for (; item; item = item->next())
+ // Save the sort order and hidden status using the window class (WM_CLASS) rather
+ // than window name (caption) - window name is i18n-ed, so it's for example
+ // not possible to create default settings.
+ // For backwards compatibility, name is kept as it is, class is preceded by '!'.
+ QMap< QString, QString > windowNameToClass;
+ for( TrayEmbedList::ConstIterator it = m_shownWins.begin();
+ it != m_shownWins.end();
+ ++it ) {
+ KWin::WindowInfo info = KWin::windowInfo( (*it)->embeddedWinId(), NET::WMName, NET::WM2WindowClass);
+ windowNameToClass[ info.name() ] = '!' + info.windowClassClass();
+ }
+ for( TrayEmbedList::ConstIterator it = m_hiddenWins.begin();
+ it != m_hiddenWins.end();
+ ++it ) {
+ KWin::WindowInfo info = KWin::windowInfo( (*it)->embeddedWinId(), NET::WMName, NET::WM2WindowClass);
+ windowNameToClass[ info.name() ] = '!' + info.windowClassClass();
+ }
+
+ conf->setGroup("SortedTrayIcons");
+ m_sortOrderIconList.clear();
+ for(QListBoxItem* item = m_iconSelector->selectedListBox()->firstItem();
+ item;
+ item = item->next())
{
- m_visibleIconList.append(item->text());
+ if( windowNameToClass.contains(item->text()))
+ m_sortOrderIconList.append(windowNameToClass[item->text()]);
+ else
+ m_sortOrderIconList.append(item->text());
}
- conf->writeEntry("Visible", m_visibleIconList);
- selection.clear();*/
+ conf->writeEntry("SortOrder", m_sortOrderIconList);
+ conf->setGroup("HiddenTrayIcons");
m_hiddenIconList.clear();
- QListBoxItem* item = m_iconSelector->selectedListBox()->firstItem();
- for (; item; item = item->next())
+ for(QListBoxItem* item = m_iconSelector->availableListBox()->firstItem();
+ item;
+ item = item->next())
{
- m_hiddenIconList.append(item->text());
+ if( windowNameToClass.contains(item->text()))
+ m_hiddenIconList.append(windowNameToClass[item->text()]);
+ else
+ m_hiddenIconList.append(item->text());
}
conf->writeEntry("Hidden", m_hiddenIconList);
conf->sync();
@@ -416,6 +438,9 @@ void SystemTrayApplet::loadSettings()
conf->setGroup("HiddenTrayIcons");
m_hiddenIconList = conf->readListEntry("Hidden");
+ conf->setGroup("SortedTrayIcons");
+ m_sortOrderIconList = conf->readListEntry("SortOrder");
+
//Note This setting comes from kdeglobal.
conf->setGroup("System Tray");
m_iconSize = conf->readNumEntry("systrayIconWidth", 22);
@@ -505,7 +530,9 @@ bool SystemTrayApplet::isWinManaged(WId
bool SystemTrayApplet::shouldHide(WId w)
{
- return m_hiddenIconList.find(KWin::windowInfo(w).name()) != m_hiddenIconList.end();
+ return m_hiddenIconList.find(KWin::windowInfo(w).name()) != m_hiddenIconList.end()
+ || m_hiddenIconList.find('!'+KWin::windowInfo(w,0,NET::WM2WindowClass).windowClassClass())
+ != m_hiddenIconList.end();
}
void SystemTrayApplet::updateVisibleWins()
@@ -529,6 +556,35 @@ void SystemTrayApplet::updateVisibleWins
(*emb)->hide();
}
}
+
+ QMap< QXEmbed*, QString > names; // cache window names and classes
+ QMap< QXEmbed*, QString > classes;
+ for( TrayEmbedList::const_iterator it = m_shownWins.begin();
+ it != m_shownWins.end();
+ ++it ) {
+ KWin::WindowInfo info = KWin::windowInfo((*it)->embeddedWinId(),NET::WMName,NET::WM2WindowClass);
+ names[ *it ] = info.name();
+ classes[ *it ] = '!'+info.windowClassClass();
+ }
+ TrayEmbedList newList;
+ for( QStringList::const_iterator it1 = m_sortOrderIconList.begin();
+ it1 != m_sortOrderIconList.end();
+ ++it1 ) {
+ for( TrayEmbedList::iterator it2 = m_shownWins.begin();
+ it2 != m_shownWins.end();
+ ) {
+ if( (*it1).startsWith("!") ? classes[ *it2 ] == *it1 : names[ *it2 ] == *it1 ) {
+ newList.append( *it2 ); // don't bail out, there may be multiple ones
+ it2 = m_shownWins.erase( it2 );
+ } else
+ ++it2;
+ }
+ }
+ for( TrayEmbedList::const_iterator it = m_shownWins.begin();
+ it != m_shownWins.end();
+ ++it )
+ newList.append( *it ); // append unsorted items
+ m_shownWins = newList;
}
void SystemTrayApplet::toggleExpanded()
Index: kicker/applets/systemtray/systemtrayapplet.h
===================================================================
--- kicker/applets/systemtray/systemtrayapplet.h.orig
+++ kicker/applets/systemtray/systemtrayapplet.h
@@ -97,6 +97,7 @@ private:
TrayEmbedList m_shownWins;
TrayEmbedList m_hiddenWins;
QStringList m_hiddenIconList;
+ QStringList m_sortOrderIconList;
KWinModule *kwin_module;
Atom net_system_tray_selection;
Atom net_system_tray_opcode;
|