awesomerc: use byidx()
[awesome.git] / layout.c
blobe7ac8848ff91456b8dca12a08de2924b0f4151e1
1 /*
2 * layout.c - layout management
4 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "client.h"
23 #include "tag.h"
24 #include "window.h"
25 #include "screen.h"
27 extern awesome_t globalconf;
29 /** Arrange windows following current selected layout
30 * \param screen the screen to arrange
32 static void
33 arrange(int screen)
35 client_t *c;
36 layout_t *curlay = layout_get_current(screen);
37 int phys_screen = screen_virttophys(screen);
38 xcb_query_pointer_cookie_t qp_c;
39 xcb_query_pointer_reply_t *qp_r;
41 for(c = globalconf.clients; c; c = c->next)
43 if(client_isvisible(c, screen))
44 client_unban(c);
45 /* we don't touch other screens windows */
46 else if(c->screen == screen)
47 client_ban(c);
50 if(curlay)
51 curlay(screen);
53 qp_c = xcb_query_pointer_unchecked(globalconf.connection,
54 xutil_screen_get(globalconf.connection,
55 phys_screen)->root);
57 /* check that the mouse is on a window or not */
58 if((qp_r = xcb_query_pointer_reply(globalconf.connection, qp_c, NULL)))
60 if(qp_r->child == XCB_NONE || qp_r->root == qp_r->child)
61 window_root_buttons_grab(qp_r->root);
62 else if ((c = client_getbywin(qp_r->child)))
63 window_buttons_grab(c->win, qp_r->root, &c->buttons);
65 globalconf.pointer_x = qp_r->root_x;
66 globalconf.pointer_y = qp_r->root_y;
68 p_delete(&qp_r);
71 /* reset status */
72 globalconf.screens[screen].need_arrange = false;
74 /* call hook */
75 if(globalconf.hooks.arrange != LUA_REFNIL)
77 lua_pushnumber(globalconf.L, screen + 1);
78 luaA_dofunction(globalconf.L, globalconf.hooks.arrange, 1, 0);
82 /** Refresh the screen disposition
83 * \return true if the screen was arranged, false otherwise
85 void
86 layout_refresh(void)
88 int screen;
90 for(screen = 0; screen < globalconf.nscreen; screen++)
91 if(globalconf.screens[screen].need_arrange)
92 arrange(screen);
95 /** Get current layout used on screen.
96 * \param screen Virtual screen number.
97 * \return layout used on that screen
99 layout_t *
100 layout_get_current(int screen)
102 layout_t *l = NULL;
103 tag_t **curtags = tags_get_current(screen);
105 if(curtags[0])
106 l = curtags[0]->layout;
107 p_delete(&curtags);
109 return l;
112 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80