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

« back to all changes in this revision

Viewing changes to kwin/bridge.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
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
 
6
 
 
7
This program is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*********************************************************************/
 
20
 
 
21
#include "bridge.h"
 
22
 
 
23
#include "client.h"
 
24
#include "options.h"
 
25
 
 
26
#include <kconfiggroup.h>
 
27
 
 
28
namespace KWin
 
29
{
 
30
 
 
31
Bridge::Bridge(Client* cl)
 
32
    : c(cl)
 
33
{
 
34
}
 
35
 
 
36
#define BRIDGE_HELPER( rettype, prototype, args1, args2, cst ) \
 
37
    rettype Bridge::prototype ( args1 ) cst \
 
38
    { \
 
39
        return c->prototype( args2 ); \
 
40
    }
 
41
 
 
42
BRIDGE_HELPER(bool, isActive, , , const)
 
43
BRIDGE_HELPER(bool, isCloseable, , , const)
 
44
BRIDGE_HELPER(bool, isMaximizable, , , const)
 
45
BRIDGE_HELPER(Bridge::MaximizeMode, maximizeMode, , , const)
 
46
BRIDGE_HELPER(bool, isMinimizable, , , const)
 
47
BRIDGE_HELPER(bool, providesContextHelp, , , const)
 
48
BRIDGE_HELPER(int, desktop, , , const)
 
49
BRIDGE_HELPER(bool, isModal, , , const)
 
50
BRIDGE_HELPER(bool, isShadeable, , , const)
 
51
BRIDGE_HELPER(bool, isShade, , , const)
 
52
BRIDGE_HELPER(bool, keepAbove, , , const)
 
53
BRIDGE_HELPER(bool, keepBelow, , , const)
 
54
BRIDGE_HELPER(bool, isMovable, , , const)
 
55
BRIDGE_HELPER(bool, isResizable, , , const)
 
56
BRIDGE_HELPER(QString, caption, , , const)
 
57
BRIDGE_HELPER(void, processMousePressEvent, QMouseEvent* e, e,)
 
58
BRIDGE_HELPER(QRect, geometry, , , const)
 
59
BRIDGE_HELPER(void, closeWindow, , ,)
 
60
BRIDGE_HELPER(void, maximize, MaximizeMode m, m,)
 
61
BRIDGE_HELPER(void, minimize, , ,)
 
62
BRIDGE_HELPER(void, showContextHelp, , ,)
 
63
BRIDGE_HELPER(void, setDesktop, int desktop, desktop,)
 
64
 
 
65
void Bridge::setKeepAbove(bool set)
 
66
{
 
67
    if (c->keepAbove() != set)
 
68
        c->workspace()->performWindowOperation(c, KeepAboveOp);
 
69
}
 
70
 
 
71
void Bridge::setKeepBelow(bool set)
 
72
{
 
73
    if (c->keepBelow() != set)
 
74
        c->workspace()->performWindowOperation(c, KeepBelowOp);
 
75
}
 
76
 
 
77
NET::WindowType Bridge::windowType(unsigned long supported_types) const
 
78
{
 
79
    return c->windowType(false, supported_types);
 
80
}
 
81
 
 
82
QIcon Bridge::icon() const
 
83
{
 
84
    QIcon ret(c->icon());
 
85
    ret.addPixmap(c->miniIcon());
 
86
    return ret;
 
87
}
 
88
 
 
89
bool Bridge::isSetShade() const
 
90
{
 
91
    return c->shadeMode() != ShadeNone;
 
92
}
 
93
 
 
94
void Bridge::showWindowMenu(const QPoint &p)
 
95
{
 
96
    c->workspace()->showWindowMenu(p, c);
 
97
}
 
98
 
 
99
void Bridge::showWindowMenu(const QRect &p)
 
100
{
 
101
    c->workspace()->showWindowMenu(p, c);
 
102
}
 
103
 
 
104
void Bridge::performWindowOperation(WindowOperation op)
 
105
{
 
106
    c->workspace()->performWindowOperation(c, op);
 
107
}
 
108
 
 
109
void Bridge::setMask(const QRegion& r, int mode)
 
110
{
 
111
    c->setMask(r, mode);
 
112
}
 
113
 
 
114
bool Bridge::isPreview() const
 
115
{
 
116
    return false;
 
117
}
 
118
 
 
119
QRect Bridge::iconGeometry() const
 
120
{
 
121
    NETRect r = c->info->iconGeometry();
 
122
    return QRect(r.pos.x, r.pos.y, r.size.width, r.size.height);
 
123
}
 
124
 
 
125
WId Bridge::windowId() const
 
126
{
 
127
    return c->window();
 
128
}
 
129
 
 
130
void Bridge::titlebarDblClickOperation()
 
131
{
 
132
    c->workspace()->performWindowOperation(c, options->operationTitlebarDblClick());
 
133
}
 
134
 
 
135
void Bridge::titlebarMouseWheelOperation(int delta)
 
136
{
 
137
    c->performMouseCommand(options->operationTitlebarMouseWheel(delta), cursorPos());
 
138
}
 
139
 
 
140
void Bridge::setShade(bool set)
 
141
{
 
142
    c->setShade(set ? ShadeNormal : ShadeNone);
 
143
}
 
144
 
 
145
int Bridge::currentDesktop() const
 
146
{
 
147
    return c->workspace()->currentDesktop();
 
148
}
 
149
 
 
150
QWidget* Bridge::initialParentWidget() const
 
151
{
 
152
    return NULL;
 
153
}
 
154
 
 
155
Qt::WFlags Bridge::initialWFlags() const
 
156
{
 
157
    return 0;
 
158
}
 
159
 
 
160
QRegion Bridge::unobscuredRegion(const QRegion& r) const
 
161
{
 
162
    QRegion reg(r);
 
163
    const ClientList stacking_order = c->workspace()->stackingOrder();
 
164
    int pos = stacking_order.indexOf(c);
 
165
    ++pos;
 
166
    for (; pos < stacking_order.count(); ++pos) {
 
167
        if (!stacking_order[pos]->isShown(true))
 
168
            continue; // these don't obscure the window
 
169
        if (c->isOnAllDesktops()) {
 
170
            if (!stacking_order[ pos ]->isOnCurrentDesktop())
 
171
                continue;
 
172
        } else {
 
173
            if (!stacking_order[ pos ]->isOnDesktop(c->desktop()))
 
174
                continue;
 
175
        }
 
176
        /* the clients all have their mask-regions in local coords
 
177
           so we have to translate them to a shared coord system
 
178
           we choose ours */
 
179
        int dx = stacking_order[ pos ]->x() - c->x();
 
180
        int dy = stacking_order[ pos ]->y() - c->y();
 
181
        QRegion creg = stacking_order[ pos ]->mask();
 
182
        creg.translate(dx, dy);
 
183
        reg -= creg;
 
184
        if (reg.isEmpty()) {
 
185
            // early out, we are completely obscured
 
186
            break;
 
187
        }
 
188
    }
 
189
    return reg;
 
190
}
 
191
 
 
192
void Bridge::grabXServer(bool grab)
 
193
{
 
194
    if (grab)
 
195
        KWin::grabXServer();
 
196
    else
 
197
        KWin::ungrabXServer();
 
198
}
 
199
 
 
200
bool Bridge::compositingActive() const
 
201
{
 
202
    return c->workspace()->compositingActive();
 
203
}
 
204
 
 
205
QRect Bridge::transparentRect() const
 
206
{
 
207
    return c->transparentRect().translated(-c->decorationRect().topLeft());
 
208
}
 
209
 
 
210
bool Bridge::isClientGroupActive()
 
211
{
 
212
    if (c->clientGroup())
 
213
        return c->clientGroup()->containsActiveClient();
 
214
    return isActive();
 
215
}
 
216
 
 
217
QList< ClientGroupItem > Bridge::clientGroupItems() const
 
218
{
 
219
    if (c->clientGroup())
 
220
        return c->clientGroup()->items();
 
221
    QList< ClientGroupItem > items;
 
222
    QIcon icon(c->icon());
 
223
    icon.addPixmap(c->miniIcon());
 
224
    items.append(ClientGroupItem(c->caption(), icon));
 
225
    return items;
 
226
}
 
227
 
 
228
long Bridge::itemId(int index)
 
229
{
 
230
    if (!c->clientGroup())
 
231
        return 0;
 
232
    const ClientList list = c->clientGroup()->clients();
 
233
    return reinterpret_cast<long>(list.at(index));
 
234
}
 
235
 
 
236
int Bridge::visibleClientGroupItem()
 
237
{
 
238
    if (c->clientGroup())
 
239
        return c->clientGroup()->indexOfVisibleClient();
 
240
    return 0;
 
241
}
 
242
 
 
243
void Bridge::setVisibleClientGroupItem(int index)
 
244
{
 
245
    if (c->clientGroup())
 
246
        c->clientGroup()->setVisible(index);
 
247
}
 
248
 
 
249
void Bridge::moveItemInClientGroup(int index, int before)
 
250
{
 
251
    if (c->clientGroup())
 
252
        c->clientGroup()->move(index, before);
 
253
}
 
254
 
 
255
void Bridge::moveItemToClientGroup(long itemId, int before)
 
256
{
 
257
    Client* item = reinterpret_cast<Client*>(itemId);
 
258
    if (!c->workspace()->hasClient(item)) {
 
259
        kWarning(1212) << "****** ARBITRARY CODE EXECUTION ATTEMPT DETECTED ******";
 
260
        return;
 
261
    }
 
262
    if (item->clientGroup())
 
263
        c->workspace()->moveItemToClientGroup(item->clientGroup(), item->clientGroup()->indexOfClient(item),
 
264
                                              c->clientGroup(), before);
 
265
}
 
266
 
 
267
void Bridge::removeFromClientGroup(int index, const QRect& newGeom)
 
268
{
 
269
    if (c->clientGroup())
 
270
        c->clientGroup()->remove(index, newGeom);
 
271
}
 
272
 
 
273
void Bridge::closeClientGroupItem(int index)
 
274
{
 
275
    if (!c->clientGroup())
 
276
        return;
 
277
    const ClientList list = c->clientGroup()->clients();
 
278
    if (index >= 0 || index <= list.count())
 
279
        list.at(index)->closeWindow();
 
280
}
 
281
 
 
282
void Bridge::closeAllInClientGroup()
 
283
{
 
284
    if (c->clientGroup())
 
285
        c->clientGroup()->closeAll();
 
286
}
 
287
 
 
288
void Bridge::displayClientMenu(int index, const QPoint& pos)
 
289
{
 
290
    if (c->clientGroup())
 
291
        c->clientGroup()->displayClientMenu(index, pos);
 
292
}
 
293
 
 
294
KDecoration::WindowOperation Bridge::buttonToWindowOperation(Qt::MouseButtons button)
 
295
{
 
296
    return c->mouseButtonToWindowOperation(button);
 
297
}
 
298
 
 
299
} // namespace