From a72c6ec51263d12dcd4aa7e1dc7869d776d06a30 Mon Sep 17 00:00:00 2001 From: RamonUnch <74856804+RamonUnch@users.noreply.github.com> Date: Thu, 22 Jul 2021 14:37:21 +0200 Subject: [PATCH] Minor fixes --- altdrag.nsi | 2 +- nanolibc.h | 27 +++++++++++++++++++++++++-- tray.c | 2 +- unfuck.h | 37 ++++++++++++++++++++----------------- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/altdrag.nsi b/altdrag.nsi index 56398856..811559e1 100644 --- a/altdrag.nsi +++ b/altdrag.nsi @@ -1,7 +1,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # define the name of the installer !define APP_NAME "AltDrag" -!define APP_VERSION "1.45" +!define APP_VERSION "1.46" # define the name of the installer OutFile "${APP_NAME}${APP_VERSION}-inst.exe" diff --git a/nanolibc.h b/nanolibc.h index 52557840..f18d20ee 100644 --- a/nanolibc.h +++ b/nanolibc.h @@ -1,11 +1,35 @@ #ifndef NANOLIBC_H #define NANOLIBC_H +#define flatten __attribute__((flatten)) +#define xpure __attribute__((const)) +#define pure __attribute__((pure)) +#define noreturn __attribute__((noreturn)) +#define fastcall __attribute__((fastcall)) +#define ainline __attribute__((always_inline)) + /* return +/-1 if x is +/- and 0 if x == 0 */ -static inline int sign(int x) +static xpure int sign(int x) { return (x > 0) - (x < 0); } + +#if defined(__x86_64__) || defined(__i386__) +static xpure int Iabs(int x) +{ + __asm__ ( + "cdq \n" + "xor %%edx, %%eax \n" + "sub %%edx, %%eax \n" + : "=eax" (x) + : "eax" (x) + : "%edx" + ); + return x; +} +#define abs(x) Iabs(x) +#endif + /* Function to set the kth bit of n */ static int setBit(int n, int k) { @@ -72,7 +96,6 @@ static int wtoiL(const wchar_t *s) return sign*v; } #define _wtoi wtoiL - static inline void reverse(wchar_t *str, int length) { int start = 0; diff --git a/tray.c b/tray.c index a01717e9..5d7f625b 100644 --- a/tray.c +++ b/tray.c @@ -39,7 +39,7 @@ int InitTray() // Register TaskbarCreated so we can re-add the tray icon if (when) explorer.exe crashes WM_TASKBARCREATED = RegisterWindowMessage(L"TaskbarCreated"); - LOG("Register TaskbarCreated message: %s\n", WM_TASKBARCREATED? "OK": "Fail!"); + LOG("Register TaskbarCreated message: %X\n", WM_TASKBARCREATED); return 0; } diff --git a/unfuck.h b/unfuck.h index 6fc84ba5..de870de4 100644 --- a/unfuck.h +++ b/unfuck.h @@ -26,12 +26,6 @@ #define NIIF_USER 0x00000004 #endif -#define flatten __attribute__((flatten)) -#define xpure __attribute__((const)) -#define pure __attribute__((pure)) -#define noreturn __attribute__((noreturn)) -#define fastcall __attribute__((fastcall)) - #ifndef SUBCLASSPROC typedef LRESULT (CALLBACK *SUBCLASSPROC) (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam @@ -538,10 +532,11 @@ static xpure int IsEqualT(int a, int b, int th) { return (b - th <= a) & (a <= b + th); } -static xpure int IsInRangeT(int x, int a, int b, int T) +static int IsInRangeT(int x, int a, int b, int T) { return (a-T <= x) & (x <= b+T); } + static pure unsigned AreRectsAligned(const RECT *a, const RECT *b, const int tol) { return IsEqualT(a->left, b->right, tol) << 2 @@ -549,20 +544,28 @@ static pure unsigned AreRectsAligned(const RECT *a, const RECT *b, const int tol | IsEqualT(a->right, b->left, tol) << 3 | IsEqualT(a->bottom, b->top, tol) << 5; } -static xpure int SegT(int ax, int bx, int ay1, int ay2, int by1, int by2, int tol) +static int InRange(int x, int a, int b) { - return IsEqualT(ax, bx, tol) /* ax == bx */ - && ( (ay1 >= by1 && ay1 <= by2) - || (by1 >= ay1 && by1 <= ay2) - || (ay2 >= by1 && ay2 <= by2) - || (by2 >= ay1 && by2 <= ay2) ); + return (x >= a) && (x <= b); } +static xpure int SegT(long ax, long bx, const long *_ay12, const long *_by12, int tol) +{ + const long by1 = _by12[0]; /* left/top */ + const long by2 = _by12[2]; /* right/bottom */ + const long ay1 = _ay12[0]; /* left/top */ + const long ay2 = _ay12[2]; /* right/bottom */ + return IsEqualT(ax, bx, tol) /* ax == bx */ + && ( InRange(ay1, by1, by2) + || InRange(by1, ay1, ay2) + || InRange(ay2, by1, by2) + || InRange(by2, ay1, ay2) ); + } static pure unsigned AreRectsTouchingT(const RECT *a, const RECT *b, const int tol) { - return SegT(a->left, b->right, a->top, a->bottom, b->top, b->bottom, tol) << 2 - | SegT(a->right, b->left, a->top, a->bottom, b->top, b->bottom, tol) << 3 - | SegT(a->top, b->bottom, a->left, a->right, b->left, b->right, tol) << 4 - | SegT(a->bottom, b->top, a->left, a->right, b->left, b->right, tol) << 5; + return SegT(a->left, b->right, &a->top, &b->top, tol) << 2 + | SegT(a->right, b->left, &a->top, &b->top, tol) << 3 + | SegT(a->top, b->bottom, &a->left, &b->left, tol) << 4 + | SegT(a->bottom, b->top, &a->left, &b->left, tol) << 5; } static void CropRect(RECT *__restrict__ wnd, RECT *crop) {