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

« back to all changes in this revision

Viewing changes to kwin/effects/_test/test_input.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) 2007 Lubos Lunak <l.lunak@kde.org>
 
6
 
 
7
You can Freely distribute this program under the GNU General Public
 
8
License. See the file "COPYING" for the exact licensing terms.
 
9
******************************************************************/
 
10
 
 
11
/*
 
12
 
 
13
 Testing of handling input in effects. This testing effect moves all windows
 
14
 by 100 pixels down, creates an input window that'll intercept all mouse events
 
15
 and activates the window that's been clicked (click position needs to be
 
16
 transformed). This is useful for effects that present something on the screen
 
17
 and let the user interact with it (e.g. a list of window thumbnails and the
 
18
 user can activate the window by clicking its thumbnail).
 
19
 
 
20
*/
 
21
 
 
22
#include "test_input.h"
 
23
 
 
24
#include <assert.h>
 
25
 
 
26
#include <qcursor.h>
 
27
#include <qevent.h>
 
28
 
 
29
namespace KWin
 
30
{
 
31
 
 
32
KWIN_EFFECT(test_input, TestInputEffect)
 
33
 
 
34
TestInputEffect::TestInputEffect()
 
35
{
 
36
    input = effects->createInputWindow(this, 0, 0, displayWidth(), displayHeight(), Qt::CrossCursor);
 
37
}
 
38
 
 
39
TestInputEffect::~TestInputEffect()
 
40
{
 
41
    effects->destroyInputWindow(input);
 
42
}
 
43
 
 
44
void TestInputEffect::prePaintScreen(ScreenPrePaintData& data, int time)
 
45
{
 
46
    data.mask |= PAINT_SCREEN_TRANSFORMED;
 
47
    effects->prePaintScreen(data, time);
 
48
}
 
49
 
 
50
void TestInputEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
 
51
{
 
52
    data.yTranslate += 100;
 
53
    effects->paintScreen(mask, region, data);
 
54
}
 
55
 
 
56
void TestInputEffect::windowInputMouseEvent(Window w, QEvent* e)
 
57
{
 
58
    assert(w == input);
 
59
    if (e->type() != QEvent::MouseButtonPress)
 
60
        return;
 
61
    QPoint pos = static_cast< QMouseEvent* >(e)->pos();
 
62
    pos -= QPoint(0, 100);   // adjust for transformation
 
63
    foreach (EffectWindow * c, effects->stackingOrder()) {
 
64
        if (/* TODO c->isShown( true ) && */c->isOnCurrentDesktop()
 
65
                                           && c->geometry().contains(pos)) {
 
66
            effects->activateWindow(c);
 
67
            return;
 
68
        }
 
69
    }
 
70
}
 
71
 
 
72
} // namespace