Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
fix compile error when using gcc 7.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
henkman committed Feb 24, 2018
1 parent 22ed829 commit 17d7093
Showing 1 changed file with 55 additions and 64 deletions.
119 changes: 55 additions & 64 deletions virgo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
#include <windows.h>
#include <shellapi.h>

#define sb_free(a) ((a) ? HeapFree(GetProcessHeap(), 0, stb__sbraw(a)),0 : 0)
#define sb_push(a,v) (stb__sbmaybegrow(a,1), (a)[stb__sbn(a)++] = (v))
#define sb_count(a) ((a) ? stb__sbn(a) : 0)
#define sb_free(a) ((a) ? HeapFree(GetProcessHeap(), 0, stb__sbraw(a)), 0 : 0)
#define sb_push(a, v) (stb__sbmaybegrow(a, 1), (a)[stb__sbn(a)++] = (v))
#define sb_count(a) ((a) ? stb__sbn(a) : 0)

#define stb__sbraw(a) ((int *) (a) - 2)
#define stb__sbm(a) stb__sbraw(a)[0]
#define stb__sbn(a) stb__sbraw(a)[1]
#define stb__sbraw(a) ((int *)(a)-2)
#define stb__sbm(a) stb__sbraw(a)[0]
#define stb__sbn(a) stb__sbraw(a)[1]

#define stb__sbneedgrow(a,n) ((a)==0 || stb__sbn(a)+(n) >= stb__sbm(a))
#define stb__sbmaybegrow(a,n) (stb__sbneedgrow(a,(n)) ? stb__sbgrow(a,n) : 0)
#define stb__sbgrow(a,n) ((a) = stb__sbgrowf((a), (n), sizeof(*(a))))
#define stb__sbneedgrow(a, n) ((a) == 0 || stb__sbn(a) + (n) >= stb__sbm(a))
#define stb__sbmaybegrow(a, n) (stb__sbneedgrow(a, (n)) ? stb__sbgrow(a, n) : 0)
#define stb__sbgrow(a, n) ((a) = stb__sbgrowf((a), (n), sizeof(*(a))))

#ifndef MOD_NOREPEAT
#define MOD_NOREPEAT 0x4000
Expand Down Expand Up @@ -43,25 +43,25 @@ typedef struct {

static void *stb__sbgrowf(void *arr, unsigned increment, unsigned itemsize)
{
unsigned dbl_cur = arr ? 2*stb__sbm(arr) : 0;
unsigned dbl_cur = arr ? 2 * stb__sbm(arr) : 0;
unsigned min_needed = sb_count(arr) + increment;
unsigned m = dbl_cur > min_needed ? dbl_cur : min_needed;
unsigned *p;
if (arr) {
p = HeapReAlloc(GetProcessHeap(), 0, stb__sbraw(arr),
itemsize*m + sizeof(unsigned)*2);
itemsize * m + sizeof(unsigned) * 2);
} else {
p = HeapAlloc(GetProcessHeap(), 0, itemsize*m + sizeof(unsigned)*2);
p = HeapAlloc(GetProcessHeap(), 0, itemsize * m + sizeof(unsigned) * 2);
}
if (p) {
if (!arr) {
p[1] = 0;
}
p[0] = m;
return p+2;
return p + 2;
} else {
ExitProcess(1);
return (void *)(2*sizeof(unsigned));
return (void *)(2 * sizeof(unsigned));
}
}

