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

« back to all changes in this revision

Viewing changes to kwin/outline.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) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
 
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 "outline.h"
 
22
#include "effects.h"
 
23
#include <QtCore/QRect>
 
24
#include <QtGui/QX11Info>
 
25
#include <QtGui/QPainter>
 
26
#include <X11/Xlib.h>
 
27
 
 
28
namespace KWin {
 
29
 
 
30
Outline::Outline()
 
31
    : m_initialized(false)
 
32
{
 
33
}
 
34
 
 
35
Outline::~Outline()
 
36
{
 
37
    if (m_initialized) {
 
38
        XDestroyWindow(QX11Info::display(), m_leftOutline);
 
39
        XDestroyWindow(QX11Info::display(), m_rightOutline);
 
40
        XDestroyWindow(QX11Info::display(), m_topOutline);
 
41
        XDestroyWindow(QX11Info::display(), m_bottomOutline);
 
42
    }
 
43
}
 
44
 
 
45
void Outline::show()
 
46
{
 
47
    if (effects && static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::Outline)) {
 
48
        static_cast<EffectsHandlerImpl*>(effects)->slotShowOutline(m_outlineGeometry);
 
49
        return; // done by effect
 
50
    }
 
51
    showWithX();
 
52
}
 
53
 
 
54
void Outline::hide()
 
55
{
 
56
    if (effects && static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::Outline)) {
 
57
        static_cast<EffectsHandlerImpl*>(effects)->slotHideOutline();
 
58
        return; // done by effect
 
59
    }
 
60
    hideWithX();
 
61
}
 
62
 
 
63
void Outline::show(const QRect& outlineGeometry)
 
64
{
 
65
    setGeometry(outlineGeometry);
 
66
    show();
 
67
}
 
68
 
 
69
void Outline::setGeometry(const QRect& outlineGeometry)
 
70
{
 
71
    m_outlineGeometry = outlineGeometry;
 
72
}
 
73
 
 
74
QVector< Window > Outline::windowIds() const
 
75
{
 
76
    QVector<Window> windows;
 
77
    if (m_initialized) {
 
78
        windows.reserve(4);
 
79
        windows << m_leftOutline << m_topOutline << m_rightOutline << m_bottomOutline;
 
80
    }
 
81
    return windows;
 
82
}
 
83
 
 
84
void Outline::showWithX()
 
