Skip to content

Commit 6ba4944

Browse files
committed
improved hotkey toggling; attempt to fix non exiting process problem
1 parent 24f9291 commit 6ba4944

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
SRCS=virgo.c
33
OBJS=$(SRCS:.c=.o)
4-
CFLAGS=-O3 -nostdlib -fno-asynchronous-unwind-tables -fno-builtin -fno-ident -ffunction-sections -fdata-sections -Wall -DRELEASE=1
4+
CFLAGS=-O3 -nostdlib -fno-asynchronous-unwind-tables -fno-builtin -fno-ident -ffunction-sections -fdata-sections -Wall
55
LIBS=-lgdi32 -lmsvcrt -luser32 -lshell32 -lkernel32
66
LDFLAGS=-static -nostdlib -fno-builtin -s -Wl,-e,__main,--gc-sections,-subsystem,windows $(LIBS)
77
ARCH=32

virgo.c

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#define stb__sbmaybegrow(a,n) (stb__sbneedgrow(a,(n)) ? stb__sbgrow(a,n) : 0)
1515
#define stb__sbgrow(a,n) ((a) = stb__sbgrowf((a), (n), sizeof(*(a))))
1616

17+
#ifndef MOD_NOREPEAT
18+
#define MOD_NOREPEAT 0x4000
19+
#endif
20+
1721
#define NUM_DESKTOPS 4
1822

1923
typedef struct {
@@ -49,7 +53,7 @@ static void *stb__sbgrowf(void *arr, int increment, int itemsize)
4953
p[0] = m;
5054
return p+2;
5155
} else {
52-
exit(1);
56+
ExitProcess(1);
5357
return (void *)(2*sizeof(int));
5458
}
5559
}
@@ -115,6 +119,7 @@ static void trayicon_deinit(Trayicon *t)
115119
DeleteObject(t->hBitmap);
116120
ReleaseDC(t->dummyHWND, t->hdc);
117121
Shell_NotifyIcon(NIM_DELETE, &t->nid);
122+
DestroyWindow(t->dummyHWND);
118123
}
119124

120125
static void windows_mod(Windows *wins, int state)
@@ -178,7 +183,7 @@ static void register_hotkey(int id, int mod, int vk)
178183
if(!RegisterHotKey(NULL, id, mod, vk)) {
179184
MessageBox(NULL, "could not register hotkey", "error",
180185
MB_ICONEXCLAMATION);
181-
exit(1);
186+
ExitProcess(1);
182187
}
183188
}
184189

@@ -220,9 +225,25 @@ static void virgo_update(Virgo *v)
220225
EnumWindows((WNDENUMPROC)&enum_func, (LPARAM)v);
221226
}
222227

228+
static void virgo_toggle_hotkeys(Virgo *v)
229+
{
230+
int i;
231+
v->handle_hotkeys = !v->handle_hotkeys;
232+
if(v->handle_hotkeys) {
233+
for(i=0; i<NUM_DESKTOPS; i++) {
234+
register_hotkey(i*2, MOD_ALT|MOD_NOREPEAT, i+1+0x30);
235+
register_hotkey(i*2+1, MOD_CONTROL|MOD_NOREPEAT, i+1+0x30);
236+
}
237+
} else {
238+
for(i=0; i<NUM_DESKTOPS; i++) {
239+
UnregisterHotKey(NULL, i*2);
240+
UnregisterHotKey(NULL, i*2+1);
241+
}
242+
}
243+
}
244+
223245
static void virgo_init(Virgo *v)
224246
{
225-
#define MOD_NOREPEAT 0x4000
226247
int i;
227248
v->current = 0;
228249
v->handle_hotkeys = 1;
@@ -233,7 +254,7 @@ static void virgo_init(Virgo *v)
233254
register_hotkey(i*2+1, MOD_CONTROL|MOD_NOREPEAT, i+1+0x30);
234255
}
235256
register_hotkey(i*2, MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_NOREPEAT, 'Q');
236-
register_hotkey((i*2)+1, MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_NOREPEAT, 'S');
257+
register_hotkey(i*2+1, MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_NOREPEAT, 'S');
237258
trayicon_init(&v->trayicon);
238259
}
239260

@@ -275,12 +296,8 @@ static void virgo_go_to_desk(Virgo *v, int desk)
275296
trayicon_set(&v->trayicon, v->current+1);
276297
}
277298

278-
#ifdef RELEASE
279-
extern int __main(void) asm("__main");
280-
int __main(void)
281-
#else
282-
int main(int argc, char **argv)
283-
#endif
299+
extern void __main(void) asm("__main");
300+
void __main(void)
284301
{
285302
Virgo v;
286303
MSG msg;
@@ -289,12 +306,12 @@ int main(int argc, char **argv)
289306
if(msg.message != WM_HOTKEY) {
290307
continue;
291308
}
292-
if(msg.wParam == (NUM_DESKTOPS*2)+1) {
293-
v.handle_hotkeys = !v.handle_hotkeys;
309+
if(msg.wParam == NUM_DESKTOPS*2) {
310+
break;
311+
}
312+
if(msg.wParam == NUM_DESKTOPS*2+1) {
313+
virgo_toggle_hotkeys(&v);
294314
} else if(v.handle_hotkeys) {
295-
if(msg.wParam == NUM_DESKTOPS*2) {
296-
break;
297-
}
298315
if(msg.wParam%2 == 0) {
299316
virgo_go_to_desk(&v, msg.wParam/2);
300317
} else {
@@ -303,5 +320,5 @@ int main(int argc, char **argv)
303320
}
304321
}
305322
virgo_deinit(&v);
306-
return EXIT_SUCCESS;
323+
ExitProcess(0);
307324
}

0 commit comments

Comments
 (0)