forked from nir9/lightwm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wm.c
84 lines (61 loc) · 1.33 KB
/
wm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <Windows.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include "error.h"
#include "tiling.h"
HHOOK hookHandle;
HMODULE wmDll;
HANDLE windowEvent;
void cleanupObjects() {
if (hookHandle) {
UnhookWindowsHookEx(hookHandle);
}
if (wmDll) {
FreeLibrary(wmDll);
}
if (windowEvent) {
CloseHandle(windowEvent);
}
}
void ctrlc(int sig) {
cleanupObjects();
puts("Exiting");
exit(ERROR_SUCCESS);
}
int main() {
SetProcessDPIAware();
wmDll = LoadLibraryW(L"lightwm_dll");
if (wmDll == NULL) {
reportWin32Error(L"LoadLibrary of wm_dll");
return ERROR_MOD_NOT_FOUND;
}
FARPROC shellProc = GetProcAddress(wmDll, "ShellProc");
if (shellProc == NULL) {
reportWin32Error(L"GetProcAddress");
goto cleanup;
}
windowEvent = CreateEventW(NULL, FALSE, FALSE, L"LightWMWindowEvent");
if (windowEvent == NULL) {
reportWin32Error(L"CreateEvent");
goto cleanup;
}
hookHandle = SetWindowsHookExW(WH_SHELL, (HOOKPROC)shellProc, wmDll, 0);
if (hookHandle == NULL) {
reportWin32Error(L"SetWindowsHookExW");
goto cleanup;
}
signal(SIGINT, ctrlc);
tileWindows();
for (;;) {
if (WaitForSingleObject(windowEvent, INFINITE) == WAIT_FAILED) {
reportWin32Error(L"WaitForSingleObject");
goto cleanup;
}
Sleep(200);
tileWindows();
}
cleanup:
cleanupObjects();
return EXIT_FAILURE;
}