-
Notifications
You must be signed in to change notification settings - Fork 0
/
phantomwindow.cpp
executable file
·61 lines (46 loc) · 1.64 KB
/
phantomwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Christopher Rabl
// 001051542
#include "phantomwindow.h"
PhantomWindow::PhantomWindow(QWidget *parent) {
setMinimumSize(MIN_WIDTH, MIN_HEIGHT);
// Create transparent window
setStyleSheet("background:transparent;");
setAttribute(Qt::WA_TranslucentBackground);
// Window is always on top
setWindowFlags(Qt::WindowStaysOnTopHint);
// Uncomment this to make it a "Frameless" window
//setWindowFlags(Qt::FramelessWindowHint);
// WARNING: GYPSY MAGIC BELOW! PROCEED WITH CAUTION!
Pixmap mask;
// Create a new X11 pixmap (NOT A QPixmap!) of the entire display area
// that is beneath the current window (which is always on top, although
// not always in focus because of the magic below)
mask = XCreatePixmap(
QX11Info::display(),
winId(),
1, // width
1, // height
1 // depth
);
// Combine the pixmap (which catches the input received in the top-level
// window) with a new pixmap encompassing the bottom layers of windows
XShapeCombineMask(
QX11Info::display(),
winId(),
ShapeInput,
0, // x-offset
0, // y-offset
mask,
ShapeSet
);
// Delete the mask
XFreePixmap(QX11Info::display(), mask);
// Mind... blown. You're welcome.
}
void PhantomWindow::paintEvent(QPaintEvent *event) {
QPainter painter(this);
// This works too, input just goes right through it. Uncomment to see it in action!
painter.setBrush(QBrush(Qt::blue));
painter.setOpacity(0.4);
painter.drawRect(0, 0, QMainWindow::width(), QMainWindow::height());
}