Expand All @@ -70,8 +70,8 @@ static HICON trayicon_draw(Trayicon *t, char *text, unsigned len)
ICONINFO iconInfo;
HBITMAP hOldBitmap;
HFONT hOldFont;
hOldBitmap = (HBITMAP) SelectObject(t->mdc, t->hBitmap);
hOldFont = (HFONT) SelectObject(t->mdc, t->hFont);
hOldBitmap = (HBITMAP)SelectObject(t->mdc, t->hBitmap);
hOldFont = (HFONT)SelectObject(t->mdc, t->hFont);
TextOut(t->mdc, t->bitmapWidth / 4, 0, text, len);
SelectObject(t->mdc, hOldBitmap);
SelectObject(t->mdc, hOldFont);
Expand All @@ -84,11 +84,8 @@ static HICON trayicon_draw(Trayicon *t, char *text, unsigned len)
static void trayicon_init(Trayicon *t)
{
HDC hdc;
t->hwnd = CreateWindowA(
"STATIC", "virgo",
0, 0, 0, 0, 0,
NULL, NULL, NULL, NULL
);
t->hwnd =
CreateWindowA("STATIC", "virgo", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
t->bitmapWidth = GetSystemMetrics(SM_CXSMICON);
t->nid.cbSize = sizeof(t->nid);
t->nid.hWnd = t->hwnd;
Expand All @@ -100,18 +97,16 @@ static void trayicon_init(Trayicon *t)
ReleaseDC(t->hwnd, hdc);
SetBkColor(t->mdc, RGB(0x00, 0x00, 0x00));
SetTextColor(t->mdc, RGB(0x00, 0xFF, 0x00));
t->hFont = CreateFont(
-MulDiv(11, GetDeviceCaps(t->mdc, LOGPIXELSY), 72),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("Arial")
);
t->hFont = CreateFont(-MulDiv(11, GetDeviceCaps(t->mdc, LOGPIXELSY), 72), 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("Arial"));
t->nid.hIcon = trayicon_draw(t, "1", 1);
Shell_NotifyIcon(NIM_ADD, &t->nid);
}

static void trayicon_set(Trayicon *t, unsigned number)
{
char snumber[2];
if (number>9) {
if (number > 9) {
return;
}
snumber[0] = number + '0';
Expand All @@ -134,20 +129,14 @@ static void trayicon_deinit(Trayicon *t)
static void windows_mod(Windows *wins, unsigned state)
{
unsigned i;
for (i=0; i<wins->count; i++) {
for (i = 0; i < wins->count; i++) {
ShowWindow(wins->windows[i], state);
}
}

static void windows_show(Windows *wins)
{
windows_mod(wins, SW_SHOW);
}
static void windows_show(Windows *wins) { windows_mod(wins, SW_SHOW); }

static void windows_hide(Windows *wins)
{
windows_mod(wins, SW_HIDE);
}
static void windows_hide(Windows *wins) { windows_mod(wins, SW_HIDE); }

static void windows_add(Windows *wins, HWND hwnd)
{
Expand All @@ -162,13 +151,13 @@ static void windows_add(Windows *wins, HWND hwnd)
static void windows_del(Windows *wins, HWND hwnd)
{
unsigned i, e;
for (i=0; i<wins->count; i++) {
for (i = 0; i < wins->count; i++) {
if (wins->windows[i] != hwnd) {
continue;
}
if (i != wins->count-1) {
for (e=i; e<wins->count-1; e++) {
wins->windows[e] = wins->windows[e+1];
if (i != wins->count - 1) {
for (e = i; e < wins->count - 1; e++) {
wins->windows[e] = wins->windows[e + 1];
}
}
wins->count--;
Expand All @@ -188,7 +177,7 @@ static void register_hotkey(unsigned id, unsigned mod, unsigned vk)
{
if (!RegisterHotKey(NULL, id, mod, vk)) {
MessageBox(NULL, "could not register hotkey", "error",
MB_ICONEXCLAMATION);
MB_ICONEXCLAMATION);
ExitProcess(1);
}
}
Expand All @@ -198,13 +187,13 @@ static BOOL enum_func(HWND hwnd, LPARAM lParam)
unsigned i, e;
Virgo *v;
Windows *desk;
v = (Virgo *) lParam;
v = (Virgo *)lParam;
if (!is_valid_window(hwnd)) {
return 1;
}
for (i=0; i<NUM_DESKTOPS; i++) {
for (i = 0; i < NUM_DESKTOPS; i++) {
desk = &(v->desktops[i]);
for (e=0; e<desk->count; e++) {
for (e = 0; e < desk->count; e++) {
if (desk->windows[e] == hwnd) {
return 1;
}
Expand All @@ -219,17 +208,17 @@ static void virgo_update(Virgo *v)
unsigned i, e;
Windows *desk;
HWND hwnd;
for (i=0; i<NUM_DESKTOPS; i++) {
for (i = 0; i < NUM_DESKTOPS; i++) {
desk = &(v->desktops[i]);
for (e=0; e<desk->count; e++) {
for (e = 0; e < desk->count; e++) {
hwnd = desk->windows[e];
if (!GetWindowThreadProcessId(desk->windows[e], NULL)) {
windows_del(desk, hwnd);
}
}
}
desk = &v->desktops[v->current];
for (i=0; i<desk->count; i++) {
for (i = 0; i < desk->count; i++) {
hwnd = desk->windows[i];
if (!IsWindowVisible(hwnd)) {
windows_del(desk, hwnd);
Expand All @@ -243,14 +232,14 @@ static void virgo_toggle_hotkeys(Virgo *v)
unsigned i;
v->handle_hotkeys = !v->handle_hotkeys;
if (v->handle_hotkeys) {
for (i=0; i<NUM_DESKTOPS; i++) {
register_hotkey(i*2, MOD_ALT|MOD_NOREPEAT, i+1+'0');
register_hotkey(i*2+1, MOD_CONTROL|MOD_NOREPEAT, i+1+'0');
for (i = 0; i < NUM_DESKTOPS; i++) {
register_hotkey(i * 2, MOD_ALT | MOD_NOREPEAT, i + 1 + '0');
register_hotkey(i * 2 + 1, MOD_CONTROL | MOD_NOREPEAT, i + 1 + '0');
}
} else {
for (i=0; i<NUM_DESKTOPS; i++) {
UnregisterHotKey(NULL, i*2);
UnregisterHotKey(NULL, i*2+1);
for (i = 0; i < NUM_DESKTOPS; i++) {
UnregisterHotKey(NULL, i * 2);
UnregisterHotKey(NULL, i * 2 + 1);
}
}
}
Expand All @@ -259,19 +248,21 @@ static void virgo_init(Virgo *v)
{
unsigned i;
v->handle_hotkeys = 1;
for (i=0; i<NUM_DESKTOPS; i++) {
register_hotkey(i*2, MOD_ALT|MOD_NOREPEAT, i+1+'0');
register_hotkey(i*2+1, MOD_CONTROL|MOD_NOREPEAT, i+1+'0');
for (i = 0; i < NUM_DESKTOPS; i++) {
register_hotkey(i * 2, MOD_ALT | MOD_NOREPEAT, i + 1 + '0');
register_hotkey(i * 2 + 1, MOD_CONTROL | MOD_NOREPEAT, i + 1 + '0');
}
register_hotkey(i*2, MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_NOREPEAT, 'Q');
register_hotkey(i*2+1, MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_NOREPEAT, 'S');
register_hotkey(i * 2, MOD_ALT | MOD_CONTROL | MOD_SHIFT | MOD_NOREPEAT,
'Q');
register_hotkey(i * 2 + 1, MOD_ALT | MOD_CONTROL | MOD_SHIFT | MOD_NOREPEAT,
'S');
trayicon_init(&v->trayicon);
}

static void virgo_deinit(Virgo *v)
{
unsigned i;
for (i=0; i<NUM_DESKTOPS; i++) {
for (i = 0; i < NUM_DESKTOPS; i++) {
windows_show(&v->desktops[i]);
sb_free(v->desktops[i].windows);
}
Expand Down Expand Up @@ -303,7 +294,7 @@ static void virgo_go_to_desk(Virgo *v, unsigned desk)
windows_hide(&v->desktops[v->current]);
windows_show(&v->desktops[desk]);
v->current = desk;
trayicon_set(&v->trayicon, v->current+1);
trayicon_set(&v->trayicon, v->current + 1);
}

void __main(void) __asm__("__main");
Expand All @@ -316,15 +307,15 @@ void __main(void)
if (msg.message != WM_HOTKEY) {
continue;
}
if (msg.wParam == NUM_DESKTOPS*2) {
if (msg.wParam == NUM_DESKTOPS * 2) {
break;
}
if (msg.wParam == NUM_DESKTOPS*2+1) {
if (msg.wParam == NUM_DESKTOPS * 2 + 1) {
virgo_toggle_hotkeys(&v);
} else if (msg.wParam%2 == 0) {
virgo_go_to_desk(&v, msg.wParam/2);
} else if (msg.wParam % 2 == 0) {
virgo_go_to_desk(&v, msg.wParam / 2);
} else {
virgo_move_to_desk(&v, (msg.wParam-1)/2);
virgo_move_to_desk(&v, (msg.wParam - 1) / 2);
}
}
virgo_deinit(&v);
Expand Down

0 comments on commit 17d7093

Please sign in to comment.