1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
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.
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.
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
*********************************************************************/
23
#include <QtCore/QRect>
24
#include <QtGui/QX11Info>
25
#include <QtGui/QPainter>
31
: m_initialized(false)
38
XDestroyWindow(QX11Info::display(), m_leftOutline);
39
XDestroyWindow(QX11Info::display(), m_rightOutline);
40
XDestroyWindow(QX11Info::display(), m_topOutline);
41
XDestroyWindow(QX11Info::display(), m_bottomOutline);
47
if (effects && static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::Outline)) {
48
static_cast<EffectsHandlerImpl*>(effects)->slotShowOutline(m_outlineGeometry);
49
return; // done by effect
56
if (effects && static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::Outline)) {
57
static_cast<EffectsHandlerImpl*>(effects)->slotHideOutline();
58
return; // done by effect
63
void Outline::show(const QRect& outlineGeometry)
65
setGeometry(outlineGeometry);
69
void Outline::setGeometry(const QRect& outlineGeometry)
71
m_outlineGeometry = outlineGeometry;
74
QVector< Window > Outline::windowIds() const
76
QVector<Window> windows;
79
windows << m_leftOutline << m_topOutline << m_rightOutline << m_bottomOutline;
84
void Outline::showWithX()
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);
100
int defaultDepth = XDefaultDepth(QX11Info::display(), QX11Info::appScreen());
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);
108
Pixmap xpix = XCreatePixmap(display(), rootWindow(), 5,
109
m_outlineGeometry.height() - 10, defaultDepth);
110
QPixmap pix = QPixmap::fromX11Pixmap(xpix, QPixmap::ExplicitlyShared);
113
p.drawLine(0, 0, 0, pix.height() - 1);
114
p.drawLine(4, 0, 4, pix.height() - 1);
116
p.drawLine(1, 0, 1, pix.height() - 1);
117
p.drawLine(3, 0, 3, pix.height() - 1);
119
p.drawLine(2, 0, 2, pix.height() - 1);
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);
127
Pixmap xpix = XCreatePixmap(display(), rootWindow(), m_outlineGeometry.width(),
129
QPixmap pix = QPixmap::fromX11Pixmap(xpix, QPixmap::ExplicitlyShared);
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);
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);
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);
148
XSetWindowBackgroundPixmap(QX11Info::display(), m_topOutline, pix.handle());
149
// According to the XSetWindowBackgroundPixmap documentation the pixmap can be freed.
150
XFreePixmap (display(), xpix);
153
Pixmap xpix = XCreatePixmap(display(), rootWindow(), m_outlineGeometry.width(),
155
QPixmap pix = QPixmap::fromX11Pixmap(xpix, QPixmap::ExplicitlyShared);
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);
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);
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);
174
XSetWindowBackgroundPixmap(QX11Info::display(), m_bottomOutline, pix.handle());
175
// According to the XSetWindowBackgroundPixmap documentation the pixmap can be freed.
176
XFreePixmap (display(), xpix);
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);
188
void Outline::hideWithX()
190
XUnmapWindow(QX11Info::display(), m_leftOutline);
191
XUnmapWindow(QX11Info::display(), m_rightOutline);
192
XUnmapWindow(QX11Info::display(), m_topOutline);
193
XUnmapWindow(QX11Info::display(), m_bottomOutline);