From cea1b340d704c551b60845b3e27ffde6187a4140 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Tue, 14 Aug 2018 07:18:14 -0400 Subject: [PATCH] update code style and move scale to win_sys --- clipboard/clipboard_unix.go | 3 +- robotgo.go | 6 +-- window/goWindow.h | 29 ++----------- window/win_sys.h | 87 +++++++++++++++++++++++++------------ 4 files changed, 67 insertions(+), 58 deletions(-) diff --git a/clipboard/clipboard_unix.go b/clipboard/clipboard_unix.go index 363ae91..76d7611 100644 --- a/clipboard/clipboard_unix.go +++ b/clipboard/clipboard_unix.go @@ -20,8 +20,7 @@ var ( // Primary choose primary mode on unix Primary bool - pasteCmdArgs []string - copyCmdArgs []string + pasteCmdArgs, copyCmdArgs []string xselPasteArgs = []string{xsel, "--output", "--clipboard"} xselCopyArgs = []string{xsel, "--input", "--clipboard"} diff --git a/robotgo.go b/robotgo.go index f41335c..88c35a6 100644 --- a/robotgo.go +++ b/robotgo.go @@ -194,12 +194,12 @@ func GetPixelColor(x, y int) string { // ScaleX get primary display horizontal DPI scale factor func ScaleX() int { - return int(C.scaleX()) + return int(C.scale_x()) } // ScaleY get primary display vertical DPI scale factor func ScaleY() int { - return int(C.scaleY()) + return int(C.scale_y()) } // GetScreenSize get the screen size @@ -1548,6 +1548,6 @@ func ActiveName(name string) error { // Kill kill the process by PID func Kill(pid int32) error { - ps := os.Process{Pid: int(pid)} + ps := os.Process{Pid: int(pid)} return ps.Kill() } diff --git a/window/goWindow.h b/window/goWindow.h index c70795b..8f111e6 100644 --- a/window/goWindow.h +++ b/window/goWindow.h @@ -20,33 +20,12 @@ int show_alert(const char *title, const char *msg, return alert; } -intptr scaleX(){ - #if defined(IS_MACOSX) - return 0; - #elif defined(USE_X11) - return 0; - #elif defined(IS_WINDOWS) - // Get desktop dc - HDC desktopDc = GetDC(NULL); - // Get native resolution - intptr horizontalDPI = GetDeviceCaps(desktopDc, LOGPIXELSX); - // intptr verticalDPI = GetDeviceCaps(desktopDc, LOGPIXELSY); - return horizontalDPI; - #endif +intptr scale_x(){ + return scaleX(); } -intptr scaleY(){ - #if defined(IS_MACOSX) - return 0; - #elif defined(USE_X11) - return 0; - #elif defined(IS_WINDOWS) - // Get desktop dc - HDC desktopDc = GetDC(NULL); - // Get native resolution - intptr verticalDPI = GetDeviceCaps(desktopDc, LOGPIXELSY); - return verticalDPI; - #endif +intptr scale_y(){ + return scaleY(); } bool is_valid(){ diff --git a/window/win_sys.h b/window/win_sys.h index 1c853cd..43c4bf8 100644 --- a/window/win_sys.h +++ b/window/win_sys.h @@ -1,6 +1,36 @@ // #include "../base/os.h" + Bounds get_client(uintptr pid, uintptr isHwnd); +intptr scaleX(){ + #if defined(IS_MACOSX) + return 0; + #elif defined(USE_X11) + return 0; + #elif defined(IS_WINDOWS) + // Get desktop dc + HDC desktopDc = GetDC(NULL); + // Get native resolution + intptr horizontalDPI = GetDeviceCaps(desktopDc, LOGPIXELSX); + // intptr verticalDPI = GetDeviceCaps(desktopDc, LOGPIXELSY); + return horizontalDPI; + #endif +} + +intptr scaleY(){ + #if defined(IS_MACOSX) + return 0; + #elif defined(USE_X11) + return 0; + #elif defined(IS_WINDOWS) + // Get desktop dc + HDC desktopDc = GetDC(NULL); + // Get native resolution + intptr verticalDPI = GetDeviceCaps(desktopDc, LOGPIXELSY); + return verticalDPI; + #endif +} + Bounds get_bounds(uintptr pid, uintptr isHwnd){ // Check if the window is valid Bounds bounds; @@ -8,40 +38,41 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){ #if defined(IS_MACOSX) - // Bounds bounds; - AXValueRef axp = NULL; - AXValueRef axs = NULL; - AXUIElementRef AxID = AXUIElementCreateApplication(pid); + // Bounds bounds; + AXValueRef axp = NULL; + AXValueRef axs = NULL; + AXUIElementRef AxID = AXUIElementCreateApplication(pid); - // Determine the current point of the window - if (AXUIElementCopyAttributeValue(AxID, - kAXPositionAttribute, (CFTypeRef*) &axp) - != kAXErrorSuccess || axp == NULL){ - goto exit; - } + // Determine the current point of the window + if (AXUIElementCopyAttributeValue( + AxID, kAXPositionAttribute, (CFTypeRef*) &axp) + != kAXErrorSuccess || axp == NULL){ + goto exit; + } - // Determine the current size of the window - if (AXUIElementCopyAttributeValue(AxID, - kAXSizeAttribute, (CFTypeRef*) &axs) - != kAXErrorSuccess || axs == NULL){ - goto exit; - } - - CGPoint p; CGSize s; - // Attempt to convert both values into atomic types - if (AXValueGetValue(axp, kAXValueCGPointType, &p) && - AXValueGetValue(axs, kAXValueCGSizeType, &s)){ - bounds.X = p.x; - bounds.Y = p.y; - bounds.W = s.width; - bounds.H = s.height; - } + // Determine the current size of the window + if (AXUIElementCopyAttributeValue( + AxID, kAXSizeAttribute, (CFTypeRef*) &axs) + != kAXErrorSuccess || axs == NULL){ + goto exit; + } + CGPoint p; CGSize s; + // Attempt to convert both values into atomic types + if (AXValueGetValue(axp, kAXValueCGPointType, &p) && + AXValueGetValue(axs, kAXValueCGSizeType, &s)){ + bounds.X = p.x; + bounds.Y = p.y; + bounds.W = s.width; + bounds.H = s.height; + } + + // return bounds; exit: if (axp != NULL) { CFRelease(axp); } - if (axs != NULL) { CFRelease(axs); } + if (axs != NULL) { CFRelease(axs); } - return bounds; + return bounds; #elif defined(USE_X11)