~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to libs/taskmanager/task_x11.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 
 
3
Copyright (c) 2000-2001 Matthias Elter <elter@kde.org>
 
4
Copyright (c) 2001 Richard Moore <rich@kde.org>
 
5
 
 
6
Permission is hereby granted, free of charge, to any person obtaining a copy
 
7
of this software and associated documentation files (the "Software"), to deal
 
8
in the Software without restriction, including without limitation the rights
 
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
10
copies of the Software, and to permit persons to whom the Software is
 
11
furnished to do so, subject to the following conditions:
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
19
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
******************************************************************/
 
24
 
 
25
#include "task_p.h"
 
26
 
 
27
#include <QX11Info>
 
28
 
 
29
namespace TaskManager
 
30
{
 
31
 
 
32
bool Task::updateDemandsAttentionState( WId w )
 
33
{
 
34
    const bool empty = d->transientsDemandingAttention.isEmpty();
 
35
    if (window() != w) {
 
36
        // 'w' is a transient for this task
 
37
        NETWinInfo i( QX11Info::display(), w, QX11Info::appRootWindow(), NET::WMState );
 
38
        if (i.state() & NET::DemandsAttention) {
 
39
            if (!d->transientsDemandingAttention.contains(w)) {
 
40
                d->transientsDemandingAttention.insert(w);
 
41
            }
 
42
        } else {
 
43
            d->transientsDemandingAttention.remove(w);
 
44
        }
 
45
    }
 
46
 
 
47
    return empty != d->transientsDemandingAttention.isEmpty();
 
48
}
 
49
 
 
50
void Task::addTransient( WId w, const NETWinInfo& info )
 
51
{
 
52
    d->transients.insert(w);
 
53
    if (info.state() & NET::DemandsAttention) {
 
54
        d->transientsDemandingAttention.insert(w);
 
55
        emit changed(TransientsChanged | StateChanged | AttentionChanged);
 
56
    }
 
57
}
 
58
 
 
59
QString Task::className() const
 
60
{
 
61
    XClassHint hint;
 
62
    if(XGetClassHint(QX11Info::display(), d->win, &hint)) {
 
63
        QString nh( hint.res_name );
 
64
        XFree( hint.res_name );
 
65
        XFree( hint.res_class );
 
66
        return nh;
 
67
    }
 
68
    return QString();
 
69
}
 
70
 
 
71
QString Task::classClass() const
 
72
{
 
73
    XClassHint hint;
 
74
    if(XGetClassHint(QX11Info::display(), d->win, &hint)) {
 
75
        QString ch( hint.res_class );
 
76
        XFree( hint.res_name );
 
77
        XFree( hint.res_class );
 
78
        return ch;
 
79
    }
 
80
    return QString();
 
81
}
 
82
 
 
83
void Task::move()
 
84
{
 
85
    bool on_current = d->info.isOnCurrentDesktop();
 
86
 
 
87
    if (!on_current)
 
88
    {
 
89
        KWindowSystem::setCurrentDesktop(d->info.desktop());
 
90
        KWindowSystem::forceActiveWindow(d->win);
 
91
    }
 
92
 
 
93
    if (d->info.isMinimized())
 
94
    {
 
95
        KWindowSystem::unminimizeWindow(d->win);
 
96
    }
 
97
 
 
98
    QRect geom = d->info.geometry();
 
99
    QCursor::setPos(geom.center());
 
100
 
 
101
    NETRootInfo ri(QX11Info::display(), NET::WMMoveResize);
 
102
    ri.moveResizeRequest(d->win, geom.center().x(),
 
103
                         geom.center().y(), NET::Move);
 
104
}
 
105
 
 
106
void Task::resize()
 
107
{
 
108
    bool on_current = d->info.isOnCurrentDesktop();
 
109
 
 
110
    if (!on_current)
 
111
    {
 
112
        KWindowSystem::setCurrentDesktop(d->info.desktop());
 
113
        KWindowSystem::forceActiveWindow(d->win);
 
114
    }
 
115
 
 
116
    if (d->info.isMinimized())
 
117
    {
 
118
        KWindowSystem::unminimizeWindow(d->win);
 
119
    }
 
120
 
 
121
    QRect geom = d->info.geometry();
 
122
    QCursor::setPos(geom.bottomRight());
 
123
 
 
124
    NETRootInfo ri(QX11Info::display(), NET::WMMoveResize);
 
125
    ri.moveResizeRequest(d->win, geom.bottomRight().x(),
 
126
                         geom.bottomRight().y(), NET::BottomRight);
 
127
}
 
128
 
 
129
void Task::setMaximized(bool maximize)
 
130
{
 
131
    KWindowInfo info = KWindowSystem::windowInfo(d->win, NET::WMState | NET::XAWMState | NET::WMDesktop);
 
132
    bool on_current = info.isOnCurrentDesktop();
 
133
 
 
134
    if (!on_current)
 
135
    {
 
136
        KWindowSystem::setCurrentDesktop(info.desktop());
 
137
    }
 
138
 
 
139
    if (info.isMinimized())
 
140
    {
 
141
        KWindowSystem::unminimizeWindow(d->win);
 
142
    }
 
143
 
 
144
    NETWinInfo ni(QX11Info::display(), d->win, QX11Info::appRootWindow(), NET::WMState);
 
145
 
 
146
    if (maximize)
 
147
    {
 
148
        ni.setState(NET::Max, NET::Max);
 
149
    }
 
150
    else
 
151
    {
 
152
        ni.setState(0, NET::Max);
 
153
    }
 
154
 
 
155
    if (!on_current)
 
156
    {
 
157
        KWindowSystem::forceActiveWindow(d->win);
 
158
    }
 
159
}
 
160
 
 
161
void Task::restore()
 
162
{
 
163
    KWindowInfo info = KWindowSystem::windowInfo(d->win, NET::WMState | NET::XAWMState | NET::WMDesktop);
 
164
    bool on_current = info.isOnCurrentDesktop();
 
165
 
 
166
    if (!on_current)
 
167
    {
 
168
        KWindowSystem::setCurrentDesktop(info.desktop());
 
169
    }
 
170
 
 
171
    if( info.isMinimized())
 
172
    {
 
173
        KWindowSystem::unminimizeWindow(d->win);
 
174
    }
 
175
 
 
176
    NETWinInfo ni(QX11Info::display(), d->win, QX11Info::appRootWindow(), NET::WMState);
 
177
    ni.setState(0, NET::Max);
 
178
 
 
179
    if (!on_current)
 
180
    {
 
181
        KWindowSystem::forceActiveWindow( d->win );
 
182
    }
 
183
}
 
184
 
 
185
void Task::close()
 
186
{
 
187
    NETRootInfo ri( QX11Info::display(), NET::CloseWindow );
 
188
    ri.closeWindowRequest( d->win );
 
189
}
 
190
 
 
191
void Task::toDesktop(int desk)
 
192
{
 
193
    NETWinInfo ni(QX11Info::display(), d->win, QX11Info::appRootWindow(), NET::WMDesktop);
 
194
    if (desk == 0) {
 
195
        if (isOnAllDesktops()) {
 
196
            ni.setDesktop(KWindowSystem::currentDesktop());
 
197
            KWindowSystem::forceActiveWindow(d->win);
 
198
        } else {
 
199
            ni.setDesktop(NETWinInfo::OnAllDesktops);
 
200
        }
 
201
 
 
202
        return;
 
203
    }
 
204
 
 
205
    ni.setDesktop(desk);
 
206
 
 
207
    if (desk == KWindowSystem::currentDesktop()) {
 
208
        KWindowSystem::forceActiveWindow(d->win);
 
209
    }
 
210
}
 
211
 
 
212
void Task::setAlwaysOnTop(bool stay)
 
213
{
 
214
    NETWinInfo ni( QX11Info::display(), d->win, QX11Info::appRootWindow(), NET::WMState);
 
215
    if(stay)
 
216
        ni.setState( NET::StaysOnTop, NET::StaysOnTop );
 
217
    else
 
218
        ni.setState( 0, NET::StaysOnTop );
 
219
}
 
220
 
 
221
void Task::setKeptBelowOthers(bool below)
 
222
{
 
223
    NETWinInfo ni(QX11Info::display(), d->win, QX11Info::appRootWindow(), NET::WMState);
 
224
 
 
225
    if (below)
 
226
    {
 
227
        ni.setState(NET::KeepBelow, NET::KeepBelow);
 
228
    }
 
229
    else
 
230
    {
 
231
        ni.setState(0, NET::KeepBelow);
 
232
    }
 
233
}
 
234
 
 
235
void Task::setFullScreen(bool fullscreen)
 
236
{
 
237
    NETWinInfo ni(QX11Info::display(), d->win, QX11Info::appRootWindow(), NET::WMState);
 
238
 
 
239
    if (fullscreen)
 
240
    {
 
241
        ni.setState(NET::FullScreen, NET::FullScreen);
 
242
    }
 
243
    else
 
244
    {
 
245
        ni.setState(0, NET::FullScreen);
 
246
    }
 
247
}
 
248
 
 
249
void Task::setShaded(bool shade)
 
250
{
 
251
    NETWinInfo ni( QX11Info::display(), d->win, QX11Info::appRootWindow(), NET::WMState);
 
252
    if(shade)
 
253
        ni.setState( NET::Shaded, NET::Shaded );
 
254
    else
 
255
        ni.setState( 0, NET::Shaded );
 
256
}
 
257
 
 
258
void Task::publishIconGeometry(QRect rect)
 
259
{
 
260
    if (rect == d->iconGeometry)
 
261
    {
 
262
        return;
 
263
    }
 
264
 
 
265
    d->iconGeometry = rect;
 
266
    NETWinInfo ni(QX11Info::display(), d->win, QX11Info::appRootWindow(), 0);
 
267
    NETRect r;
 
268
 
 
269
    if (rect.isValid())
 
270
    {
 
271
        r.pos.x = rect.x();
 
272
        r.pos.y = rect.y();
 
273
        r.size.width = rect.width();
 
274
        r.size.height = rect.height();
 
275
    }
 
276
    ni.setIconGeometry(r);
 
277
}
 
278
 
 
279
void Task::refreshActivities()
 
280
{
 
281
    unsigned long properties[] = { 0, NET::WM2Activities };
 
282
    NETWinInfo info(QX11Info::display(), d->win, QX11Info::appRootWindow(), properties, 2);
 
283
    QString result(info.activities());
 
284
    if (result.isEmpty() || result == "ALL") {
 
285
        d->activities.clear();
 
286
    } else {
 
287
        d->activities = result.split(',');
 
288
    }
 
289
}
 
290
 
 
291
} // namespace