update code style

This commit is contained in:
vcaesar 2018-02-11 19:03:35 +08:00
parent 35f5016d33
commit 15233120e0
4 changed files with 37 additions and 41 deletions

View File

@ -15,8 +15,8 @@
// #include "../MMBitmap_c.h" // #include "../MMBitmap_c.h"
void padHex(MMRGBHex color, char* hex){ void padHex(MMRGBHex color, char* hex){
//Length needs to be 7 because snprintf includes a terminating null. // Length needs to be 7 because snprintf includes a terminating null.
//Use %06x to pad hex value with leading 0s. // Use %06x to pad hex value with leading 0s.
snprintf(hex, 7, "%06x", color); snprintf(hex, 7, "%06x", color);
} }

View File

@ -8,8 +8,7 @@
// #include "../base/xdisplay_c.h" // #include "../base/xdisplay_c.h"
#endif #endif
MMSize getMainDisplaySize(void) MMSize getMainDisplaySize(void){
{
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
CGDirectDisplayID displayID = CGMainDisplayID(); CGDirectDisplayID displayID = CGMainDisplayID();
return MMSizeMake(CGDisplayPixelsWide(displayID), return MMSizeMake(CGDisplayPixelsWide(displayID),
@ -26,8 +25,7 @@ MMSize getMainDisplaySize(void)
#endif #endif
} }
bool pointVisibleOnMainDisplay(MMPoint point) bool pointVisibleOnMainDisplay(MMPoint point){
{
MMSize displaySize = getMainDisplaySize(); MMSize displaySize = getMainDisplaySize();
return point.x < displaySize.width && point.y < displaySize.height; return point.x < displaySize.width && point.y < displaySize.height;
} }

View File

@ -17,8 +17,7 @@
#include <string.h> #include <string.h>
#endif #endif
MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect) MMBitmapRef copyMMBitmapFromDisplayInRect(MMRect rect){
{
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
MMBitmapRef bitmap = NULL; MMBitmapRef bitmap = NULL;

View File

@ -37,7 +37,7 @@ void aWindow();
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
static Boolean (*gAXIsProcessTrustedWithOptions) (CFDictionaryRef); static Boolean(*gAXIsProcessTrustedWithOptions) (CFDictionaryRef);
static CFStringRef* gkAXTrustedCheckOptionPrompt; static CFStringRef* gkAXTrustedCheckOptionPrompt;
@ -57,7 +57,7 @@ void aWindow();
CFRelease(wlist); CFRelease(wlist);
// Check whether the resulting array is populated // Check whether the resulting array is populated
if (info != NULL && CFArrayGetCount (info) > 0){ if (info != NULL && CFArrayGetCount(info) > 0){
// Retrieve description from info array // Retrieve description from info array
CFDictionaryRef desc = (CFDictionaryRef)CFArrayGetValueAtIndex(info, 0); CFDictionaryRef desc = (CFDictionaryRef)CFArrayGetValueAtIndex(info, 0);
@ -78,7 +78,7 @@ void aWindow();
// Create an accessibility object using retrieved PID // Create an accessibility object using retrieved PID
AXUIElementRef application = AXUIElementCreateApplication(pid); AXUIElementRef application = AXUIElementCreateApplication(pid);
if (application == 0) {return NULL;} if (application == 0) {return NULL;}
CFArrayRef windows = NULL; CFArrayRef windows = NULL;
@ -104,7 +104,7 @@ void aWindow();
// Check results // Check results
if (temp == win){ if (temp == win){
// Retain element // Retain element
CFRetain (element); CFRetain(element);
result = element; result = element;
break; break;
} }
@ -118,7 +118,7 @@ void aWindow();
} }
#elif defined(USE_X11) #elif defined(USE_X11)
// Error Handling // Error Handling
typedef int (*XErrorHandler) (Display*, XErrorEvent*); typedef int (*XErrorHandler) (Display*, XErrorEvent*);
@ -129,15 +129,15 @@ void aWindow();
void XDismissErrors (void){ void XDismissErrors (void){
Display *rDisplay = XOpenDisplay(NULL); Display *rDisplay = XOpenDisplay(NULL);
// Save old handler and dismiss errors // Save old handler and dismiss errors
mOld = XSetErrorHandler (XHandleError); mOld = XSetErrorHandler(XHandleError);
// Flush output buffer // Flush output buffer
XSync (rDisplay, False); XSync(rDisplay, False);
// Reinstate old handler // Reinstate old handler
XSetErrorHandler (mOld); XSetErrorHandler(mOld);
} }
// Definitions // Definitions
struct Hints{ struct Hints{
unsigned long Flags; unsigned long Flags;
@ -186,7 +186,7 @@ void aWindow();
// Functions // Functions
static void* GetWindowProperty(MData win, Atom atom, uint32* items){ static void* GetWindowProperty(MData win, Atom atom, uint32* items){
// Property variables // Property variables
Atom type; int format; Atom type; int format;
@ -339,7 +339,7 @@ bool IsValid(){
if (result == NULL) {return false;} if (result == NULL) {return false;}
// Free result and return true // Free result and return true
XFree(result); XFree(result);
return true; return true;
#elif defined(IS_WINDOWS) #elif defined(IS_WINDOWS)
@ -418,7 +418,7 @@ bool setHandle(uintptr handle){
// Release the AX element // Release the AX element
if (mData.AxID != NULL){ if (mData.AxID != NULL){
CFRelease(mData.AxID); CFRelease(mData.AxID);
} }
// Reset both values // Reset both values
mData.CgID = 0; mData.CgID = 0;
@ -504,7 +504,7 @@ bool IsTopMost(void){
#elif defined(IS_WINDOWS) #elif defined(IS_WINDOWS)
return (GetWindowLongPtr(mData.HWnd, GWL_EXSTYLE) return (GetWindowLongPtr(mData.HWnd, GWL_EXSTYLE)
& WS_EX_TOPMOST) != 0; & WS_EX_TOPMOST) != 0;
#endif #endif
@ -523,7 +523,7 @@ bool IsMinimized(void){
== kAXErrorSuccess && data != NULL){ == kAXErrorSuccess && data != NULL){
// Convert resulting data into a bool // Convert resulting data into a bool
bool result = CFBooleanGetValue(data); bool result = CFBooleanGetValue(data);
CFRelease(data); CFRelease(data);
return result; return result;
} }
@ -537,7 +537,7 @@ bool IsMinimized(void){
#elif defined(IS_WINDOWS) #elif defined(IS_WINDOWS)
return (GetWindowLongPtr(mData.HWnd, GWL_STYLE) return (GetWindowLongPtr(mData.HWnd, GWL_STYLE)
& WS_MINIMIZE) != 0; & WS_MINIMIZE) != 0;
#endif #endif
@ -560,7 +560,7 @@ bool IsMaximized(void){
#elif defined(IS_WINDOWS) #elif defined(IS_WINDOWS)
return (GetWindowLongPtr(mData.HWnd, GWL_STYLE) return (GetWindowLongPtr(mData.HWnd, GWL_STYLE)
& WS_MAXIMIZE) != 0; & WS_MAXIMIZE) != 0;
#endif #endif
@ -572,11 +572,11 @@ void SetActive(const MData win){
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
// Attempt to raise the specified window object // Attempt to raise the specified window object
if (AXUIElementPerformAction(win.AxID, kAXRaiseAction) if (AXUIElementPerformAction(win.AxID, kAXRaiseAction)
!= kAXErrorSuccess){ != kAXErrorSuccess){
pid_t pid = 0; pid_t pid = 0;
// Attempt to retrieve the PID of the window // Attempt to retrieve the PID of the window
if (AXUIElementGetPid (win.AxID, &pid) if (AXUIElementGetPid(win.AxID, &pid)
!= kAXErrorSuccess || !pid) {return;} != kAXErrorSuccess || !pid) {return;}
// Ignore deprecated warnings // Ignore deprecated warnings
@ -589,7 +589,7 @@ void SetActive(const MData win){
ProcessSerialNumber psn; ProcessSerialNumber psn;
// Attempt to retrieve the process psn // Attempt to retrieve the process psn
if (GetProcessForPID (pid, &psn) == 0){ if (GetProcessForPID(pid, &psn) == 0){
// Gracefully activate process // Gracefully activate process
SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly);
} }
@ -609,8 +609,7 @@ void SetActive(const MData win){
if (WM_ACTIVE != None){ if (WM_ACTIVE != None){
// Retrieve the screen number // Retrieve the screen number
XWindowAttributes attr = { 0 }; XWindowAttributes attr = { 0 };
XGetWindowAttributes (rDisplay, XGetWindowAttributes(rDisplay, win.XWin, &attr);
win.XWin, &attr);
int s = XScreenNumberOfScreen(attr.screen); int s = XScreenNumberOfScreen(attr.screen);
// Prepare an event // Prepare an event
@ -676,7 +675,7 @@ MData GetActive(void){
CGWindowID win = 0; CGWindowID win = 0;
// Use undocumented API to get WID // Use undocumented API to get WID
if (_AXUIElementGetWindow (element, &win) if (_AXUIElementGetWindow(element, &win)
== kAXErrorSuccess && win){ == kAXErrorSuccess && win){
// Manually set internals // Manually set internals
result.CgID = win; result.CgID = win;
@ -689,7 +688,7 @@ MData GetActive(void){
} }
CFRelease(focused); CFRelease(focused);
return result; return result;
#elif defined(USE_X11) #elif defined(USE_X11)
@ -712,7 +711,7 @@ MData GetActive(void){
if (active != NULL){ if (active != NULL){
// Extract window from the result // Extract window from the result
long window = *((long*)active); long window = *((long*)active);
XFree(active); XFree(active);
if (window != 0){ if (window != 0){
// Set and return the foreground window // Set and return the foreground window
@ -763,13 +762,13 @@ void SetTopMost(bool state){
#elif defined(USE_X11) #elif defined(USE_X11)
// Ignore X errors // Ignore X errors
// XDismissErrors (); // XDismissErrors();
// SetState (mData.XWin, STATE_TOPMOST, state); // SetState(mData.XWin, STATE_TOPMOST, state);
#elif defined(IS_WINDOWS) #elif defined(IS_WINDOWS)
SetWindowPos(mData.HWnd, SetWindowPos(mData.HWnd,
state ? HWND_TOPMOST : HWND_NOTOPMOST, state ? HWND_TOPMOST : HWND_NOTOPMOST,
0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
#endif #endif
@ -815,9 +814,9 @@ char *GetTitle(){
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
CFStringRef data = NULL; CFStringRef data = NULL;
// Determine the current title of the window // Determine the current title of the window
if (AXUIElementCopyAttributeValue (mData.AxID, if (AXUIElementCopyAttributeValue(mData.AxID,
kAXTitleAttribute, (CFTypeRef*) &data) kAXTitleAttribute, (CFTypeRef*) &data)
== kAXErrorSuccess && data != NULL){ == kAXErrorSuccess && data != NULL){
char conv[512]; char conv[512];
@ -860,7 +859,7 @@ char *GetTitle(){
if (result != NULL){ if (result != NULL){
// Convert result to a string // Convert result to a string
char *name = (char*)result; char *name = (char*)result;
XFree(result); XFree(result);
return name; return name;
} }
@ -872,7 +871,7 @@ char *GetTitle(){
(mData.HWnd, mData.Title, 512) > 0 ? mData.Title : ""; (mData.HWnd, mData.Title, 512) > 0 ? mData.Title : "";
// return GetWindowText // return GetWindowText
// (mData.HWnd, name, 512) > 0 ? // (mData.HWnd, name, 512) > 0 ?
// _UTF8Encode (name) : "null"; // _UTF8Encode(name) : "null";
#endif #endif
} }
@ -903,7 +902,7 @@ int32 WGetPID(void){
// Check result and convert it // Check result and convert it
if (result == NULL) {return 0;} if (result == NULL) {return 0;}
int32 pid = (int32) *result; int32 pid = (int32) *result;
XFree(result); XFree(result);
return pid; return pid;
#elif defined(IS_WINDOWS) #elif defined(IS_WINDOWS)