2 * Copyright (c) 2011, Andy Spencer <andy753421@gmail.com>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
39 split, stack, max, tab
46 /* Window structure types */
50 win_t *win; // the window
51 int height; // win height in _this_ tag
55 list_t *rows; // of row_t
56 row_t *row; // focused row
57 int width; // column width
58 mode_t mode; // display mode
62 win_t *win; // the window
63 int x, y, w, h; // position of window (in this tag)
67 list_t *cols; // of col_t
68 col_t *col; // focused col
69 list_t *flts; // of flt_t
70 flt_t *flt; // focused flt
71 layer_t layer; // focused layer
72 win_t *geom; // display size and position
76 list_t *dpys; // of dpy_t
77 dpy_t *dpy; // focused dpy
82 list_t *tags; // of tag_t
83 tag_t *tag; // focused tag
84 win_t *root; // root/background window
85 list_t *screens; // display geometry
88 #define WIN(node) ((win_t*)(node)->data)
89 #define ROW(node) ((row_t*)(node)->data)
90 #define COL(node) ((col_t*)(node)->data)
91 #define FLT(node) ((flt_t*)(node)->data)
92 #define DPY(node) ((dpy_t*)(node)->data)
93 #define TAG(node) ((tag_t*)(node)->data)
95 #define tag_foreach_col(tag, dpy, col, row, win) \
96 for (list_t *dpy = tag ->dpys; dpy; dpy = dpy->next) \
97 for (list_t *col = DPY(dpy)->cols; col; col = col->next) \
98 for (list_t *row = COL(col)->rows; row; row = row->next) \
99 for (win_t *win = ROW(row)->win; win; win = NULL)
101 #define tag_foreach_flt(tag, dpy, flt, win) \
102 for (list_t *dpy = tag ->dpys; dpy; dpy = dpy->next) \
103 for (list_t *flt = DPY(dpy)->flts; flt; flt = flt->next) \
104 for (win_t *win = FLT(flt)->win; win; win = NULL) \
106 /* Window management data
107 * wm_* macros represent the currently focused item
108 * _only_ wm_focus protects against NULL pointers */
110 #define wm_tag wm->tag
111 #define wm_dpy wm->tag->dpy
112 #define wm_col wm->tag->dpy->col
113 #define wm_row wm->tag->dpy->col->row
114 #define wm_flt wm->tag->dpy->flt
115 #define wm_focus get_focus()
117 /* Mouse drag data */
118 static drag_t move_mode;
119 static list_t *move_lrow;
120 static list_t *move_lcol;
121 static list_t *move_lflt;
122 static ptr_t move_prev;
123 static layer_t move_layer;
124 static struct { int v, h; } move_dir;
126 /********************
128 ********************/
129 static win_t *get_focus(void)
131 if (!wm_tag || !wm_dpy)
133 switch (wm_dpy->layer) {
135 return wm_col && wm_row ? wm_row->win : NULL;
137 return wm_flt ? wm_flt->win : NULL;
142 /* Search for the target window in a given tag
143 * win may exist in other tags as well */
144 static int searchl(tag_t *tag, win_t *target,
145 list_t **_dpy, list_t **_col, list_t **_row, list_t **_flt)
147 tag_foreach_col(tag, dpy, col, row, win) {
149 if (_dpy) *_dpy = dpy;
150 if (_col) *_col = col;
151 if (_row) *_row = row;
155 tag_foreach_flt(tag, dpy, flt, win) {
157 if (_dpy) *_dpy = dpy;
158 if (_flt) *_flt = flt;
165 static int search(tag_t *tag, win_t *target,
166 dpy_t **_dpy, col_t **_col, row_t **_row, flt_t **_flt)
168 list_t *dpy, *col, *row, *flt;
169 switch (searchl(tag, target, &dpy, &col, &row, &flt)) {
171 if (_dpy) *_dpy = DPY(dpy);
172 if (_col) *_col = COL(col);
173 if (_row) *_row = ROW(row);
176 if (_dpy) *_dpy = DPY(dpy);
177 if (_flt) *_flt = FLT(flt);
183 /* Set the mode for the windows column in the current tag */
184 static void set_mode(win_t *win, mode_t mode)
187 if (tiling != search(wm_tag, win, NULL, &col, NULL, NULL))
189 printf("set_mode: %p, %d -> %d\n",
190 col, col->mode, mode);
192 if (col->mode == split)
193 for (list_t *cur = col->rows; cur; cur = cur->next) {
194 row_t *row = cur->data;
195 row->height = wm_dpy->geom->h;
200 /* Focus the window in the current tag and record
201 * it as the currently focused window */
202 static void set_focus(win_t *win)
204 if (win == NULL || win == wm->root) {
209 /* - Only grab mouse button on unfocused window,
210 * this prevents stealing all mouse clicks from client windows,
211 * - A better way may be to re-send mouse clicks to client windows
212 * using the return value from wm_handle_key */
213 for (int i = key_mouse1; i < key_mouse7; i++) {
215 sys_watch(wm_focus, i, MOD());
216 sys_unwatch(win, i, MOD());
219 dpy_t *dpy; col_t *col; row_t *row; flt_t *flt;
220 switch (search(wm_tag, win, &dpy, &col, &row, &flt)) {
230 dpy->layer = floating;
236 /* Save mouse start location when moving/resizing windows */
237 static void set_move(win_t *win, ptr_t ptr, drag_t drag)
239 printf("set_move: %d - %p@%d,%d\n",
240 drag, win, ptr.rx, ptr.ry);
242 if (drag == move || drag == resize) {
243 move_layer = searchl(wm_tag, win, NULL,
244 &move_lcol, &move_lrow, &move_lflt);
248 int midy = win->y + (win->h/2);
249 int midx = win->x + (win->w/2);
250 move_dir.v = ptr.ry < midy ? -1 : +1;
251 move_dir.h = ptr.rx < midx ? -1 : +1;
255 /* Print a text representation of the window layout
256 * Quite useful for debugging */
257 static void print_txt(void)
259 for (list_t *ltag = wm->tags; ltag; ltag = ltag->next) {
260 tag_t *tag = ltag->data;
261 printf("tag: <%-9p [%p->%p] >%-9p d=%-9p - %d\n",
262 ltag->prev, ltag, ltag->data, ltag->next,
263 tag->dpy, tag->name);
264 for (list_t *ldpy = tag->dpys; ldpy; ldpy = ldpy->next) {
265 dpy_t *dpy = ldpy->data;
266 win_t *geom = dpy->geom;
267 printf(" dpy: <%-9p [%p->%p] >%-9p %c=%-9p - %d,%d %dx%d\n",
268 ldpy->prev, ldpy, ldpy->data, ldpy->next,
269 dpy->layer == tiling ? 'c' : 'f',
270 dpy->layer == tiling ? (void*)dpy->col : (void*)dpy->flt,
271 geom->x, geom->y, geom->h, geom->w);
272 for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next) {
273 col_t *col = lcol->data;
274 printf(" col: <%-9p [%p->%p] >%-9p r=%-9p - %dpx @ %d\n",
275 lcol->prev, lcol, lcol->data, lcol->next,
276 col->row, col->width, col->mode);
277 for (list_t *lrow = col->rows; lrow; lrow = lrow->next) {
278 row_t *row = lrow->data;
279 win_t *win = row->win;
280 printf(" win: <%-9p [%p>>%p] >%-9p focus=%d%d - %4dpx \n",
281 lrow->prev, lrow, win, lrow->next,
282 col->row == row, wm_focus == win, win->h);
284 for (list_t *lflt = dpy->flts; lflt; lflt = lflt->next) {
285 flt_t *flt = lflt->data;
286 win_t *win = flt->win;
287 printf(" flt: <%-9p [%p>>%p] >%-9p focus=%d%d - %d,%d %dx%d \n",
288 lflt->prev, lflt, win, lflt->next,
289 dpy->flt == flt, wm_focus == flt->win,
290 flt->x, flt->y, flt->h, flt->w);
294 /* Cleanly remove a window from a tag
295 * Determines the new focused row/col
296 * Prunes empty lists */
297 static layer_t cut_win(win_t *win, tag_t *tag)
299 list_t *ldpy, *lcol, *lrow, *lflt;
300 layer_t layer = searchl(tag, win, &ldpy, &lcol, &lrow, &lflt);
302 if (layer == tiling) {
303 dpy_t *dpy = DPY(ldpy);
304 col_t *col = COL(lcol);
305 col->row = lrow->prev ? lrow->prev->data :
306 lrow->next ? lrow->next->data : NULL;
307 col->rows = list_remove(col->rows, lrow, 1);
308 if (col->rows == NULL && (lcol->next || lcol->prev)) {
309 dpy->col = lcol->prev ? lcol->prev->data :
310 lcol->next ? lcol->next->data : NULL;
311 dpy->cols = list_remove(dpy->cols, lcol, 1);
315 if (layer == floating) {
316 dpy_t *dpy = DPY(ldpy);
317 dpy->flts = list_remove(dpy->flts, lflt, 1);
318 dpy->flt = dpy->flts ? list_last(dpy->flts)->data : NULL;
319 if (!dpy->flt && dpy->col && dpy->col->row)
326 /* Insert a window into the tiling layer
327 * The window is added immediately after the
328 * columns currently focused row */
329 static void put_win_col(win_t *win, tag_t *tag, dpy_t *dpy, col_t *col)
331 row_t *row = new0(row_t);
336 dpy->cols = list_insert(dpy->cols, col);
339 int nrows = list_length(col->rows);
341 list_t *prev = list_find(col->rows, col->row);
342 list_insert_after(prev, row);
344 col->rows = list_insert(col->rows, row);
348 tag->dpy->col->row = row;
349 tag->dpy->layer = tiling;
351 row->height = dpy->geom->h / MAX(nrows,1);
353 int ncols = list_length(dpy->cols);
354 col->width = dpy->geom->w / MAX(ncols-1,1);
358 /* Insert a window into the floating layer */
359 static void put_win_flt(win_t *win, tag_t *tag, dpy_t *dpy)
361 flt_t *flt = new0(flt_t);
363 flt->w = dpy->geom->w / 2;
364 flt->h = dpy->geom->h / 2;
365 flt->x = dpy->geom->x + flt->w / 2;
366 flt->y = dpy->geom->y + flt->h / 2;
368 flt->x = dpy->flt->x + 20;
369 flt->y = dpy->flt->y + 20;
371 dpy->flts = list_append(dpy->flts, flt);
374 tag->dpy->layer = floating;
377 /* Insert a window into a tag */
378 static void put_win(win_t *win, tag_t *tag, layer_t layer)
381 put_win_col(win, tag, tag->dpy, tag->dpy->col);
382 if (layer == floating)
383 put_win_flt(win, tag, tag->dpy);
386 /* Move a window up, down, left, or right
387 * This handles moving with a column, between
388 * columns, and between multiple monitors. */
389 static void shift_window(win_t *win, int col, int row)
392 printf("shift_window: %p - %+d,%+d\n", win, col, row);
394 printf("shift_window: >>>\n");
395 list_t *ldpy, *lcol, *lrow, *lflt;
396 if (tiling != searchl(wm_tag, win, &ldpy, &lcol, &lrow, &lflt))
398 dpy_t *dpy = ldpy->data;
400 /* Move with a column, just swap rows */
401 list_t *src = lrow, *dst = NULL;
402 if (row < 0) dst = src->prev;
403 if (row > 0) dst = src->next;
405 printf("swap: %p <-> %p\n", src->data, dst->data);
406 row_t *tmp = src->data;
407 src->data = dst->data;
412 /* Moving between columns */
413 int onlyrow = !lrow->prev && !lrow->next;
414 list_t *src = lcol, *dst = NULL;
417 /* Normal move between columns */
419 } else if (!onlyrow) {
420 /* Create new column */
421 dpy->cols = list_insert(dpy->cols, new0(col_t));
423 } else if (ldpy->prev) {
424 /* Move to next monitor */
425 dpy = ldpy->prev->data;
426 dst = list_last(dpy->cols);
428 /* We, shall, not, be,
429 * we shall not be moved */
436 } else if (!onlyrow) {
437 dpy->cols = list_append(dpy->cols, new0(col_t));
439 } else if (ldpy->next) {
440 dpy = ldpy->next->data;
446 cut_win(win, wm_tag);
447 put_win_col(win, wm_tag, dpy, dst ? dst->data : NULL);
455 /* Get next/prev item, with wraparound */
456 static list_t *get_next(list_t *list, int forward)
458 list_t *next = forward ? list->next : list->prev;
461 while ((list = forward ? next->prev : next->next))
467 /* Move keyboard focus in a given direction */
468 static void shift_focus(int cols, int rows)
470 printf("shift_focus: %+d,%+d\n", cols, rows);
471 if (rows != 0 && wm_focus) {
472 /* Move focus up/down */
473 list_t *dpy, *col, *row;
474 if (tiling != searchl(wm_tag, wm_focus, &dpy, &col, &row, NULL))
476 row_t *next = get_next(row, rows > 0)->data;
477 set_focus(next->win);
478 if (COL(col)->mode != split)
482 /* Move focus left/right */
483 list_t *dpy, *col, *row, *ndpy, *ncol = NULL;
485 /* Currently focused on a window */
486 if (tiling != searchl(wm_tag, wm_focus, &dpy, &col, &row, NULL))
488 ncol = cols > 0 ? col->next : col->prev;
490 /* Currently focused on an empty display */
491 dpy = list_find(wm_tag->dpys, wm_dpy);
494 /* Moving focus to a different display */
495 ndpy = get_next(dpy, cols > 0);
496 ncol = cols > 0 ? DPY(ndpy)->cols :
497 list_last(DPY(ndpy)->cols);
500 if (ncol && COL(ncol) && COL(ncol)->row)
501 set_focus(COL(ncol)->row->win);
507 /* Raise the window in the floating */
508 static void raise_float(win_t *win)
510 printf("raise_float: %p\n", win);
512 for (cur = wm_dpy->flts; cur; cur = cur->next)
513 if (FLT(cur)->win == win)
516 flt_t *flt = cur->data;
517 wm_dpy->flts = list_remove(wm_dpy->flts, cur, 0);
518 wm_dpy->flts = list_append(wm_dpy->flts, flt);
523 /* Toggle between floating and tiling layers */
524 static void switch_layer(void)
526 printf("switch_float: %p %d\n",
527 wm_dpy, wm_dpy->layer);
528 wm_dpy->layer = !wm_dpy->layer;
532 /* Move current window between floating and tiling layers */
533 static void set_layer(win_t *win)
536 printf("set_float: %p %p\n", wm_dpy, win);
537 wm_dpy->layer = !cut_win(win, wm_tag);
538 put_win(win, wm_tag, wm_dpy->layer);
542 /* Allocate a new tag */
543 static tag_t *tag_new(list_t *screens, int name)
545 tag_t *tag = new0(tag_t);
547 for (list_t *cur = screens; cur; cur = cur->next) {
548 dpy_t *dpy = new0(dpy_t);
549 dpy->geom = cur->data;
550 tag->dpys = list_append(tag->dpys, dpy);
552 tag->dpy = tag->dpys->data;
557 * If it does not exist it is based on the
558 * display geometry in wm->screens */
559 static tag_t *tag_find(int name)
562 for (list_t *cur = wm->tags; cur; cur = cur->next)
563 if (name == TAG(cur)->name) {
568 tag = tag_new(wm->screens, name);
569 wm->tags = list_append(wm->tags, tag);
574 /* Move the window from the current tag to the new tag
575 * Unlike wmii, only remove the current tag, not all tags */
576 static void tag_set(win_t *win, int name)
578 printf("tag_set: %p %d\n", win, name);
579 if (wm_tag->name == name)
581 tag_t *tag = tag_find(name);
582 layer_t layer = cut_win(win, wm_tag);
583 put_win(win, tag, layer);
587 /* Switch to a different tag */
588 static void tag_switch(int name)
590 printf("tag_switch: %d\n", name);
592 if ((wm_col == NULL || wm_row == NULL) && wm_flt == NULL) {
593 list_t *ltag = list_find(wm->tags, old);
594 wm->tags = list_remove(wm->tags, ltag, 1);
596 dpy_t *dpy = old->dpys->data;
598 dpy->cols = list_remove(dpy->cols, dpy->cols, 1);
599 old->dpys = list_remove(old->dpys, old->dpys, 1);
603 wm_tag = tag_find(name);
606 /* Tile all windows in the given display
607 * This performs all the actual window tiling
608 * Currently supports split, stack and maximized modes */
609 static void wm_update_cols(dpy_t *dpy)
611 int x=0, y=0; // Current window top-left position
612 int tx=0, ty=0; // Total size (sum of initial col widths and row heights w/o margin)
613 int mx=0, my=0; // Maximum usable size (screen size minus margins)
614 int sy=0; // Stack size (height of focused stack window)
616 /* Scale horizontally */
618 mx = dpy->geom->w - (list_length(dpy->cols)+1)*MARGIN;
619 for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next)
620 tx += COL(lcol)->width;
621 for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next)
622 COL(lcol)->width *= (float)mx / tx;
624 /* Scale each column vertically */
625 win_t *focus = get_focus();
626 for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next) {
627 col_t *col = lcol->data;
628 int nrows = list_length(col->rows);
630 for (list_t *lrow = col->rows; lrow; lrow = lrow->next)
631 ty += ROW(lrow)->height;
633 my = dpy->geom->h - (MARGIN + (nrows-1)* MARGIN + MARGIN);
634 sy = dpy->geom->h - (MARGIN + (nrows-1)*(MARGIN/2) + MARGIN)
636 for (list_t *lrow = col->rows; lrow; lrow = lrow->next) {
637 win_t *win = ROW(lrow)->win;
638 win->h = ROW(lrow)->height;
642 sys_move(win, x+MARGIN, y+MARGIN,
643 col->width, win->h * ((float)my / ty));
645 y += height + MARGIN;
648 if (lrow->next && ROW(lrow->next)->win == col->row->win) {
649 /* Hack to prevent flashing */
650 win_t *next = ROW(lrow->next)->win;
651 sys_move(next, x+MARGIN, y+MARGIN+STACK+MARGIN/2,
654 height = win == col->row->win ? sy : STACK;
655 sys_move(win, x+MARGIN, y+MARGIN,
657 y += height + (MARGIN/2);
661 sys_move(win, x+MARGIN, 0+MARGIN,
662 col->width, dpy->geom->h-2*MARGIN);
667 ROW(lrow)->height = win->h;
669 x += col->width + MARGIN;
673 /*******************************
674 * Window management functions *
675 *******************************/
679 tag_foreach_col(wm_tag, dpy, col, row, win)
680 sys_show(win, st_show);
681 tag_foreach_flt(wm_tag, dpy, flt, win)
682 sys_show(win, st_show);
683 for (list_t *tag = wm ->tags; tag; tag = tag->next)
684 if (tag->data != wm_tag) {
685 tag_foreach_col(TAG(tag), dpy, col, row, win)
686 sys_show(win, st_hide);
687 tag_foreach_flt(TAG(tag), dpy, flt, win)
688 sys_show(win, st_hide);
691 /* Refresh the display */
692 for (list_t *ldpy = wm_tag->dpys; ldpy; ldpy = ldpy->next)
693 wm_update_cols(ldpy->data);
694 tag_foreach_flt(wm_tag, ldpy, lflt, win) {
695 flt_t *flt = lflt->data;
696 sys_move(win, flt->x, flt->y, flt->w, flt->h);
703 int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr)
705 if (!win || win == wm_dpy->geom) return 0;
706 //printf("wm_handle_key: %p - %x %c%c%c%c%c\n", win, key,
707 // mod.up ? '^' : 'v',
708 // mod.alt ? 'a' : '-',
709 // mod.ctrl ? 'c' : '-',
710 // mod.shift ? 's' : '-',
711 // mod.win ? 'w' : '-');
714 if (key == key_mouse1)
716 if (key_mouse0 <= key && key <= key_mouse7) {
717 if (key == key_mouse1 && mod.MODKEY && !mod.up)
718 return set_move(win,ptr,move), 1;
719 if (key == key_mouse3 && mod.MODKEY && !mod.up)
720 return set_move(win,ptr,resize), 1;
721 if (move_mode != none && mod.up)
722 return set_move(win,ptr,none), 1;
723 if (key == key_mouse1 && !mod.up && win->h == STACK)
724 return wm_update(), 0;
728 /* Only handle key-down */
735 if (key == key_f1) return raise_float(win), 1;
736 if (key == key_f2) return set_focus(win), 1;
737 if (key == key_f3) return sys_show(win, st_show), 1;
738 if (key == key_f4) return sys_show(win, st_hide), 1;
740 if (key == key_f5) return wm_update(), 1;
741 if (key == key_f6) return print_txt(), 1;
746 if (mod.MODKEY && mod.shift)
747 return set_layer(win), 1;
749 return switch_layer(), 1;
752 /* Movement commands */
753 if (mod.MODKEY && mod.shift) {
755 case 'h': return shift_window(wm_focus,-1, 0), 1;
756 case 'j': return shift_window(wm_focus, 0,+1), 1;
757 case 'k': return shift_window(wm_focus, 0,-1), 1;
758 case 'l': return shift_window(wm_focus,+1, 0), 1;
762 else if (mod.MODKEY) {
764 case 'h': return shift_focus(-1, 0), 1;
765 case 'j': return shift_focus( 0,+1), 1;
766 case 'k': return shift_focus( 0,-1), 1;
767 case 'l': return shift_focus(+1, 0), 1;
772 /* Column mode commands */
775 case 'd': return set_mode(win, split), 1;
776 case 's': return set_mode(win, stack), 1;
777 case 'm': return set_mode(win, max), 1;
778 case 't': return set_mode(win, tab), 1;
784 if (mod.MODKEY && '0' <= key && key <= '9') {
785 int name = key - '0';
794 if (key == key_enter)
795 return set_focus(win), 1;
797 if (key_mouse0 <= key && key <= key_mouse7)
798 return set_focus(win), 0;
800 /* Reset focus after after focus change,
801 * not sure what is causing the focus change in the first place
802 * but preventing that would be a better solution */
803 if (key == key_focus)
804 sys_focus(wm_focus ?: wm->root);
809 int wm_handle_ptr(win_t *cwin, ptr_t ptr)
811 //printf("wm_handle_ptr: %p - %d,%d %d,%d (%d) -- \n",
812 // cwin, ptr.x, ptr.y, ptr.rx, ptr.ry, move_mode);
814 if (move_mode == none)
817 int dx = ptr.rx - move_prev.rx;
818 int dy = ptr.ry - move_prev.ry;
821 if (move_layer == tiling && move_mode == resize) {
822 list_t *vert = move_dir.v < 0 ? move_lrow->prev : move_lrow->next;
823 list_t *horz = move_dir.h < 0 ? move_lcol->prev : move_lcol->next;
825 ROW(move_lrow)->height += move_dir.v * dy;
826 ROW(vert)->height -= move_dir.v * dy;
829 COL(move_lcol)->width += move_dir.h * dx;
830 COL(horz)->width -= move_dir.h * dx;
835 if (move_layer == floating) {
836 flt_t *flt = move_lflt->data;
837 win_t *win = flt->win;
838 if (move_mode == move)
839 sys_move(win, win->x+dx, win->y+dy, win->w, win->h);
840 else if (move_mode == resize)
842 win->x + dx * (move_dir.h < 0),
843 win->y + dy * (move_dir.v < 0),
844 win->w + dx * move_dir.h,
845 win->h + dy * move_dir.v);
846 flt->x = win->x; flt->y = win->y;
847 flt->w = win->w; flt->h = win->h;
853 void wm_insert(win_t *win)
855 printf("wm_insert: %p\n", win);
858 /* Initialize window */
859 win->wm = new0(win_wm_t);
860 sys_watch(win, key_enter, MOD());
861 sys_watch(win, key_focus, MOD());
864 put_win(win, wm_tag, wm_dpy->layer);
872 void wm_remove(win_t *win)
874 printf("wm_remove: %p\n", win);
876 for (list_t *tag = wm->tags; tag; tag = tag->next)
877 cut_win(win, tag->data);
884 void wm_init(win_t *root)
886 printf("wm_init: %p\n", root);
888 /* Hack, fix screen order */
889 list_t *screens = sys_info(root);
890 list_t *left = screens;
891 list_t *right = screens->next;
892 if (left && right && WIN(left)->x > WIN(right)->x) {
893 void *tmp = left->data;
894 left->data = right->data;
900 wm->screens = screens;
901 wm->tag = tag_new(wm->screens, 1);
902 wm->tags = list_insert(NULL, wm->tag);
904 Key_t keys_e[] = {key_enter, key_focus};
905 Key_t keys_s[] = {'h', 'j', 'k', 'l', ' ',
906 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
907 Key_t keys_m[] = {'h', 'j', 'k', 'l', 'd', 's', 'm', 't', ' ',
908 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
909 key_f1, key_f2, key_f3, key_f4, key_f5, key_f6,
910 key_mouse1, key_mouse3};
911 for (int i = 0; i < countof(keys_e); i++)
912 sys_watch(root, keys_e[i], MOD());
913 for (int i = 0; i < countof(keys_m); i++)
914 sys_watch(root, keys_m[i], MOD(.MODKEY=1));
915 for (int i = 0; i < countof(keys_s); i++)
916 sys_watch(root, keys_s[i], MOD(.MODKEY=1,.shift=1));