mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-06 00:33:55 +00:00
fix windows active by pid and change some style
This commit is contained in:
parent
50508899ac
commit
ae548fca8f
@ -57,16 +57,46 @@ void set_active(const MData win){
|
|||||||
SetActive(win);
|
SetActive(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(IS_WINDOWS)
|
||||||
|
typedef struct{
|
||||||
|
HWND hWnd;
|
||||||
|
DWORD dwPid;
|
||||||
|
}WNDINFO;
|
||||||
|
|
||||||
|
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam){
|
||||||
|
WNDINFO* pInfo = (WNDINFO*)lParam;
|
||||||
|
DWORD dwProcessId = 0;
|
||||||
|
GetWindowThreadProcessId(hWnd, &dwProcessId);
|
||||||
|
|
||||||
|
if(dwProcessId == pInfo->dwPid){
|
||||||
|
pInfo->hWnd = hWnd;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND GetHwndByPId(DWORD dwProcessId){
|
||||||
|
WNDINFO info = {0};
|
||||||
|
info.hWnd = NULL;
|
||||||
|
info.dwPid = dwProcessId;
|
||||||
|
EnumWindows(EnumWindowsProc, (LPARAM)&info);
|
||||||
|
// printf("%d\n", info.hWnd);
|
||||||
|
return info.hWnd;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void active_PID(uintptr pid){
|
void active_PID(uintptr pid){
|
||||||
MData win;
|
MData win;
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
// Handle to a AXUIElementRef
|
// Handle to a AXUIElementRef
|
||||||
win.AxID = AXUIElementCreateApplication(pid);
|
win.AxID = AXUIElementCreateApplication(pid);
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
win.XWin = (Window) pid; // Handle to an X11 window
|
win.XWin = (Window)pid; // Handle to an X11 window
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
win.HWnd = (HWND) pid; // Handle to a window HWND
|
// win.HWnd = (HWND)pid; // Handle to a window HWND
|
||||||
|
win.HWnd = GetHwndByPId(pid);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SetActive(win);
|
SetActive(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,8 +504,8 @@ bool IsTopMost(void){
|
|||||||
|
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
|
|
||||||
return (GetWindowLongPtr(mData.HWnd,
|
return (GetWindowLongPtr(mData.HWnd, GWL_EXSTYLE)
|
||||||
GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
|
& WS_EX_TOPMOST) != 0;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -537,8 +537,8 @@ bool IsMinimized(void){
|
|||||||
|
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
|
|
||||||
return (GetWindowLongPtr(mData.HWnd,
|
return (GetWindowLongPtr(mData.HWnd, GWL_STYLE)
|
||||||
GWL_STYLE) & WS_MINIMIZE) != 0;
|
& WS_MINIMIZE) != 0;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -560,8 +560,8 @@ bool IsMaximized(void){
|
|||||||
|
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
|
|
||||||
return (GetWindowLongPtr (mData.HWnd,
|
return (GetWindowLongPtr(mData.HWnd, GWL_STYLE)
|
||||||
GWL_STYLE) & WS_MAXIMIZE) != 0;
|
& WS_MAXIMIZE) != 0;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -676,8 +676,8 @@ MData GetActive(void){
|
|||||||
|
|
||||||
CGWindowID win = 0;
|
CGWindowID win = 0;
|
||||||
// Use undocumented API to get WID
|
// Use undocumented API to get WID
|
||||||
if (_AXUIElementGetWindow (element,
|
if (_AXUIElementGetWindow (element, &win)
|
||||||
&win) == kAXErrorSuccess && win){
|
== kAXErrorSuccess && win){
|
||||||
// Manually set internals
|
// Manually set internals
|
||||||
result.CgID = win;
|
result.CgID = win;
|
||||||
result.AxID = element;
|
result.AxID = element;
|
||||||
@ -697,8 +697,7 @@ MData GetActive(void){
|
|||||||
MData result;
|
MData result;
|
||||||
Display *rDisplay = XOpenDisplay(NULL);
|
Display *rDisplay = XOpenDisplay(NULL);
|
||||||
// Check X-Window display
|
// Check X-Window display
|
||||||
if (WM_ACTIVE == None ||
|
if (WM_ACTIVE == None || rDisplay == NULL){
|
||||||
rDisplay == NULL){
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -725,8 +724,7 @@ MData GetActive(void){
|
|||||||
// Use input focus instead
|
// Use input focus instead
|
||||||
Window window = None;
|
Window window = None;
|
||||||
int revert = RevertToNone;
|
int revert = RevertToNone;
|
||||||
XGetInputFocus(rDisplay,
|
XGetInputFocus(rDisplay, &window, &revert);
|
||||||
&window, &revert);
|
|
||||||
|
|
||||||
// Return foreground window
|
// Return foreground window
|
||||||
result.XWin = window;
|
result.XWin = window;
|
||||||
@ -770,9 +768,9 @@ void SetTopMost(bool state){
|
|||||||
|
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
|
|
||||||
SetWindowPos (mData.HWnd, state ?
|
SetWindowPos(mData.HWnd,
|
||||||
HWND_TOPMOST : HWND_NOTOPMOST, 0,
|
state ? HWND_TOPMOST : HWND_NOTOPMOST,
|
||||||
0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user