-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathWindowOverlay_UNIX.cpp
More file actions
107 lines (86 loc) · 2.79 KB
/
Copy pathWindowOverlay_UNIX.cpp
File metadata and controls
107 lines (86 loc) · 2.79 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "hacklib/GfxOverlay_UNIX.h"
#include "hacklib/WindowOverlay.h"
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <stack>
#include <unistd.h>
using namespace hl;
WindowHandle WindowOverlay::GetTargetWindow()
{
auto display = XOpenDisplay(NULL);
auto screen = DefaultScreen(display);
auto root = RootWindow(display, screen);
auto atomPID = XInternAtom(display, "_NET_WM_PID", True);
std::stack<Window> windows;
windows.push(root);
while (!windows.empty())
{
auto hWnd = windows.top();
windows.pop();
Atom type = 0;
int format = 0;
unsigned long numitems = 0;
unsigned long bytesafter = 0;
unsigned char* propPID = nullptr;
auto result = XGetWindowProperty(display, hWnd, atomPID, 0, 1, False, XA_CARDINAL, &type, &format, &numitems,
&bytesafter, &propPID);
if (result == Success && propPID != nullptr)
{
if (*(pid_t*)propPID == getpid())
{
XWindowAttributes attrs = {};
XGetWindowAttributes(display, hWnd, &attrs);
if (attrs.width > 0 && attrs.height > 0 && attrs.c_class == InputOutput &&
attrs.map_state == IsViewable)
{
XFree(propPID);
return hWnd;
}
}
XFree(propPID);
}
Window outRoot = 0;
Window outParent = 0;
Window* outChildren = nullptr;
unsigned int numchildren = 0;
if (XQueryTree(display, hWnd, &outRoot, &outParent, &outChildren, &numchildren))
{
for (unsigned int i = 0; i < numchildren; i++)
{
windows.push(outChildren[i]);
}
}
}
XCloseDisplay(display);
return 0;
}
void WindowOverlay::cbWindowLoop()
{
auto display = m_impl->display;
auto root = RootWindow(display, m_impl->screen);
XWindowChanges changes = {};
unsigned int changeMask = 0;
XWindowAttributes attrs = {};
XGetWindowAttributes(display, m_targetWindow, &attrs);
int absX = 0, absY = 0;
Window child = 0;
XTranslateCoordinates(display, m_targetWindow, root, 0, 0, &absX, &absY, &child);
const int posX = absX - attrs.x;
const int posY = absY - attrs.y;
if (posX != m_posX || posY != m_posY)
{
m_posX = changes.x = posX;
m_posY = changes.y = posY;
changeMask |= CWX | CWY;
}
if (attrs.width != m_width || attrs.height != m_height)
{
m_width = changes.width = attrs.width;
m_height = changes.height = attrs.height;
changeMask |= CWWidth | CWHeight;
}
if (changeMask && m_hWnd)
{
XConfigureWindow(display, m_hWnd, changeMask, &changes);
}
}