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,32 @@ 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
+ int32_t 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
- Window rootWindow;
48
- int32_t x, y;
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);
47
+ XWindowAttributes windowAttributes;
48
+ int32_t getXGeometryResult = XGetWindowAttributes (xServer, windowHandle, &windowAttributes);
49
+ printf (" Border width: %d" , windowAttributes.border_width );
50
+ if (getXGeometryResult > 0 ) {
51
+ windowRect = MMRectMake (windowAttributes.x - windowAttributes.border_width , \
52
+ windowAttributes.y - windowAttributes.border_width , \
53
+ windowAttributes.width + windowAttributes.border_width , \
54
+ windowAttributes.height + windowAttributes.border_width );
53
55
}
54
56
disconnectFromX (xServer);
55
- return MMRectMake (0 , 0 , 0 , 0 );
56
57
}
57
- return MMRectMake ( 0 , 0 , 0 , 0 ) ;
58
+ return windowRect ;
58
59
}
0 commit comments