[client] Add client_redraw (FS#170)
[awesome.git] / layout.c
blob0f3e2c94420c90a591d6302e9dfdcbaae629d03e
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 <xcb/xcb.h>
23 #include <xcb/xcb_atom.h>
24 #include <xcb/xcb_aux.h>
26 #include "tag.h"
27 #include "focus.h"
28 #include "widget.h"
29 #include "window.h"
30 #include "client.h"
31 #include "screen.h"
32 #include "layouts/tile.h"
33 #include "layouts/max.h"
34 #include "layouts/fibonacci.h"
35 #include "layouts/floating.h"
37 extern AwesomeConf globalconf;
39 #include "layoutgen.h"
41 /** Arrange windows following current selected layout
42 * \param screen the screen to arrange
44 static void
45 arrange(int screen)
47 client_t *c;
48 Layout *curlay = layout_get_current(screen);
49 int phys_screen = screen_virttophys(screen);
50 xcb_query_pointer_cookie_t qp_c;
51 xcb_query_pointer_reply_t *qp_r;
53 for(c = globalconf.clients; c; c = c->next)
55 if(client_isvisible(c, screen) && !c->newcomer)
56 client_unban(c);
57 /* we don't touch other screens windows */
58 else if(c->screen == screen || c->newcomer)
59 client_ban(c);
62 curlay->arrange(screen);
64 for(c = globalconf.clients; c; c = c->next)
65 if(c->newcomer && client_isvisible(c, screen))
67 c->newcomer = false;
68 client_unban(c);
69 if(globalconf.screens[screen].new_get_focus
70 && !c->skip
71 && (!globalconf.focus->client || !globalconf.focus->client->ismax))
72 client_focus(c, screen, true);
73 else if(globalconf.focus->client && globalconf.focus->client->ismax)
74 client_stack(globalconf.focus->client);
77 /* if we have a valid client that could be focused but currently no window
78 * are focused, then set the focus on this window */
79 if((c = focus_get_current_client(screen)) && globalconf.focus->client != c)
80 client_focus(c, screen, true);
82 qp_c = xcb_query_pointer_unchecked(globalconf.connection,
83 xcb_aux_get_screen(globalconf.connection,
84 phys_screen)->root);
86 /* check that the mouse is on a window or not */
87 if((qp_r = xcb_query_pointer_reply(globalconf.connection, qp_c, NULL)))
89 if(qp_r->root == XCB_NONE || qp_r->child == XCB_NONE || qp_r->root == qp_r->child)
90 window_root_grabbuttons(phys_screen);
92 globalconf.pointer_x = qp_r->root_x;
93 globalconf.pointer_y = qp_r->root_y;
94 p_delete(&qp_r);
97 /* reset status */
98 globalconf.screens[screen].need_arrange = false;
101 /** Refresh the screen disposition
102 * \return true if the screen was arranged, false otherwise
105 layout_refresh(void)
107 int screen;
108 int arranged = 0;
110 for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
111 if(globalconf.screens[screen].need_arrange)
113 arrange(screen);
114 arranged++;
117 return arranged;
120 /** Get current layout used on screen
121 * \param screen screen id
122 * \return layout used on that screen
124 Layout *
125 layout_get_current(int screen)
127 tag_t **curtags = tags_get_current(screen);
128 Layout *l = curtags[0]->layout;
129 p_delete(&curtags);
130 return l;
133 /** Set the layout of the current tag.
134 * Argument must be a relative or absolute integer of available layouts.
135 * \param screen Screen ID
136 * \param arg Layout specifier
137 * \ingroup ui_callback
139 void
140 uicb_tag_setlayout(int screen, char *arg)
142 Layout *l = globalconf.screens[screen].layouts;
143 tag_t *tag, **curtags;
144 int i;
146 if(arg)
148 curtags = tags_get_current(screen);
149 for(i = 0; l && l != curtags[0]->layout; i++, l = l->next);
150 p_delete(&curtags);
152 if(!l)
153 i = 0;
155 i = compute_new_value_from_arg(arg, (double) i);
157 if(i >= 0)
158 for(l = globalconf.screens[screen].layouts; l && i > 0; i--)
159 l = l->next;
160 else
161 for(l = globalconf.screens[screen].layouts; l && i < 0; i++)
162 l = layout_list_prev_cycle(&globalconf.screens[screen].layouts, l);
164 if(!l)
165 l = globalconf.screens[screen].layouts;
168 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
169 if(tag->selected)
170 tag->layout = l;
172 if(globalconf.focus->client)
173 arrange(screen);
175 widget_invalidate_cache(screen, WIDGET_CACHE_LAYOUTS);
178 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80