rename uicb_togglefloating to uicb_client_togglefloating
[awesome.git] / tag.c
blobd1c3de9aff07b5d3a40a091a0898e56fc10b7db4
1 /*
2 * tag.c - tag management
4 * Copyright © 2007 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 <stdio.h>
23 #include <X11/Xutil.h>
25 #include "screen.h"
26 #include "layout.h"
27 #include "tag.h"
28 #include "util.h"
29 #include "rules.h"
31 /** Returns True if a client is tagged
32 * with one of the tags
33 * \param c Client
34 * \param tags tag to check
35 * \param ntags number of tags in *tags
36 * \return True or False
38 Bool
39 isvisible(Client * c, int screen, Tag * tags, int ntags)
41 int i;
43 if(c->screen != screen)
44 return False;
46 for(i = 0; i < ntags; i++)
47 if(c->tags[i] && tags[i].selected)
48 return True;
49 return False;
52 void
53 tag_client_with_current_selected(Client *c, awesome_config *awesomeconf)
55 int i;
57 p_realloc(&c->tags, awesomeconf->ntags);
58 for(i = 0; i < awesomeconf->ntags; i++)
59 c->tags[i] = awesomeconf->tags[i].selected;
62 /** Tag selected window with tag
63 * \param arg Tag name
64 * \ingroup ui_callback
66 void
67 uicb_client_tag(awesome_config *awesomeconf,
68 const char *arg)
70 int i;
71 Client *sel = get_current_tag(awesomeconf->tags, awesomeconf->ntags)->client_sel;
73 if(!sel)
74 return;
76 for(i = 0; i < awesomeconf->ntags; i++)
77 sel->tags[i] = arg == NULL;
79 i = arg ? atoi(arg) - 1 : 0;
81 if(i >= 0 && i < awesomeconf->ntags)
82 sel->tags[i] = True;
84 saveprops(sel, awesomeconf->ntags);
85 arrange(awesomeconf);
88 /** Toggle floating state of a client
89 * \param arg unused
90 * \ingroup ui_callback
92 void
93 uicb_client_togglefloating(awesome_config * awesomeconf,
94 const char *arg __attribute__ ((unused)))
96 Client *sel = get_current_tag(awesomeconf->tags, awesomeconf->ntags)->client_sel;
98 if(!sel)
99 return;
101 sel->isfloating = !sel->isfloating;
103 if (arg == NULL)
104 client_resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, awesomeconf, True, False);
105 else
106 client_resize(sel, sel->x, sel->y, sel->w, sel->h, awesomeconf, True, True);
108 saveprops(sel, awesomeconf->ntags);
109 arrange(awesomeconf);
112 /** Toggle tag view
113 * \param arg Tag name
114 * \ingroup ui_callback
116 void
117 uicb_toggletag(awesome_config *awesomeconf,
118 const char *arg)
120 Client *sel = get_current_tag(awesomeconf->tags, awesomeconf->ntags)->client_sel;
121 unsigned int i;
122 int j;
124 if(!sel)
125 return;
126 i = arg ? atoi(arg) - 1 : 0;
127 sel->tags[i] = !sel->tags[i];
128 for(j = 0; j < awesomeconf->ntags && !sel->tags[j]; j++);
129 if(j == awesomeconf->ntags)
130 sel->tags[i] = True;
131 saveprops(sel, awesomeconf->ntags);
132 arrange(awesomeconf);
135 /** Add a tag to viewed tags
136 * \param arg Tag name
137 * \ingroup ui_callback
139 void
140 uicb_toggleview(awesome_config *awesomeconf,
141 const char *arg)
143 unsigned int i;
144 int j;
146 i = arg ? atoi(arg) - 1: 0;
147 awesomeconf->tags[i].selected = !awesomeconf->tags[i].selected;
148 for(j = 0; j < awesomeconf->ntags && !awesomeconf->tags[j].selected; j++);
149 if(j == awesomeconf->ntags)
150 awesomeconf->tags[i].selected = True;
151 saveawesomeprops(awesomeconf);
152 arrange(awesomeconf);
155 /** View tag
156 * \param awesomeconf awesome config ref
157 * \param arg tag to view
158 * \ingroup ui_callback
160 void
161 uicb_view(awesome_config *awesomeconf,
162 const char *arg)
164 int i;
166 for(i = 0; i < awesomeconf->ntags; i++)
168 awesomeconf->tags[i].was_selected = awesomeconf->tags[i].selected;
169 awesomeconf->tags[i].selected = arg == NULL;
172 if(arg)
174 i = atoi(arg) - 1;
175 if(i >= 0 && i < awesomeconf->ntags)
176 awesomeconf->tags[i].selected = True;
179 saveawesomeprops(awesomeconf);
180 arrange(awesomeconf);
183 /** View previously selected tags
184 * \param awesomeconf awesome config ref
185 * \param arg unused
186 * \ingroup ui_callback
188 void
189 uicb_tag_prev_selected(awesome_config *awesomeconf,
190 const char *arg __attribute__ ((unused)))
192 int i;
193 Bool t;
195 for(i = 0; i < awesomeconf->ntags; i++)
197 t = awesomeconf->tags[i].selected;
198 awesomeconf->tags[i].selected = awesomeconf->tags[i].was_selected;
199 awesomeconf->tags[i].was_selected = t;
201 arrange(awesomeconf);
204 /** View next tag
205 * \param arg unused
206 * \ingroup ui_callback
208 void
209 uicb_tag_viewnext(awesome_config *awesomeconf,
210 const char *arg __attribute__ ((unused)))
212 int i;
213 int firsttag = -1;
215 for(i = 0; i < awesomeconf->ntags; i++)
217 if(firsttag < 0 && awesomeconf->tags[i].selected)
218 firsttag = i;
219 awesomeconf->tags[i].selected = False;
221 if(++firsttag >= awesomeconf->ntags)
222 firsttag = 0;
223 awesomeconf->tags[firsttag].selected = True;
224 saveawesomeprops(awesomeconf);
225 arrange(awesomeconf);
228 /** View previous tag
229 * \param arg unused
230 * \ingroup ui_callback
232 void
233 uicb_tag_viewprev(awesome_config *awesomeconf,
234 const char *arg __attribute__ ((unused)))
236 int i;
237 int firsttag = -1;
239 for(i = awesomeconf->ntags - 1; i >= 0; i--)
241 if(firsttag < 0 && awesomeconf->tags[i].selected)
242 firsttag = i;
243 awesomeconf->tags[i].selected = False;
245 if(--firsttag < 0)
246 firsttag = awesomeconf->ntags - 1;
247 awesomeconf->tags[firsttag].selected = True;
248 saveawesomeprops(awesomeconf);
249 arrange(awesomeconf);
251 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99