luaaA: add luaA_unregister()
[awesome.git] / layout.c
blob20661afd080da836c94f50480af42ee0240d39b2
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 lua_pushnumber(globalconf.L, screen + 1);
76 luaA_dofunction(globalconf.L, globalconf.hooks.arrange, 1, 0);
79 /** Refresh the screen disposition
80 * \return true if the screen was arranged, false otherwise
82 void
83 layout_refresh(void)
85 int screen;
87 for(screen = 0; screen < globalconf.nscreen; screen++)
88 if(globalconf.screens[screen].need_arrange)
89 arrange(screen);
92 /** Get current layout used on screen.
93 * \param screen Virtual screen number.
94 * \return layout used on that screen
96 layout_t *
97 layout_get_current(int screen)
99 layout_t *l = NULL;
100 tag_t **curtags = tags_get_current(screen);
102 if(curtags[0])
103 l = curtags[0]->layout;
104 p_delete(&curtags);
106 return l;
109 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80