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 bool
pasteCmdArgs []string
copyCmdArgs []string
pasteCmdArgs, copyCmdArgs []string
xselPasteArgs = []string{xsel, "--output", "--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
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()
}

View File

@ -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(){

View File

@ -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)