update code style and move scale to win_sys

This commit is contained in:
vcaesar 2018-08-14 07:18:14 -04:00
parent 2a813b1e31
commit cea1b340d7
4 changed files with 67 additions and 58 deletions

View File

@ -20,8 +20,7 @@ var (
// Primary choose primary mode on unix // Primary choose primary mode on unix
Primary bool Primary bool
pasteCmdArgs []string pasteCmdArgs, copyCmdArgs []string
copyCmdArgs []string
xselPasteArgs = []string{xsel, "--output", "--clipboard"} xselPasteArgs = []string{xsel, "--output", "--clipboard"}
xselCopyArgs = []string{xsel, "--input", "--clipboard"} xselCopyArgs = []string{xsel, "--input", "--clipboard"}

View File

@ -194,12 +194,12 @@ func GetPixelColor(x, y int) string {
// ScaleX get primary display horizontal DPI scale factor // ScaleX get primary display horizontal DPI scale factor
func ScaleX() int { func ScaleX() int {
return int(C.scaleX()) return int(C.scale_x())
} }
// ScaleY get primary display vertical DPI scale factor // ScaleY get primary display vertical DPI scale factor
func ScaleY() int { func ScaleY() int {
return int(C.scaleY()) return int(C.scale_y())
} }
// GetScreenSize get the screen size // GetScreenSize get the screen size

View File

@ -20,33 +20,12 @@ int show_alert(const char *title, const char *msg,
return alert; return alert;
} }
intptr scaleX(){ intptr scale_x(){
#if defined(IS_MACOSX) return scaleX();
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(){ intptr scale_y(){
#if defined(IS_MACOSX) return scaleY();
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
} }
bool is_valid(){ bool is_valid(){

View File

@ -1,6 +1,36 @@
// #include "../base/os.h" // #include "../base/os.h"
Bounds get_client(uintptr pid, uintptr isHwnd); 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){ Bounds get_bounds(uintptr pid, uintptr isHwnd){
// Check if the window is valid // Check if the window is valid
Bounds bounds; Bounds bounds;
@ -14,15 +44,15 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){
AXUIElementRef AxID = AXUIElementCreateApplication(pid); AXUIElementRef AxID = AXUIElementCreateApplication(pid);
// Determine the current point of the window // Determine the current point of the window
if (AXUIElementCopyAttributeValue(AxID, if (AXUIElementCopyAttributeValue(
kAXPositionAttribute, (CFTypeRef*) &axp) AxID, kAXPositionAttribute, (CFTypeRef*) &axp)
!= kAXErrorSuccess || axp == NULL){ != kAXErrorSuccess || axp == NULL){
goto exit; goto exit;
} }
// Determine the current size of the window // Determine the current size of the window
if (AXUIElementCopyAttributeValue(AxID, if (AXUIElementCopyAttributeValue(
kAXSizeAttribute, (CFTypeRef*) &axs) AxID, kAXSizeAttribute, (CFTypeRef*) &axs)
!= kAXErrorSuccess || axs == NULL){ != kAXErrorSuccess || axs == NULL){
goto exit; goto exit;
} }
@ -37,6 +67,7 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){
bounds.H = s.height; bounds.H = s.height;
} }
// return bounds;
exit: exit:
if (axp != NULL) { CFRelease(axp); } if (axp != NULL) { CFRelease(axp); }
if (axs != NULL) { CFRelease(axs); } if (axs != NULL) { CFRelease(axs); }