+BOOL CALLBACK MonProc(HMONITOR mon, HDC dc, LPRECT rect, LPARAM _screens)
+{
+ MONITORINFO info = {.cbSize=sizeof(MONITORINFO)};
+ GetMonitorInfo(mon, &info);
+ RECT *work = &info.rcWork;
+
+ list_t **screens = (list_t**)_screens;
+ win_t *screen = new0(win_t);
+ screen->x = work->left;
+ screen->y = work->top;
+ screen->w = work->right - work->left;
+ screen->h = work->bottom - work->top;
+ *screens = list_append(*screens, screen);
+ printf("mon_proc: %d,%d %dx%d\n",
+ screen->x, screen->y, screen->w, screen->h);
+ return TRUE;
+}
+
+BOOL CALLBACK LoopProc(HWND hwnd, LPARAM user)
+{
+ win_t *win;
+ if ((win = win_find(hwnd,1)))
+ wm_insert(win);
+ return TRUE;
+}
+
+/********************
+ * System functions *
+ ********************/
+void sys_move(win_t *win, int x, int y, int w, int h)
+{
+ printf("sys_move: %p - %d,%d %dx%d\n", win, x, y, w, h);
+ win->x = x; win->y = y;
+ win->w = MAX(w,1); win->h = MAX(h,1);
+ MoveWindow(win->sys->hwnd, win->x, win->y, win->w, win->h, TRUE);
+}
+
+void sys_raise(win_t *win)
+{
+ printf("sys_raise: %p\n", win);
+ SetForegroundWindow(win->sys->hwnd);
+
+ //HWND hwnd = win->sys->hwnd;
+ //HWND top = GetAncestor(hwnd,GA_ROOT);
+ //SetWindowPos(top, HWND_TOPMOST, 0, 0, 0, 0,
+ // SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
+}
+
+void sys_focus(win_t *win)
+{
+ printf("sys_focus: %p\n", win);
+
+ /* Windows prevents a thread from using SetForegroundInput under
+ * certain circumstances and instead flashes the windows toolbar icon.
+ * Attaching the thread input queues avoids this behavior */
+ DWORD oldId = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
+ DWORD newId = GetCurrentThreadId();
+ AttachThreadInput(oldId, newId, TRUE);
+
+ BringWindowToTop(win->sys->hwnd);
+ SetForegroundWindow(win->sys->hwnd);
+ SetFocus(win->sys->hwnd);
+
+ AttachThreadInput(oldId, newId, FALSE);
+}
+
+void sys_show(win_t *win, state_t state)
+{
+ static struct {
+ char *str;
+ int cmd;
+ } map[] = {
+ [st_show ] {"show" , SW_SHOW },
+ [st_full ] {"full" , SW_MAXIMIZE},
+ [st_shade] {"shade", SW_SHOW },
+ [st_icon ] {"icon" , SW_MINIMIZE},
+ [st_hide ] {"hide" , SW_HIDE },
+ };
+ win->sys->state = state;
+ printf("sys_show: %s\n", map[state].str);
+ ShowWindow(win->sys->hwnd, map[state].cmd);
+}
+
+void sys_watch(win_t *win, Key_t key, mod_t mod)
+{
+ (void)key2w; // TODO
+ //printf("sys_watch: %p\n", win);
+}
+
+void sys_unwatch(win_t *win, Key_t key, mod_t mod)
+{
+ (void)key2w; // TODO
+ //printf("sys_unwatch: %p\n", win);
+}
+
+list_t *sys_info(win_t *win)
+{
+ if (screens == NULL)
+ EnumDisplayMonitors(NULL, NULL, MonProc, (LPARAM)&screens);
+ return screens;
+}
+