85
{
 
86
    if (!m_initialized) {
 
87
        XSetWindowAttributes attr;
 
88
        attr.override_redirect = 1;
 
89
        m_leftOutline = XCreateWindow(QX11Info::display(), QX11Info::appRootWindow(), 0, 0, 1, 1, 0,
 
90
                                      CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect, &attr);
 
91
        m_rightOutline = XCreateWindow(QX11Info::display(), QX11Info::appRootWindow(), 0, 0, 1, 1, 0,
 
92
                                       CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect, &attr);
 
93
        m_topOutline = XCreateWindow(QX11Info::display(), QX11Info::appRootWindow(), 0, 0, 1, 1, 0,
 
94
                                     CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect, &attr);
 
95
        m_bottomOutline = XCreateWindow(QX11Info::display(), QX11Info::appRootWindow(), 0, 0, 1, 1, 0,
 
96
                                        CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect, &attr);
 
97
        m_initialized = true;
 
98
    }
 
99
 
 
100
    int defaultDepth = XDefaultDepth(QX11Info::display(), QX11Info::appScreen());
 
101
 
 
102
// left/right parts are between top/bottom, they don't reach as far as the corners
 
103
    XMoveResizeWindow(QX11Info::display(), m_leftOutline, m_outlineGeometry.x(), m_outlineGeometry.y() + 5, 5, m_outlineGeometry.height() - 10);
 
104
    XMoveResizeWindow(QX11Info::display(), m_rightOutline, m_outlineGeometry.x() + m_outlineGeometry.width() - 5, m_outlineGeometry.y() + 5, 5, m_outlineGeometry.height() - 10);
 
105
    XMoveResizeWindow(QX11Info::display(), m_topOutline, m_outlineGeometry.x(), m_outlineGeometry.y(), m_outlineGeometry.width(), 5);
 
106
    XMoveResizeWindow(QX11Info::display(), m_bottomOutline, m_outlineGeometry.x(), m_outlineGeometry.y() + m_outlineGeometry.height() - 5, m_outlineGeometry.width(), 5);
 
107
    {
 
108
        Pixmap xpix = XCreatePixmap(display(), rootWindow(), 5,
 
109
                                    m_outlineGeometry.height() - 10, defaultDepth);
 
110
        QPixmap pix = QPixmap::fromX11Pixmap(xpix, QPixmap::ExplicitlyShared);
 
111
        QPainter p(&pix);
 
112
        p.setPen(Qt::white);
 
113
        p.drawLine(0, 0, 0, pix.height() - 1);
 
114
        p.drawLine(4, 0, 4, pix.height() - 1);
 
115
        p.setPen(Qt::gray);
 
116
        p.drawLine(1, 0, 1, pix.height() - 1);
 
117
        p.drawLine(3, 0, 3, pix.height() - 1);
 
118
        p.setPen(Qt::black);
 
119
        p.drawLine(2, 0, 2, pix.height() - 1);
 
120
        p.end();
 
121
        XSetWindowBackgroundPixmap(QX11Info::display(), m_leftOutline, pix.handle());
 
122
        XSetWindowBackgroundPixmap(QX11Info::display(), m_rightOutline, pix.handle());
 
123
        // According to the XSetWindowBackgroundPixmap documentation the pixmap can be freed.
 
124
        XFreePixmap (display(), xpix);
 
125
    }
 
126
    {
 
127
        Pixmap xpix = XCreatePixmap(display(), rootWindow(), m_outlineGeometry.width(),
 
128
                                    5, defaultDepth);
 
129
        QPixmap pix = QPixmap::fromX11Pixmap(xpix, QPixmap::ExplicitlyShared);
 
130
        QPainter p(&pix);
 
131
        p.setPen(Qt::white);
 
132
        p.drawLine(0, 0, pix.width() - 1 - 0, 0);
 
133
        p.drawLine(4, 4, pix.width() - 1 - 4, 4);
 
134
        p.drawLine(0, 0, 0, 4);
 
135
        p.drawLine(pix.width() - 1 - 0, 0, pix.width() - 1 - 0, 4);
 
136
        p.setPen(Qt::gray);
 
137
        p.drawLine(1, 1, pix.width() - 1 - 1, 1);
 
138
        p.drawLine(3, 3, pix.width() - 1 - 3, 3);
 
139
        p.drawLine(1, 1, 1, 4);
 
140
        p.drawLine(3, 3, 3, 4);
 
141
        p.drawLine(pix.width() - 1 - 1, 1, pix.width() - 1 - 1, 4);
 
142
        p.drawLine(pix.width() - 1 - 3, 3, pix.width() - 1 - 3, 4);
 
143
        p.setPen(Qt::black);
 
144
        p.drawLine(2, 2, pix.width() - 1 - 2, 2);
 
145
        p.drawLine(2, 2, 2, 4);
 
146
        p.drawLine(pix.width() - 1 - 2, 2, pix.width() - 1 - 2, 4);
 
147
        p.end();
 
148
        XSetWindowBackgroundPixmap(QX11Info::display(), m_topOutline, pix.handle());
 
149
        // According to the XSetWindowBackgroundPixmap documentation the pixmap can be freed.
 
150
        XFreePixmap (display(), xpix);
 
151
    }
 
152
    {
 
153
        Pixmap xpix = XCreatePixmap(display(), rootWindow(), m_outlineGeometry.width(),
 
154
                                    5, defaultDepth);
 
155
        QPixmap pix = QPixmap::fromX11Pixmap(xpix, QPixmap::ExplicitlyShared);
 
156
        QPainter p(&pix);
 
157
        p.setPen(Qt::white);
 
158
        p.drawLine(4, 0, pix.width() - 1 - 4, 0);
 
159
        p.drawLine(0, 4, pix.width() - 1 - 0, 4);
 
160
        p.drawLine(0, 4, 0, 0);
 
161
        p.drawLine(pix.width() - 1 - 0, 4, pix.width() - 1 - 0, 0);
 
162
        p.setPen(Qt::gray);
 
163
        p.drawLine(3, 1, pix.width() - 1 - 3, 1);
 
164
        p.drawLine(1, 3, pix.width() - 1 - 1, 3);
 
165
        p.drawLine(3, 1, 3, 0);
 
166
        p.drawLine(1, 3, 1, 0);
 
167
        p.drawLine(pix.width() - 1 - 3, 1, pix.width() - 1 - 3, 0);
 
168
        p.drawLine(pix.width() - 1 - 1, 3, pix.width() - 1 - 1, 0);
 
169
        p.setPen(Qt::black);
 
170
        p.drawLine(2, 2, pix.width() - 1 - 2, 2);
 
171
        p.drawLine(2, 0, 2, 2);
 
172
        p.drawLine(pix.width() - 1 - 2, 0, pix.width() - 1 - 2, 2);
 
173
        p.end();
 
174
        XSetWindowBackgroundPixmap(QX11Info::display(), m_bottomOutline, pix.handle());
 
175
        // According to the XSetWindowBackgroundPixmap documentation the pixmap can be freed.
 
176
        XFreePixmap (display(), xpix);
 
177
    }
 
178
    XClearWindow(QX11Info::display(), m_leftOutline);
 
179
    XClearWindow(QX11Info::display(), m_rightOutline);
 
180
    XClearWindow(QX11Info::display(), m_topOutline);
 
181
    XClearWindow(QX11Info::display(), m_bottomOutline);
 
182
    XMapWindow(QX11Info::display(), m_leftOutline);
 
183
    XMapWindow(QX11Info::display(), m_rightOutline);
 
184
    XMapWindow(QX11Info::display(), m_topOutline);
 
185
    XMapWindow(QX11Info::display(), m_bottomOutline);
 
186
}
 
187
 
 
188
void Outline::hideWithX()
 
189
{
 
190
    XUnmapWindow(QX11Info::display(), m_leftOutline);
 
191
    XUnmapWindow(QX11Info::display(), m_rightOutline);
 
192
    XUnmapWindow(QX11Info::display(), m_topOutline);
 
193
    XUnmapWindow(QX11Info::display(), m_bottomOutline);
 
194
}
 
195
 
 
196
} // namespace