]> Pileus Git - wmpus/commitdiff
Add Win32 support for tags and multiple monitors
authorAndy Spencer <andy753421@gmail.com>
Mon, 26 Sep 2011 07:54:59 +0000 (07:54 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 26 Sep 2011 08:24:22 +0000 (08:24 +0000)
makefile
sys-win32.c
sys-x11.c
wm-wmii.c

index d629e6ed4f3f8185324d4cad5aa1fe2a13d8d493..4900ee57be91ce841559a82000438fd35a726469 100644 (file)
--- a/makefile
+++ b/makefile
@@ -26,7 +26,7 @@ debug: $(PROG)
 $(PROG): main.o util.o sys-$(SYS).o wm-$(WM).o
        $(CC) $(CFLAGS) -o $@ $+ $(LIBS)
 
-%.o: %.c $(wildcard *.h)
+%.o: %.c $(wildcard *.h) makefile
        $(CC) --std=gnu99 $(CFLAGS) -c -o $@ $<
 
 clean:
index 4a5e8318becc5e349b1e6c580186390e22f03b2c..1bc8a6cd48ab8182016b432d6fcc99ae8f67f35f 100644 (file)
@@ -16,6 +16,7 @@
 /* Internal structures */
 struct win_sys {
        HWND hwnd;
+       state_t state;
 };
 
 typedef struct {
@@ -214,7 +215,8 @@ LRESULT CALLBACK ShlProc(int msg, WPARAM wParam, LPARAM lParam)
                return 1;
        case HSHELL_WINDOWDESTROYED:
                printf("ShlProc: %p - window destroyed\n", hwnd);
-               if ((win = win_find(hwnd,0))) {
+               if ((win = win_find(hwnd,0)) &&
+                   win->sys->state == st_show) {
                        wm_remove(win);
                        win_remove(win);
                }
@@ -249,7 +251,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 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 = MAX(x,0); win->y = MAX(y,0);
+       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);
 }
@@ -279,6 +281,23 @@ void sys_focus(win_t *win)
        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
@@ -291,6 +310,31 @@ void sys_unwatch(win_t *win, Key_t key, mod_t mod)
        printf("sys_unwatch: %p\n", win);
 }
 
+BOOL CALLBACK Mon(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;
+}
+
+list_t *sys_info(win_t *win)
+{
+       list_t *screens = NULL;
+       EnumDisplayMonitors(NULL, NULL, Mon, (LPARAM)&screens);
+       return screens;
+}
+
 win_t *sys_init(void)
 {
        HINSTANCE hInst = GetModuleHandle(NULL);
index 6290f80acbff90a91e29d293ed4e9303a8cd3c0b..dc22fba6ecf9bdc1b9102639d97399e9ce22fb86 100644 (file)
--- a/sys-x11.c
+++ b/sys-x11.c
@@ -388,7 +388,7 @@ 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);
        int b = 2*BORDER;
-       win->x = MAX(x,0);   win->y = MAX(y,0);
+       win->x = x; win->y = y;
        win->w = MAX(w,1+b); win->h = MAX(h,1+b);
        w      = MAX(w-b,1); h      = MAX(h-b,1);
        XMoveResizeWindow(win->sys->dpy, win->sys->xid, x, y, w, h);
index 4a6c0245e1fb789644f856dc297cce3caa1253a4..2d5daba079530a5eda421e432933ed3963191ee9 100644 (file)
--- a/wm-wmii.c
+++ b/wm-wmii.c
@@ -69,6 +69,7 @@ static wm_t  *wm;
 #define wm_tag   wm->tag
 #define wm_focus (wm_tag && wm_dpy && wm_col && wm_row ? wm_win : NULL)
 
+#define WIN(l) ((win_t*)(l)->data)
 #define ROW(l) ((row_t*)(l)->data)
 #define COL(l) ((col_t*)(l)->data)
 #define DPY(l) ((dpy_t*)(l)->data)
@@ -471,7 +472,7 @@ int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr)
                if (key == key_f3) return sys_show(win, st_show), 1;
                if (key == key_f4) return sys_show(win, st_hide), 1;
                if (key == key_f5) return wm_update(),    1;
-               if (key == key_f6) return print_txt(), 1;
+               if (key == key_f6) return print_txt(),    1;
        }
        if (key_mouse0 <= key && key <= key_mouse7)
                sys_raise(win);
@@ -611,9 +612,19 @@ void wm_init(win_t *root)
 {
        printf("wm_init: %p\n", root);
 
+       /* Hack, fix screen order */
+       list_t *screens = sys_info(root);
+       list_t *left  = screens;
+       list_t *right = screens->next;
+       if (left && right && WIN(left)->x > WIN(right)->x) {
+               void *tmp   = left->data;
+               left->data  = right->data;
+               right->data = tmp;
+       }
+
        wm          = new0(wm_t);
        wm->root    = root;
-       wm->screens = sys_info(root);
+       wm->screens = screens;
        wm->tag     = tag_new(wm->screens, 1);
        wm->tags    = list_insert(NULL, wm->tag);
 
@@ -622,7 +633,7 @@ void wm_init(win_t *root)
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        Key_t keys_m[] = {'h', 'j', 'k', 'l', 'd', 's', 'm', 't',
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
-               key_f1, key_f2, key_f3, key_f4, key_f5, key_f6,
+               /*key_f1, key_f2, key_f3, key_f4,*/ key_f5, key_f6,
                key_mouse1, key_mouse3};
        for (int i = 0; i < countof(keys_e); i++)
                sys_watch(root, keys_e[i],  MOD());