From fa1051211bdaf7253c38740ee4aba6a087ffac60 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Mon, 13 Aug 2018 08:53:49 -0400 Subject: [PATCH] Fixed error and update code style --- window/pub.h | 2 +- window/win_sys.h | 10 ++++++---- window/window.h | 18 +++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/window/pub.h b/window/pub.h index 5688eb2..2cf99d2 100644 --- a/window/pub.h +++ b/window/pub.h @@ -276,7 +276,7 @@ typedef struct _Bounds Bounds; if (result != NULL) { if (nItems == 4) { frame.X = (int32) result[0]; - frame.Y = (int32) result[2] + frame.Y = (int32) result[2]; frame.W = (int32) result[0] + (int32) result[1]; frame.H = (int32) result[2] + (int32) result[3]; } diff --git a/window/win_sys.h b/window/win_sys.h index 81889a7..177c9f5 100644 --- a/window/win_sys.h +++ b/window/win_sys.h @@ -49,7 +49,7 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){ MData win; win.XWin = (Window)pid; - Bounds client = GetClient(); + Bounds client = get_client(pid, isHwnd); Bounds frame = GetFrame(win); bounds.X = client.X - frame.X; @@ -91,6 +91,8 @@ Bounds get_client(uintptr pid, uintptr isHwnd){ #elif defined(USE_X11) + Display *rDisplay = XOpenDisplay(NULL); + // Ignore X errors XDismissErrors(); MData win; @@ -103,17 +105,17 @@ Bounds get_client(uintptr pid, uintptr isHwnd){ int32 x = 0, y = 0; // Check if the window is the root - XQueryTree(rDisplay, win, + XQueryTree(rDisplay, win.XWin, &root, &parent, &children, &count); if (children) { XFree(children); } // Retrieve window attributes XWindowAttributes attr = { 0 }; - XGetWindowAttributes(rDisplay, win, &attr); + XGetWindowAttributes(rDisplay, win.XWin, &attr); // Coordinates must be translated if (parent != attr.root){ - XTranslateCoordinates(rDisplay, win, attr.root, attr.x, + XTranslateCoordinates(rDisplay, win.XWin, attr.root, attr.x, attr.y, &x, &y, &parent); } // Coordinates can be left alone diff --git a/window/window.h b/window/window.h index 7ebfc58..60dd530 100644 --- a/window/window.h +++ b/window/window.h @@ -275,7 +275,7 @@ bool IsMinimized(void){ // Ignore X errors // XDismissErrors(); - // return GetState (mData.XWin, STATE_MINIMIZE); + // return GetState(mData.XWin, STATE_MINIMIZE); #elif defined(IS_WINDOWS) @@ -298,7 +298,7 @@ bool IsMaximized(void){ // Ignore X errors // XDismissErrors(); - // return GetState (mData.XWin, STATE_MAXIMIZE); + // return GetState(mData.XWin, STATE_MAXIMIZE); #elif defined(IS_WINDOWS) @@ -447,7 +447,7 @@ MData GetActive(void){ // Get the current active window result.XWin = XDefaultRootWindow(rDisplay); - void* active = GetWindowProperty(result,WM_ACTIVE,NULL); + void* active = GetWindowProperty(result, WM_ACTIVE, NULL); // Check result value if (active != NULL) { @@ -607,8 +607,9 @@ char *GetTitle(){ #elif defined(IS_WINDOWS) - return GetWindowText - (mData.HWnd, mData.Title, 512) > 0 ? mData.Title : ""; + return GetWindowText( + mData.HWnd, mData.Title, 512) > 0 ? + mData.Title : ""; // return GetWindowText // (mData.HWnd, name, 512) > 0 ? // _UTF8Encode(name) : "null"; @@ -624,10 +625,9 @@ int32 WGetPID(void){ pid_t pid = 0; // Attempt to retrieve the window pid - if (AXUIElementGetPid(mData.AxID, &pid) - == kAXErrorSuccess) { - return pid; - } + if (AXUIElementGetPid(mData.AxID, &pid)== kAXErrorSuccess) { + return pid; + } return 0;