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
@ -1548,6 +1548,6 @@ func ActiveName(name string) error {
// Kill kill the process by PID // Kill kill the process by PID
func Kill(pid int32) error { func Kill(pid int32) error {
ps := os.Process{Pid: int(pid)} ps := os.Process{Pid: int(pid)}
return ps.Kill() return ps.Kill()
} }

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;
@ -8,40 +38,41 @@ Bounds get_bounds(uintptr pid, uintptr isHwnd){
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
// Bounds bounds; // Bounds bounds;
AXValueRef axp = NULL; AXValueRef axp = NULL;
AXValueRef axs = NULL; AXValueRef axs = NULL;
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;
} }
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;
}
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: exit:
if (axp != NULL) { CFRelease(axp); } if (axp != NULL) { CFRelease(axp); }
if (axs != NULL) { CFRelease(axs); } if (axs != NULL) { CFRelease(axs); }
return bounds; return bounds;
#elif defined(USE_X11) #elif defined(USE_X11)