Skip to content

Commit 107fb79

Browse files
author
Simon Hofmann
committed
(#17) Refactored window_manager code on Linux to properly use existing XGetMainDisplay code
1 parent 95d50c4 commit 107fb79

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/linux/window_manager.cc

+6-10
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ extern "C" {
88
WindowHandle getActiveWindow() {
99
Display* xServer = XGetMainDisplay();
1010
Window window;
11-
if (xServer != nullptr) {
11+
if (xServer != NULL) {
1212
int32_t revertToWindow;
1313
XGetInputFocus(xServer, &window, &revertToWindow);
14-
XCloseMainDisplay();
1514
return window;
1615
}
1716
return -1;
@@ -20,7 +19,7 @@ WindowHandle getActiveWindow() {
2019
std::vector<WindowHandle> getWindows() {
2120
Display* xServer = XGetMainDisplay();
2221
std::vector<WindowHandle> windowHandles;
23-
if (xServer != nullptr) {
22+
if (xServer != NULL) {
2423
Window defaultRootWindow = DefaultRootWindow(xServer);
2524
Window rootWindow;
2625
Window parentWindow;
@@ -33,37 +32,34 @@ std::vector<WindowHandle> getWindows() {
3332
windowHandles.push_back(windowList[idx]);
3433
}
3534
}
36-
XCloseMainDisplay();
3735
}
3836
return windowHandles;
3937
}
4038

4139
std::string getWindowTitle(const WindowHandle windowHandle) {
4240
Display* xServer = XGetMainDisplay();
4341
std::string windowName = "";
44-
if (xServer != nullptr) {
42+
if (xServer != NULL) {
4543
XTextProperty windowTextProperty;
4644
Status getWMNameResult = XGetWMName(xServer, windowHandle, &windowTextProperty);
4745
if (getWMNameResult > 0) {
4846
windowName = std::string(reinterpret_cast<const char*>(windowTextProperty.value));
4947
}
50-
XCloseMainDisplay();
5148
}
52-
return windowName;
49+
return windowName;
5350
}
5451

5552
MMRect getWindowRect(const WindowHandle windowHandle) {
5653
Display* xServer = XGetMainDisplay();
5754
MMRect windowRect = MMRectMake(0, 0, 0, 0);
58-
if (xServer != nullptr) {
55+
if (xServer != NULL) {
5956
Window rootWindow;
6057
int32_t x, y;
6158
uint32_t width, height, border_width, border_height;
6259
Status getXGeometryResult = XGetGeometry(xServer, windowHandle, &rootWindow, &x, &y, &width, &height, &border_width, &border_height);
6360
if (getXGeometryResult > 0) {
6461
windowRect = MMRectMake(x, y, width, height);
6562
}
66-
XCloseMainDisplay();
6763
}
6864
return windowRect;
69-
}
65+
}

0 commit comments

Comments
 (0)