~ubuntu-branches/ubuntu/wily/kwin/wily-proposed

« back to all changes in this revision

Viewing changes to abstract_client.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-08-10 23:16:37 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20150810231637-5zb2tstjkez93hml
Tags: 4:5.3.95-0ubuntu1
new upstream beta release

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) 2015 Martin Gräßlin <mgraesslin@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
#include "abstract_client.h"
 
21
#include "decorations/decorationpalette.h"
 
22
#include "focuschain.h"
 
23
#include "screens.h"
 
24
#ifdef KWIN_BUILD_TABBOX
 
25
#include "tabbox.h"
 
26
#endif
 
27
#include "tabgroup.h"
 
28
#include "workspace.h"
 
29
 
 
30
#if HAVE_WAYLAND
 
31
#include "wayland_server.h"
 
32
#include <KWayland/Server/plasmawindowmanagement_interface.h>
 
33
#endif
 
34
 
 
35
namespace KWin
 
36
{
 
37
 
 
38
QHash<QString, std::weak_ptr<Decoration::DecorationPalette>> AbstractClient::s_palettes;
 
39
std::shared_ptr<Decoration::DecorationPalette> AbstractClient::s_defaultPalette;
 
40
 
 
41
AbstractClient::AbstractClient()
 
42
    : Toplevel()
 
43
#ifdef KWIN_BUILD_TABBOX
 
44
    , m_tabBoxClient(QSharedPointer<TabBox::TabBoxClientImpl>(new TabBox::TabBoxClientImpl(this)))
 
45
#endif
 
46
    , m_colorScheme(QStringLiteral("kdeglobals"))
 
47
{
 
48
}
 
49
 
 
50
AbstractClient::~AbstractClient() = default;
 
51
 
 
52
void AbstractClient::updateMouseGrab()
 
53
{
 
54
}
 
55
 
 
56
bool AbstractClient::belongToSameApplication(const AbstractClient *c1, const AbstractClient *c2, bool active_hack)
 
57
{
 
58
    return c1->belongsToSameApplication(c2, active_hack);
 
59
}
 
60
 
 
61
bool AbstractClient::isTransient() const
 
62
{
 
63
    return false;
 
64
}
 
65
 
 
66
TabGroup *AbstractClient::tabGroup() const
 
67
{
 
68
    return nullptr;
 
69
}
 
70
 
 
71
bool AbstractClient::untab(const QRect &toGeometry, bool clientRemoved)
 
72
{
 
73
    Q_UNUSED(toGeometry)
 
74
    Q_UNUSED(clientRemoved)
 
75
    return false;
 
76
}
 
77
 
 
78
bool AbstractClient::isCurrentTab() const
 
79
{
 
80
    return true;
 
81
}
 
82
 
 
83
void AbstractClient::growHorizontal()
 
84
{
 
85
}
 
86
 
 
87
void AbstractClient::growVertical()
 
88
{
 
89
}
 
90
 
 
91
void AbstractClient::shrinkHorizontal()
 
92
{
 
93
}
 
94
 
 
95
void AbstractClient::shrinkVertical()
 
96
{
 
97
}
 
98
 
 
99
void AbstractClient::packTo(int left, int top)
 
100
{
 
101
    Q_UNUSED(left)
 
102
    Q_UNUSED(top)
 
103
}
 
104
 
 
105
xcb_timestamp_t AbstractClient::userTime() const
 
106
{
 
107
    return XCB_TIME_CURRENT_TIME;
 
108
}
 
109
 
 
110
void AbstractClient::setSkipSwitcher(bool set)
 
111
{
 
112
    set = rules()->checkSkipSwitcher(set);
 
113
    if (set == skipSwitcher())
 
114
        return;
 
115
    m_skipSwitcher = set;
 
116
    updateWindowRules(Rules::SkipSwitcher);
 
117
    emit skipSwitcherChanged();
 
118
}
 
119
 
 
120
void AbstractClient::setSkipPager(bool b)
 
121
{
 
122
    b = rules()->checkSkipPager(b);
 
123
    if (b == skipPager())
 
124
        return;
 
125
    m_skipPager = b;
 
126
    doSetSkipPager();
 
127
    info->setState(b ? NET::SkipPager : NET::States(0), NET::SkipPager);
 
128
    updateWindowRules(Rules::SkipPager);
 
129
    emit skipPagerChanged();
 
130
}
 
131
 
 
132
void AbstractClient::doSetSkipPager()
 
133
{
 
134
}
 
135
 
 
136
void AbstractClient::setSkipTaskbar(bool b)
 
137
{
 
138
    int was_wants_tab_focus = wantsTabFocus();
 
139
    if (b == skipTaskbar())
 
140
        return;
 
141
    m_skipTaskbar = b;
 
142
    doSetSkipTaskbar();
 
143
    updateWindowRules(Rules::SkipTaskbar);
 
144
    if (was_wants_tab_focus != wantsTabFocus()) {
 
145
        FocusChain::self()->update(this, isActive() ? FocusChain::MakeFirst : FocusChain::Update);
 
146
    }
 
147
    emit skipTaskbarChanged();
 
148
}
 
149
 
 
150
void AbstractClient::setOriginalSkipTaskbar(bool b)
 
151
{
 
152
    m_originalSkipTaskbar = rules()->checkSkipTaskbar(b);
 
153
    setSkipTaskbar(m_originalSkipTaskbar);
 
154
}
 
155
 
 
156
void AbstractClient::doSetSkipTaskbar()
 
157
{
 
158
 
 
159
}
 
160
 
 
161
void AbstractClient::setIcon(const QIcon &icon)
 
162
{
 
163
    m_icon = icon;
 
164
    emit iconChanged();
 
165
}
 
166
 
 
167
void AbstractClient::setActive(bool act)
 
168
{
 
169
    if (m_active == act) {
 
170
        return;
 
171
    }
 
172
    m_active = act;
 
173
    const int ruledOpacity = m_active
 
174
                             ? rules()->checkOpacityActive(qRound(opacity() * 100.0))
 
175
                             : rules()->checkOpacityInactive(qRound(opacity() * 100.0));
 
176
    setOpacity(ruledOpacity / 100.0);
 
177
    workspace()->setActiveClient(act ? this : NULL);
 
178
 
 
179
    if (!m_active)
 
180
        cancelAutoRaise();
 
181
 
 
182
    if (!m_active && shadeMode() == ShadeActivated)
 
183
        setShade(ShadeNormal);
 
184
 
 
185
    doSetActive();
 
186
    emit activeChanged();
 
187
    updateMouseGrab();
 
188
}
 
189
 
 
190
void AbstractClient::doSetActive()
 
191
{
 
192
}
 
193
 
 
194
void AbstractClient::updateLayer()
 
195
{
 
196
}
 
197
 
 
198
void AbstractClient::setKeepAbove(bool b)
 
199
{
 
200
    b = rules()->checkKeepAbove(b);
 
201
    if (b && !rules()->checkKeepBelow(false))
 
202
        setKeepBelow(false);
 
203
    if (b == keepAbove()) {
 
204
        // force hint change if different
 
205
        if (info && bool(info->state() & NET::KeepAbove) != keepAbove())
 
206
            info->setState(keepAbove() ? NET::KeepAbove : NET::States(0), NET::KeepAbove);
 
207
        return;
 
208
    }
 
209
    m_keepAbove = b;
 
210
    if (info) {
 
211
        info->setState(keepAbove() ? NET::KeepAbove : NET::States(0), NET::KeepAbove);
 
212
    }
 
213
    workspace()->updateClientLayer(this);
 
214
    updateWindowRules(Rules::Above);
 
215
 
 
216
    doSetKeepAbove();
 
217
    emit keepAboveChanged(m_keepAbove);
 
218
}
 
219
 
 
220
void AbstractClient::doSetKeepAbove()
 
221
{
 
222
}
 
223
 
 
224
void AbstractClient::setKeepBelow(bool b)
 
225
{
 
226
    b = rules()->checkKeepBelow(b);
 
227
    if (b && !rules()->checkKeepAbove(false))
 
228
        setKeepAbove(false);
 
229
    if (b == keepBelow()) {
 
230
        // force hint change if different
 
231
        if (info && bool(info->state() & NET::KeepBelow) != keepBelow())
 
232
            info->setState(keepBelow() ? NET::KeepBelow : NET::States(0), NET::KeepBelow);
 
233
        return;
 
234
    }
 
235
    m_keepBelow = b;
 
236
    if (info) {
 
237
        info->setState(keepBelow() ? NET::KeepBelow : NET::States(0), NET::KeepBelow);
 
238
    }
 
239
    workspace()->updateClientLayer(this);
 
240
    updateWindowRules(Rules::Below);
 
241
 
 
242
    doSetKeepBelow();
 
243
    emit keepBelowChanged(m_keepBelow);
 
244
}
 
245
 
 
246
void AbstractClient::doSetKeepBelow()
 
247
{
 
248
}
 
249
 
 
250
void AbstractClient::startAutoRaise()
 
251
{
 
252
    delete m_autoRaiseTimer;
 
253
    m_autoRaiseTimer = new QTimer(this);
 
254
    connect(m_autoRaiseTimer, &QTimer::timeout, this, &AbstractClient::autoRaise);
 
255
    m_autoRaiseTimer->setSingleShot(true);
 
256
    m_autoRaiseTimer->start(options->autoRaiseInterval());
 
257
}
 
258
 
 
259
void AbstractClient::cancelAutoRaise()
 
260
{
 
261
    delete m_autoRaiseTimer;
 
262
    m_autoRaiseTimer = nullptr;
 
263
}
 
264
 
 
265
void AbstractClient::autoRaise()
 
266
{
 
267
    workspace()->raiseClient(this);
 
268
    cancelAutoRaise();
 
269
}
 
270
 
 
271
bool AbstractClient::wantsTabFocus() const
 
272
{
 
273
    return (isNormalWindow() || isDialog()) && wantsInput();
 
274
}
 
275
 
 
276
bool AbstractClient::isSpecialWindow() const
 
277
{
 
278
    // TODO
 
279
    return isDesktop() || isDock() || isSplash() || isToolbar() || isNotification() || isOnScreenDisplay();
 
280
}
 
281
 
 
282
void AbstractClient::demandAttention(bool set)
 
283
{
 
284
    if (isActive())
 
285
        set = false;
 
286
    if (m_demandsAttention == set)
 
287
        return;
 
288
    m_demandsAttention = set;
 
289
    if (info) {
 
290
        info->setState(set ? NET::DemandsAttention : NET::States(0), NET::DemandsAttention);
 
291
    }
 
292
    workspace()->clientAttentionChanged(this, set);
 
293
    emit demandsAttentionChanged();
 
294
}
 
295
 
 
296
void AbstractClient::setDesktop(int desktop)
 
297
{
 
298
    const int numberOfDesktops = VirtualDesktopManager::self()->count();
 
299
    if (desktop != NET::OnAllDesktops)   // Do range check
 
300
        desktop = qMax(1, qMin(numberOfDesktops, desktop));
 
301
    desktop = qMin(numberOfDesktops, rules()->checkDesktop(desktop));
 
302
    if (m_desktop == desktop)
 
303
        return;
 
304
 
 
305
    int was_desk = m_desktop;
 
306
    const bool wasOnCurrentDesktop = isOnCurrentDesktop();
 
307
    m_desktop = desktop;
 
308
 
 
309
    doSetDesktop(desktop, was_desk);
 
310
 
 
311
    FocusChain::self()->update(this, FocusChain::MakeFirst);
 
312
    updateWindowRules(Rules::Desktop);
 
313
 
 
314
    emit desktopChanged();
 
315
    if (wasOnCurrentDesktop != isOnCurrentDesktop())
 
316
        emit desktopPresenceChanged(this, was_desk);
 
317
}
 
318
 
 
319
void AbstractClient::doSetDesktop(int desktop, int was_desk)
 
320
{
 
321
    Q_UNUSED(desktop)
 
322
    Q_UNUSED(was_desk)
 
323
}
 
324
 
 
325
void AbstractClient::setOnAllDesktops(bool b)
 
326
{
 
327
    if ((b && isOnAllDesktops()) ||
 
328
            (!b && !isOnAllDesktops()))
 
329
        return;
 
330
    if (b)
 
331
        setDesktop(NET::OnAllDesktops);
 
332
    else
 
333
        setDesktop(VirtualDesktopManager::self()->current());
 
334
}
 
335
 
 
336
bool AbstractClient::isShadeable() const
 
337
{
 
338
    return false;
 
339
}
 
340
 
 
341
void AbstractClient::setShade(bool set)
 
342
{
 
343
    set ? setShade(ShadeNormal) : setShade(ShadeNone);
 
344
}
 
345
 
 
346
void AbstractClient::setShade(ShadeMode mode)
 
347
{
 
348
    Q_UNUSED(mode)
 
349
}
 
350
 
 
351
ShadeMode AbstractClient::shadeMode() const
 
352
{
 
353
    return ShadeNone;
 
354
}
 
355
 
 
356
AbstractClient::Position AbstractClient::titlebarPosition() const
 
357
{
 
358
    // TODO: still needed, remove?
 
359
    return PositionTop;
 
360
}
 
361
 
 
362
void AbstractClient::setMinimized(bool set)
 
363
{
 
364
    set ? minimize() : unminimize();
 
365
}
 
366
 
 
367
void AbstractClient::minimize(bool avoid_animation)
 
368
{
 
369
    if (!isMinimizable() || isMinimized())
 
370
        return;
 
371
 
 
372
    if (isShade() && info) // NETWM restriction - KWindowInfo::isMinimized() == Hidden && !Shaded
 
373
        info->setState(0, NET::Shaded);
 
374
 
 
375
    m_minimized = true;
 
376
 
 
377
    doMinimize();
 
378
 
 
379
    updateWindowRules(Rules::Minimize);
 
380
    FocusChain::self()->update(this, FocusChain::MakeFirstMinimized);
 
381
    // TODO: merge signal with s_minimized
 
382
    emit clientMinimized(this, !avoid_animation);
 
383
    emit minimizedChanged();
 
384
}
 
385
 
 
386
void AbstractClient::unminimize(bool avoid_animation)
 
387
{
 
388
    if (!isMinimized())
 
389
        return;
 
390
 
 
391
    if (rules()->checkMinimize(false)) {
 
392
        return;
 
393
    }
 
394
 
 
395
    if (isShade() && info) // NETWM restriction - KWindowInfo::isMinimized() == Hidden && !Shaded
 
396
        info->setState(NET::Shaded, NET::Shaded);
 
397
 
 
398
    m_minimized = false;
 
399
 
 
400
    doMinimize();
 
401
 
 
402
    updateWindowRules(Rules::Minimize);
 
403
    emit clientUnminimized(this, !avoid_animation);
 
404
    emit minimizedChanged();
 
405
}
 
406
 
 
407
void AbstractClient::doMinimize()
 
408
{
 
409
}
 
410
 
 
411
QPalette AbstractClient::palette() const
 
412
{
 
413
    if (!m_palette) {
 
414
        return QPalette();
 
415
    }
 
416
    return m_palette->palette();
 
417
}
 
418
 
 
419
const Decoration::DecorationPalette *AbstractClient::decorationPalette() const
 
420
{
 
421
    return m_palette.get();
 
422
}
 
423
 
 
424
void AbstractClient::updateColorScheme(QString path)
 
425
{
 
426
    if (path.isEmpty()) {
 
427
        path = QStringLiteral("kdeglobals");
 
428
    }
 
429
 
 
430
    if (!m_palette || m_colorScheme != path) {
 
431
        m_colorScheme = path;
 
432
 
 
433
        if (m_palette) {
 
434
            disconnect(m_palette.get(), &Decoration::DecorationPalette::changed, this, &AbstractClient::handlePaletteChange);
 
435
        }
 
436
 
 
437
        auto it = s_palettes.find(m_colorScheme);
 
438
 
 
439
        if (it == s_palettes.end() || it->expired()) {
 
440
            m_palette = std::make_shared<Decoration::DecorationPalette>(m_colorScheme);
 
441
            if (m_palette->isValid()) {
 
442
                s_palettes[m_colorScheme] = m_palette;
 
443
            } else {
 
444
                if (!s_defaultPalette) {
 
445
                    s_defaultPalette = std::make_shared<Decoration::DecorationPalette>(QStringLiteral("kdeglobals"));
 
446
                    s_palettes[QStringLiteral("kdeglobals")] = s_defaultPalette;
 
447
                }
 
448
 
 
449
                m_palette = s_defaultPalette;
 
450
            }
 
451
 
 
452
            if (m_colorScheme == QStringLiteral("kdeglobals")) {
 
453
                s_defaultPalette = m_palette;
 
454
            }
 
455
        } else {
 
456
            m_palette = it->lock();
 
457
        }
 
458
 
 
459
        connect(m_palette.get(), &Decoration::DecorationPalette::changed, this, &AbstractClient::handlePaletteChange);
 
460
 
 
461
        emit paletteChanged(palette());
 
462
    }
 
463
}
 
464
 
 
465
void AbstractClient::handlePaletteChange()
 
466
{
 
467
    emit paletteChanged(palette());
 
468
}
 
469
 
 
470
void AbstractClient::keepInArea(QRect area, bool partial)
 
471
{
 
472
    if (partial) {
 
473
        // increase the area so that can have only 100 pixels in the area
 
474
        area.setLeft(qMin(area.left() - width() + 100, area.left()));
 
475
        area.setTop(qMin(area.top() - height() + 100, area.top()));
 
476
        area.setRight(qMax(area.right() + width() - 100, area.right()));
 
477
        area.setBottom(qMax(area.bottom() + height() - 100, area.bottom()));
 
478
    }
 
479
    if (!partial) {
 
480
        // resize to fit into area
 
481
        if (area.width() < width() || area.height() < height())
 
482
            resizeWithChecks(qMin(area.width(), width()), qMin(area.height(), height()));
 
483
    }
 
484
    int tx = x(), ty = y();
 
485
    if (geometry().right() > area.right() && width() <= area.width())
 
486
        tx = area.right() - width() + 1;
 
487
    if (geometry().bottom() > area.bottom() && height() <= area.height())
 
488
        ty = area.bottom() - height() + 1;
 
489
    if (!area.contains(geometry().topLeft())) {
 
490
        if (tx < area.x())
 
491
            tx = area.x();
 
492
        if (ty < area.y())
 
493
            ty = area.y();
 
494
    }
 
495
    if (tx != x() || ty != y())
 
496
        move(tx, ty);
 
497
}
 
498
 
 
499
QSize AbstractClient::maxSize() const
 
500
{
 
501
    return rules()->checkMaxSize(QSize(INT_MAX, INT_MAX));
 
502
}
 
503
 
 
504
QSize AbstractClient::minSize() const
 
505
{
 
506
    return rules()->checkMinSize(QSize(0, 0));
 
507
}
 
508
 
 
509
void AbstractClient::updateMoveResize(const QPointF &currentGlobalCursor)
 
510
{
 
511
    Q_UNUSED(currentGlobalCursor)
 
512
}
 
513
 
 
514
bool AbstractClient::hasStrut() const
 
515
{
 
516
    return false;
 
517
}
 
518
 
 
519
void AbstractClient::setupWindowManagementInterface()
 
520
{
 
521
#if HAVE_WAYLAND
 
522
    if (m_windowManagementInterface) {
 
523
        // already setup
 
524
        return;
 
525
    }
 
526
    if (!waylandServer() || !surface()) {
 
527
        return;
 
528
    }
 
529
    if (!waylandServer()->windowManagement()) {
 
530
        return;
 
531
    }
 
532
    using namespace KWayland::Server;
 
533
    auto w = waylandServer()->windowManagement()->createWindow(this);
 
534
    w->setTitle(caption());
 
535
    w->setVirtualDesktop(isOnAllDesktops() ? 0 : desktop() - 1);
 
536
    w->setActive(isActive());
 
537
    w->setFullscreen(isFullScreen());
 
538
    w->setKeepAbove(keepAbove());
 
539
    w->setKeepBelow(keepBelow());
 
540
    w->setMaximized(maximizeMode() == KWin::MaximizeFull);
 
541
    w->setMinimized(isMinimized());
 
542
    w->setOnAllDesktops(isOnAllDesktops());
 
543
    w->setDemandsAttention(isDemandingAttention());
 
544
    w->setCloseable(isCloseable());
 
545
    w->setMaximizeable(isMaximizable());
 
546
    w->setMinimizeable(isMinimizable());
 
547
    w->setFullscreenable(isFullScreenable());
 
548
    w->setThemedIconName(icon().name().isEmpty() ? QStringLiteral("xorg") : icon().name());
 
549
    w->setAppId(QString::fromUtf8(resourceName()));
 
550
    connect(this, &AbstractClient::captionChanged, w, [w, this] { w->setTitle(caption()); });
 
551
    connect(this, &AbstractClient::desktopChanged, w,
 
552
        [w, this] {
 
553
            if (isOnAllDesktops()) {
 
554
                w->setOnAllDesktops(true);
 
555
                return;
 
556
            }
 
557
            w->setVirtualDesktop(desktop() - 1);
 
558
            w->setOnAllDesktops(false);
 
559
        }
 
560
    );
 
561
    connect(this, &AbstractClient::activeChanged, w, [w, this] { w->setActive(isActive()); });
 
562
    connect(this, &AbstractClient::fullScreenChanged, w, [w, this] { w->setFullscreen(isFullScreen()); });
 
563
    connect(this, &AbstractClient::keepAboveChanged, w, &PlasmaWindowInterface::setKeepAbove);
 
564
    connect(this, &AbstractClient::keepBelowChanged, w, &PlasmaWindowInterface::setKeepBelow);
 
565
    connect(this, &AbstractClient::minimizedChanged, w, [w, this] { w->setMinimized(isMinimized()); });
 
566
    connect(this, static_cast<void (AbstractClient::*)(AbstractClient*,MaximizeMode)>(&AbstractClient::clientMaximizedStateChanged), w,
 
567
        [w] (KWin::AbstractClient *c, MaximizeMode mode) {
 
568
            Q_UNUSED(c);
 
569
            w->setMaximized(mode == KWin::MaximizeFull);
 
570
        }
 
571
    );
 
572
    connect(this, &AbstractClient::demandsAttentionChanged, w, [w, this] { w->setDemandsAttention(isDemandingAttention()); });
 
573
    connect(this, &AbstractClient::iconChanged, w,
 
574
        [w, this] {
 
575
            const QIcon i = icon();
 
576
            w->setThemedIconName(i.name().isEmpty() ? QStringLiteral("xorg") : i.name());
 
577
        }
 
578
    );
 
579
    connect(this, &AbstractClient::windowClassChanged, w,
 
580
        [w, this] {
 
581
            w->setAppId(QString::fromUtf8(resourceName()));
 
582
        }
 
583
    );
 
584
    connect(w, &PlasmaWindowInterface::closeRequested, this, [this] { closeWindow(); });
 
585
    connect(w, &PlasmaWindowInterface::virtualDesktopRequested, this,
 
586
        [this] (quint32 desktop) {
 
587
            workspace()->sendClientToDesktop(this, desktop + 1, true);
 
588
        }
 
589
    );
 
590
    connect(w, &PlasmaWindowInterface::fullscreenRequested, this,
 
591
        [this] (bool set) {
 
592
            setFullScreen(set, false);
 
593
        }
 
594
    );
 
595
    connect(w, &PlasmaWindowInterface::minimizedRequested, this,
 
596
        [this] (bool set) {
 
597
            if (set) {
 
598
                minimize();
 
599
            } else {
 
600
                unminimize();
 
601
            }
 
602
        }
 
603
    );
 
604
    connect(w, &PlasmaWindowInterface::maximizedRequested, this,
 
605
        [this] (bool set) {
 
606
            maximize(set ? MaximizeFull : MaximizeRestore);
 
607
        }
 
608
    );
 
609
    connect(w, &PlasmaWindowInterface::keepAboveRequested, this,
 
610
        [this] (bool set) {
 
611
            setKeepAbove(set);
 
612
        }
 
613
    );
 
614
    connect(w, &PlasmaWindowInterface::keepBelowRequested, this,
 
615
        [this] (bool set) {
 
616
            setKeepBelow(set);
 
617
        }
 
618
    );
 
619
    connect(w, &PlasmaWindowInterface::demandsAttentionRequested, this,
 
620
        [this] (bool set) {
 
621
            demandAttention(set);
 
622
        }
 
623
    );
 
624
    connect(w, &PlasmaWindowInterface::activeRequested, this,
 
625
        [this] (bool set) {
 
626
            if (set) {
 
627
                workspace()->activateClient(this, true);
 
628
            }
 
629
        }
 
630
    );
 
631
    m_windowManagementInterface = w;
 
632
#endif
 
633
}
 
634
 
 
635
void AbstractClient::destroyWindowManagementInterface()
 
636
{
 
637
#if HAVE_WAYLAND
 
638
    delete m_windowManagementInterface;
 
639
    m_windowManagementInterface = nullptr;
 
640
#endif
 
641
}
 
642
 
 
643
Options::MouseCommand AbstractClient::getMouseCommand(Qt::MouseButton button, bool *handled) const
 
644
{
 
645
    *handled = false;
 
646
    if (button == Qt::NoButton) {
 
647
        return Options::MouseNothing;
 
648
    }
 
649
    if (isActive()) {
 
650
        if (options->isClickRaise()) {
 
651
            *handled = true;
 
652
            return Options::MouseActivateRaiseAndPassClick;
 
653
        }
 
654
    } else {
 
655
        *handled = true;
 
656
        switch (button) {
 
657
        case Qt::LeftButton:
 
658
            return options->commandWindow1();
 
659
        case Qt::MiddleButton:
 
660
            return options->commandWindow2();
 
661
        case Qt::RightButton:
 
662
            return options->commandWindow3();
 
663
        default:
 
664
            // all other buttons pass Activate & Pass Client
 
665
            return Options::MouseActivateAndPassClick;
 
666
        }
 
667
    }
 
668
    return Options::MouseNothing;
 
669
}
 
670
 
 
671
Options::MouseCommand AbstractClient::getWheelCommand(Qt::Orientation orientation, bool *handled) const
 
672
{
 
673
    *handled = false;
 
674
    if (orientation != Qt::Vertical) {
 
675
        return Options::MouseNothing;
 
676
    }
 
677
    if (!isActive()) {
 
678
        *handled = true;
 
679
        return options->commandWindowWheel();
 
680
    }
 
681
    return Options::MouseNothing;
 
682
}
 
683
 
 
684
bool AbstractClient::performMouseCommand(Options::MouseCommand cmd, const QPoint &globalPos)
 
685
{
 
686
    bool replay = false;
 
687
    switch(cmd) {
 
688
    case Options::MouseRaise:
 
689
        workspace()->raiseClient(this);
 
690
        break;
 
691
    case Options::MouseLower: {
 
692
        workspace()->lowerClient(this);
 
693
        break;
 
694
    }
 
695
    case Options::MouseOperationsMenu:
 
696
        if (isActive() && options->isClickRaise())
 
697
            autoRaise();
 
698
        workspace()->showWindowMenu(QRect(globalPos, globalPos), this);
 
699
        break;
 
700
    case Options::MouseToggleRaiseAndLower:
 
701
        workspace()->raiseOrLowerClient(this);
 
702
        break;
 
703
    case Options::MouseActivateAndRaise: {
 
704
        replay = isActive(); // for clickraise mode
 
705
        bool mustReplay = !rules()->checkAcceptFocus(info->input());
 
706
        if (mustReplay) {
 
707
            ToplevelList::const_iterator  it = workspace()->stackingOrder().constEnd(),
 
708
                                     begin = workspace()->stackingOrder().constBegin();
 
709
            while (mustReplay && --it != begin && *it != this) {
 
710
                AbstractClient *c = qobject_cast<AbstractClient*>(*it);
 
711
                if (!c || (c->keepAbove() && !keepAbove()) || (keepBelow() && !c->keepBelow()))
 
712
                    continue; // can never raise above "it"
 
713
                mustReplay = !(c->isOnCurrentDesktop() && c->isOnCurrentActivity() && c->geometry().intersects(geometry()));
 
714
            }
 
715
        }
 
716
        workspace()->takeActivity(this, Workspace::ActivityFocus | Workspace::ActivityRaise);
 
717
        screens()->setCurrent(globalPos);
 
718
        replay = replay || mustReplay;
 
719
        break;
 
720
    }
 
721
    case Options::MouseActivateAndLower:
 
722
        workspace()->requestFocus(this);
 
723
        workspace()->lowerClient(this);
 
724
        screens()->setCurrent(globalPos);
 
725
        replay = replay || !rules()->checkAcceptFocus(info->input());
 
726
        break;
 
727
    case Options::MouseActivate:
 
728
        replay = isActive(); // for clickraise mode
 
729
        workspace()->takeActivity(this, Workspace::ActivityFocus);
 
730
        screens()->setCurrent(globalPos);
 
731
        replay = replay || !rules()->checkAcceptFocus(info->input());
 
732
        break;
 
733
    case Options::MouseActivateRaiseAndPassClick:
 
734
        workspace()->takeActivity(this, Workspace::ActivityFocus | Workspace::ActivityRaise);
 
735
        screens()->setCurrent(globalPos);
 
736
        replay = true;
 
737
        break;
 
738
    case Options::MouseActivateAndPassClick:
 
739
        workspace()->takeActivity(this, Workspace::ActivityFocus);
 
740
        screens()->setCurrent(globalPos);
 
741
        replay = true;
 
742
        break;
 
743
    case Options::MouseMaximize:
 
744
        maximize(MaximizeFull);
 
745
        break;
 
746
    case Options::MouseRestore:
 
747
        maximize(MaximizeRestore);
 
748
        break;
 
749
    case Options::MouseMinimize:
 
750
        minimize();
 
751
        break;
 
752
    case Options::MouseAbove: {
 
753
        StackingUpdatesBlocker blocker(workspace());
 
754
        if (keepBelow())
 
755
            setKeepBelow(false);
 
756
        else
 
757
            setKeepAbove(true);
 
758
        break;
 
759
    }
 
760
    case Options::MouseBelow: {
 
761
        StackingUpdatesBlocker blocker(workspace());
 
762
        if (keepAbove())
 
763
            setKeepAbove(false);
 
764
        else
 
765
            setKeepBelow(true);
 
766
        break;
 
767
    }
 
768
    case Options::MousePreviousDesktop:
 
769
        workspace()->windowToPreviousDesktop(this);
 
770
        break;
 
771
    case Options::MouseNextDesktop:
 
772
        workspace()->windowToNextDesktop(this);
 
773
        break;
 
774
    case Options::MouseOpacityMore:
 
775
        if (!isDesktop())   // No point in changing the opacity of the desktop
 
776
            setOpacity(qMin(opacity() + 0.1, 1.0));
 
777
        break;
 
778
    case Options::MouseOpacityLess:
 
779
        if (!isDesktop())   // No point in changing the opacity of the desktop
 
780
            setOpacity(qMax(opacity() - 0.1, 0.1));
 
781
        break;
 
782
    case Options::MousePreviousTab:
 
783
        if (tabGroup())
 
784
            tabGroup()->activatePrev();
 
785
    break;
 
786
    case Options::MouseNextTab:
 
787
        if (tabGroup())
 
788
            tabGroup()->activateNext();
 
789
    break;
 
790
    case Options::MouseClose:
 
791
        closeWindow();
 
792
        break;
 
793
    case Options::MouseDragTab:
 
794
    case Options::MouseNothing:
 
795
    default:
 
796
        replay = true;
 
797
        break;
 
798
    }
 
799
    return replay;
 
800
}
 
801
 
 
802
}