forked from nir9/lightwm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiling.c
56 lines (43 loc) · 1.04 KB
/
tiling.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
#include "tiling.h"
#include "error.h"
#include <Windows.h>
HWND managed[256];
int currentManagedIndex = 0;
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) {
if (currentManagedIndex > 255) {
return FALSE;
}
if (!IsWindowVisible(hwnd) || IsHungAppWindow(hwnd)) {
return TRUE;
}
WINDOWINFO winInfo;
winInfo.cbSize = sizeof(WINDOWINFO);
if (!GetWindowInfo(hwnd, &winInfo)) {
return TRUE;
}
if (winInfo.dwStyle & WS_POPUP) {
return TRUE;
}
if (GetWindowTextLengthW(hwnd) == 0) {
return TRUE;
}
RECT clientRect;
if (!GetClientRect(hwnd, &clientRect)) {
return TRUE;
}
// Skip small windows to avoid bugs
if (clientRect.right < 100 || clientRect.bottom < 100){
return TRUE;
}
managed[currentManagedIndex] = hwnd;
currentManagedIndex++;
return TRUE;
}
void tileWindows() {
currentManagedIndex = 0;
EnumChildWindows(GetDesktopWindow(), EnumChildProc, 0);
if (currentManagedIndex == 0) {
return;
}
TileWindows(GetDesktopWindow(), MDITILE_VERTICAL | MDITILE_SKIPDISABLED, NULL, currentManagedIndex, managed);
}