Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RamonUnch authored Jul 22, 2021
1 parent 88eec63 commit a72c6ec
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
2 changes: 1 addition & 1 deletion altdrag.nsi
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
27 changes: 25 additions & 2 deletions nanolibc.h
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
37 changes: 20 additions & 17 deletions unfuck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -538,31 +532,40 @@ 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
| IsEqualT(a->top, b->bottom, tol) << 4
| 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)
{
Expand Down

0 comments on commit a72c6ec

Please sign in to comment.