1
1
#include < X11/Xlib.h>
2
+ #include < X11/Xutil.h>
2
3
#include " ../window_manager.h"
3
4
4
5
Display* connectToX () {
@@ -27,32 +28,30 @@ std::vector<WindowHandle> getWindows() {
27
28
28
29
std::string getWindowTitle (const WindowHandle windowHandle) {
29
30
Display* xServer = connectToX ();
31
+ std::string windowName = " " ;
30
32
if (xServer != nullptr ) {
31
- char * windowName = NULL ;
32
- if (XFetchName (xServer, windowHandle, &windowName)) {
33
- std::string wndName = std::string (windowName);
34
- XFree (windowName);
35
- disconnectFromX (xServer);
36
- return wndName;
33
+ XTextProperty windowTextProperty;
34
+ Status getWMNameResult = XGetWMName (xServer, windowHandle, &windowTextProperty);
35
+ if (getWMNameResult > 0 ) {
36
+ windowName = std::string (reinterpret_cast <const char *>(windowTextProperty.value ));
37
37
}
38
38
disconnectFromX (xServer);
39
- return " " ;
40
39
}
41
- return " " ;
40
+ return windowName;
42
41
}
43
42
44
43
MMRect getWindowRect (const WindowHandle windowHandle) {
45
44
Display* xServer = connectToX ();
45
+ MMRect windowRect = MMRectMake (0 , 0 , 0 , 0 );
46
46
if (xServer != nullptr ) {
47
47
Window rootWindow;
48
48
int32_t x, y;
49
49
uint32_t width, height, border_width, border_height;
50
- if ( XGetGeometry (xServer, windowHandle, &rootWindow, &x, &y, &width, &height, &border_width, &border_height)) {
51
- disconnectFromX (xServer);
52
- return MMRectMake (x, y, width, height);
50
+ Status getXGeometryResult = XGetGeometry (xServer, windowHandle, &rootWindow, &x, &y, &width, &height, &border_width, &border_height);
51
+ if (getXGeometryResult > 0 ) {
52
+ windowRect = MMRectMake (x - border_width , y - border_height , width + border_width , height + border_height );
53
53
}
54
54
disconnectFromX (xServer);
55
- return MMRectMake (0 , 0 , 0 , 0 );
56
55
}
57
- return MMRectMake ( 0 , 0 , 0 , 0 ) ;
56
+ return windowRect ;
58
57
}
0 commit comments