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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
/*****************************************************************
Copyright (c) 2001 Matthias Elter <elter@kde.org>
Copyright (c) 2001 John Firebaugh <jfirebaugh@kde.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************/
#include <assert.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include "taskmanager.h"
#if defined(HAVE_XCOMPOSITE) && \
defined(HAVE_XRENDER) && \
defined(HAVE_XFIXES)
#include <fixx11h.h>
#endif
#include "taskrmbmenu.h"
#include "taskrmbmenu.moc"
TaskRMBMenu::TaskRMBMenu(const Task::List& theTasks, bool show, TQPopupMenu* moveMenu, TQWidget *parent, const char *name)
: TQPopupMenu( parent, name )
, tasks( theTasks )
, showAll( show )
, taskMoveMenu( moveMenu )
{
assert(tasks.count() > 0);
if (tasks.count() == 1)
{
fillMenu(tasks.first());
}
else
{
fillMenu();
}
}
TaskRMBMenu::TaskRMBMenu(Task::Ptr task, bool show, TQWidget *parent, const char *name)
: TQPopupMenu( parent, name )
, showAll( show )
, taskMoveMenu( NULL )
{
fillMenu(task);
}
void TaskRMBMenu::fillMenu(Task::Ptr t)
{
int id;
setCheckable(true);
insertItem(i18n("Ad&vanced"), makeAdvancedMenu(t));
bool checkActions = KWin::allowedActionsSupported();
if (TaskManager::the()->numberOfDesktops() > 1)
{
id = insertItem(i18n("To &Desktop"), makeDesktopsMenu(t));
if (showAll)
{
id = insertItem(i18n("&To Current Desktop"),
t, TQT_SLOT(toCurrentDesktop()));
setItemEnabled( id, !t->isOnCurrentDesktop() );
}
if (checkActions)
{
setItemEnabled(id, t->info().actionSupported(NET::ActionChangeDesktop));
}
}
id = insertItem(SmallIconSet("move"), i18n("&Move"), t, TQT_SLOT(move()));
setItemEnabled(id, !checkActions || t->info().actionSupported(NET::ActionMove));
id = insertItem(i18n("Re&size"), t, TQT_SLOT(resize()));
setItemEnabled(id, !checkActions || t->info().actionSupported(NET::ActionResize));
id = insertItem(i18n("Mi&nimize"), t, TQT_SLOT(toggleIconified()));
setItemChecked(id, t->isIconified());
setItemEnabled(id, !checkActions || t->info().actionSupported(NET::ActionMinimize));
id = insertItem(i18n("Ma&ximize"), t, TQT_SLOT(toggleMaximized()));
setItemChecked(id, t->isMaximized());
setItemEnabled(id, !checkActions || t->info().actionSupported(NET::ActionMax));
id = insertItem(i18n("&Shade"), t, TQT_SLOT(toggleShaded()));
setItemChecked(id, t->isShaded());
setItemEnabled(id, !checkActions || t->info().actionSupported(NET::ActionShade));
insertSeparator();
if (taskMoveMenu) {
taskMoveMenu->reparent(this, taskMoveMenu->getWFlags(), taskMoveMenu->geometry().topLeft(), FALSE);
insertItem(i18n("Move Task Button"), taskMoveMenu);
insertSeparator();
}
id = insertItem(SmallIcon("window-close"), i18n("&Close"), t, TQT_SLOT(close()));
setItemEnabled(id, !checkActions || t->info().actionSupported(NET::ActionClose));
}
void TaskRMBMenu::fillMenu()
{
int id;
setCheckable( true );
Task::List::iterator itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
Task::Ptr t = (*it);
id = insertItem( TQIconSet( t->pixmap() ),
t->visibleNameWithState(),
new TaskRMBMenu(t, this) );
setItemChecked( id, t->isActive() );
connectItem( id, t, TQT_SLOT( activateRaiseOrIconify() ) );
}
insertSeparator();
bool enable = false;
if (TaskManager::the()->numberOfDesktops() > 1)
{
id = insertItem(i18n("All to &Desktop"), makeDesktopsMenu());
id = insertItem(i18n("All &to Current Desktop"), this, TQT_SLOT(slotAllToCurrentDesktop()));
Task::List::iterator itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
if (!(*it)->isOnCurrentDesktop())
{
enable = true;
break;
}
}
setItemEnabled(id, enable);
}
enable = false;
id = insertItem( i18n( "Mi&nimize All" ), this, TQT_SLOT( slotMinimizeAll() ) );
itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
if( !(*it)->isIconified() ) {
enable = true;
break;
}
}
setItemEnabled( id, enable );
enable = false;
id = insertItem( i18n( "Ma&ximize All" ), this, TQT_SLOT( slotMaximizeAll() ) );
itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
if( !(*it)->isMaximized() ) {
enable = true;
break;
}
}
setItemEnabled( id, enable );
enable = false;
id = insertItem( i18n( "&Restore All" ), this, TQT_SLOT( slotRestoreAll() ) );
itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
if( (*it)->isIconified() || (*it)->isMaximized() ) {
enable = true;
break;
}
}
setItemEnabled( id, enable );
insertSeparator();
enable = false;
insertItem( SmallIcon( "window-close" ), i18n( "&Close All" ), this, TQT_SLOT( slotCloseAll() ) );
}
TQPopupMenu* TaskRMBMenu::makeAdvancedMenu(Task::Ptr t)
{
int id;
TQPopupMenu* menu = new TQPopupMenu(this);
menu->setCheckable(true);
id = menu->insertItem(SmallIconSet("go-up"),
i18n("Keep &Above Others"),
t, TQT_SLOT(toggleAlwaysOnTop()));
menu->setItemChecked(id, t->isAlwaysOnTop());
id = menu->insertItem(SmallIconSet("go-down"),
i18n("Keep &Below Others"),
t, TQT_SLOT(toggleKeptBelowOthers()));
menu->setItemChecked(id, t->isKeptBelowOthers());
id = menu->insertItem(SmallIconSet("view-fullscreen"),
i18n("&Fullscreen"),
t, TQT_SLOT(toggleFullScreen()));
menu->setItemChecked(id, t->isFullScreen());
if (KWin::allowedActionsSupported())
{
menu->setItemEnabled(id, t->info().actionSupported(NET::ActionFullScreen));
}
return menu;
}
TQPopupMenu* TaskRMBMenu::makeDesktopsMenu(Task::Ptr t)
{
TQPopupMenu* m = new TQPopupMenu( this );
m->setCheckable( true );
int id = m->insertItem( i18n("&All Desktops"), t, TQT_SLOT( toDesktop(int) ) );
m->setItemParameter( id, 0 ); // 0 means all desktops
m->setItemChecked( id, t->isOnAllDesktops() );
m->insertSeparator();
for (int i = 1; i <= TaskManager::the()->numberOfDesktops(); i++) {
TQString name = TQString("&%1 %2").arg(i).arg(TaskManager::the()->desktopName(i).replace('&', "&&"));
id = m->insertItem( name, t, TQT_SLOT( toDesktop(int) ) );
m->setItemParameter( id, i );
m->setItemChecked( id, !t->isOnAllDesktops() && t->desktop() == i );
}
return m;
}
TQPopupMenu* TaskRMBMenu::makeDesktopsMenu()
{
TQPopupMenu* m = new TQPopupMenu( this );
m->setCheckable( true );
int id = m->insertItem( i18n("&All Desktops"), this, TQT_SLOT( slotAllToDesktop(int) ) );
m->setItemParameter( id, 0 ); // 0 means all desktops
m->insertSeparator();
for (int i = 1; i <= TaskManager::the()->numberOfDesktops(); i++) {
TQString name = TQString("&%1 %2").arg(i).arg(TaskManager::the()->desktopName(i).replace('&', "&&"));
id = m->insertItem( name, this, TQT_SLOT( slotAllToDesktop(int) ) );
m->setItemParameter( id, i );
}
return m;
}
void TaskRMBMenu::slotMinimizeAll()
{
Task::List::iterator itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
(*it)->setIconified(true);
}
}
void TaskRMBMenu::slotMaximizeAll()
{
Task::List::iterator itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
(*it)->setMaximized(true);
}
}
void TaskRMBMenu::slotRestoreAll()
{
Task::List::iterator itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
(*it)->restore();
}
}
void TaskRMBMenu::slotShadeAll()
{
Task::List::iterator itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
(*it)->setShaded( !(*it)->isShaded() );
}
}
void TaskRMBMenu::slotCloseAll()
{
Task::List::iterator itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
(*it)->close();
}
}
void TaskRMBMenu::slotAllToDesktop( int desktop )
{
Task::List::iterator itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
(*it)->toDesktop( desktop );
}
}
void TaskRMBMenu::slotAllToCurrentDesktop()
{
Task::List::iterator itEnd = tasks.end();
for (Task::List::iterator it = tasks.begin(); it != itEnd; ++it)
{
(*it)->toCurrentDesktop();
}
}
|