[doc] Add a bunch of documentation
[awesome.git] / layout.c
blobd899c7dd929ad780efc9e30da76de81b9ea33d74
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 <X11/Xatom.h>
23 #include <X11/Xutil.h>
25 #include "tag.h"
26 #include "focus.h"
27 #include "widget.h"
28 #include "window.h"
29 #include "client.h"
30 #include "screen.h"
31 #include "layouts/tile.h"
32 #include "layouts/max.h"
33 #include "layouts/fibonacci.h"
34 #include "layouts/floating.h"
36 extern AwesomeConf globalconf;
38 #include "layoutgen.h"
40 /** Arrange windows following current selected layout
41 * \param screen the screen to arrange
43 static void
44 arrange(int screen)
46 Client *c;
47 Layout *curlay = layout_get_current(screen);
48 unsigned int dui;
49 int di, x, y, phys_screen = screen_virttophys(screen);
50 Window rootwin, childwin;
52 for(c = globalconf.clients; c; c = c->next)
54 if(client_isvisible(c, screen) && !c->newcomer)
55 client_unban(c);
56 /* we don't touch other screens windows */
57 else if(c->screen == screen || c->newcomer)
58 client_ban(c);
61 curlay->arrange(screen);
63 for(c = globalconf.clients; c; c = c->next)
64 if(c->newcomer && client_isvisible(c, screen))
66 c->newcomer = False;
67 client_unban(c);
68 if(globalconf.screens[screen].new_get_focus && !c->skip)
69 client_focus(c, screen, True);
72 /* if we have a valid client that could be focused but currently no window
73 * are focused, then set the focus on this window */
74 if((c = focus_get_current_client(screen)) && !globalconf.focus->client)
75 client_focus(c, screen, True);
77 /* check that the mouse is on a window or not */
78 if(XQueryPointer(globalconf.display,
79 RootWindow(globalconf.display, phys_screen),
80 &rootwin, &childwin, &x, &y, &di, &di, &dui))
82 if(rootwin == None || childwin == None || childwin == rootwin)
83 window_root_grabbuttons(phys_screen);
85 globalconf.pointer_x = x;
86 globalconf.pointer_y = y;
89 /* reset status */
90 globalconf.screens[screen].need_arrange = False;
93 /** Refresh the screen disposition
94 * \return true if the screen was arranged, false otherwise
96 int
97 layout_refresh(void)
99 int screen;
100 int arranged = 0;
102 for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
103 if(globalconf.screens[screen].need_arrange)
105 arrange(screen);
106 arranged++;
109 return arranged;
112 /** Get current layout used on screen
113 * \param screen screen id
114 * \return layout used on that screen
116 Layout *
117 layout_get_current(int screen)
119 Tag **curtags = tags_get_current(screen);
120 Layout *l = curtags[0]->layout;
121 p_delete(&curtags);
122 return l;
125 /** Set layout for current tag.
126 * Argument must be a relative or absolute integer of available layouts.
127 * \param screen Screen ID
128 * \param arg Layout specifier
129 * \ingroup ui_callback
131 void
132 uicb_tag_setlayout(int screen, char *arg)
134 Layout *l = globalconf.screens[screen].layouts;
135 Tag *tag, **curtags;
136 int i;
138 if(arg)
140 curtags = tags_get_current(screen);
141 for(i = 0; l && l != curtags[0]->layout; i++, l = l->next);
142 p_delete(&curtags);
144 if(!l)
145 i = 0;
147 i = compute_new_value_from_arg(arg, (double) i);
149 if(i >= 0)
150 for(l = globalconf.screens[screen].layouts; l && i > 0; i--)
151 l = l->next;
152 else
153 for(l = globalconf.screens[screen].layouts; l && i < 0; i++)
154 l = layout_list_prev_cycle(&globalconf.screens[screen].layouts, l);
156 if(!l)
157 l = globalconf.screens[screen].layouts;
160 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
161 if(tag->selected)
162 tag->layout = l;
164 if(globalconf.focus->client)
165 arrange(screen);
167 widget_invalidate_cache(screen, WIDGET_CACHE_LAYOUTS);
170 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80