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.
23 #include <X11/Xutil.h>
32 extern AwesomeConf globalconf
;
35 detach_tagclientlink(TagClientLink
*tc
)
39 if(globalconf
.tclink
== tc
)
40 globalconf
.tclink
= tc
->next
;
43 for(tmp
= globalconf
.tclink
; tmp
&& tmp
->next
!= tc
; tmp
= tmp
->next
);
51 tag_client(Client
*c
, Tag
*t
)
53 TagClientLink
*tc
, *new_tc
;
56 if(is_client_tagged(c
, t
))
59 new_tc
= p_new(TagClientLink
, 1);
61 if(!globalconf
.tclink
)
62 globalconf
.tclink
= new_tc
;
65 for(tc
= globalconf
.tclink
; tc
->next
; tc
= tc
->next
);
74 untag_client(Client
*c
, Tag
*t
)
78 for(tc
= globalconf
.tclink
; tc
; tc
= tc
->next
)
79 if(tc
->client
== c
&& tc
->tag
== t
)
80 detach_tagclientlink(tc
);
84 is_client_tagged(Client
*c
, Tag
*t
)
91 for(tc
= globalconf
.tclink
; tc
; tc
= tc
->next
)
92 if(tc
->client
== c
&& tc
->tag
== t
)
99 tag_client_with_current_selected(Client
*c
)
102 VirtScreen vscreen
= globalconf
.screens
[c
->screen
];
104 for(tag
= vscreen
.tags
; tag
; tag
= tag
->next
)
108 untag_client(c
, tag
);
112 tag_client_with_rules(Client
*c
)
116 Bool matched
= False
;
118 for(r
= globalconf
.rules
; r
; r
= r
->next
)
119 if(client_match_rule(c
, r
))
121 c
->isfloating
= r
->isfloating
;
123 if(r
->screen
!= RULE_NOSCREEN
&& r
->screen
!= c
->screen
)
124 move_client_to_screen(c
, r
->screen
, True
);
126 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
127 if(is_tag_match_rules(tag
, r
))
133 untag_client(c
, tag
);
136 tag_client_with_current_selected(c
);
143 get_current_tags(int screen
)
145 Tag
*tag
, **tags
= NULL
;
148 tags
= p_new(Tag
*, n
);
149 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
152 p_realloc(&tags
, ++n
);
156 /* finish with null */
162 /** Tag selected window with tag
163 * \param screen Screen ID
164 * \param arg Tag name
165 * \ingroup ui_callback
168 uicb_client_tag(int screen
, char *arg
)
171 Tag
*tag
, *target_tag
;
172 Client
*sel
= globalconf
.focus
->client
;
179 tag_id
= atoi(arg
) - 1;
182 for(target_tag
= globalconf
.screens
[screen
].tags
; target_tag
&& tag_id
> 0;
183 target_tag
= target_tag
->next
, tag_id
--);
186 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
187 untag_client(sel
, tag
);
188 tag_client(sel
, target_tag
);
193 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
194 tag_client(sel
, tag
);
196 client_saveprops(sel
, screen
);
200 /** Toggle floating state of a client
201 * \param screen Screen ID
203 * \ingroup ui_callback
206 uicb_client_togglefloating(int screen
, char *arg
__attribute__ ((unused
)))
208 Client
*sel
= globalconf
.focus
->client
;
213 sel
->isfloating
= !sel
->isfloating
;
216 client_resize(sel
, sel
->rx
, sel
->ry
, sel
->rw
, sel
->rh
, True
, False
);
218 client_resize(sel
, sel
->x
, sel
->y
, sel
->w
, sel
->h
, True
, True
);
220 client_saveprops(sel
, screen
);
224 /** Toggle a tag on client
225 * \param screen Screen ID
226 * \param arg Tag name
227 * \ingroup ui_callback
230 uicb_client_toggletag(int screen
, char *arg
)
232 Client
*sel
= globalconf
.focus
->client
;
234 Tag
*tag
, *target_tag
;
242 for(target_tag
= globalconf
.screens
[screen
].tags
; target_tag
&& i
> 0;
243 target_tag
= target_tag
->next
, i
--);
246 if(is_client_tagged(sel
, target_tag
))
247 untag_client(sel
, target_tag
);
249 tag_client(sel
, target_tag
);
252 /* check that there's at least one tag selected for this client*/
253 for(tag
= globalconf
.screens
[screen
].tags
; tag
254 && !is_client_tagged(sel
, tag
); tag
= tag
->next
)
257 tag_client(sel
, target_tag
);
260 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
261 if(is_client_tagged(sel
, tag
))
262 tag_client(sel
, tag
);
264 untag_client(sel
, tag
);
266 client_saveprops(sel
, screen
);
270 /** Add a tag to viewed tags
271 * \param screen Screen ID
272 * \param arg Tag name
273 * \ingroup ui_callback
276 uicb_tag_toggleview(int screen
, char *arg
)
279 Tag
*tag
, *target_tag
;
284 for(target_tag
= globalconf
.screens
[screen
].tags
; target_tag
&& i
> 0;
285 target_tag
= target_tag
->next
, i
--);
288 target_tag
->selected
= !target_tag
->selected
;
290 /* check that there's at least one tag selected */
291 for(tag
= globalconf
.screens
[screen
].tags
; tag
&& !tag
->selected
; tag
= tag
->next
);
293 target_tag
->selected
= True
;
296 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
297 tag
->selected
= !tag
->selected
;
299 saveawesomeprops(screen
);
301 ewmh_update_net_current_desktop(get_phys_screen(screen
));
305 * \param screen Screen ID
306 * \param arg tag to view
307 * \ingroup ui_callback
310 uicb_tag_view(int screen
, char *arg
)
313 Tag
*tag
, *target_tag
;
318 for(target_tag
= globalconf
.screens
[screen
].tags
; target_tag
&& i
> 0;
319 target_tag
= target_tag
->next
, i
--);
322 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
323 tag
->selected
= False
;
324 target_tag
->selected
= True
;
328 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
329 tag
->selected
= True
;
331 saveawesomeprops(screen
);
333 ewmh_update_net_current_desktop(get_phys_screen(screen
));
336 /** View previously selected tags
337 * \param screen Screen ID
339 * \ingroup ui_callback
342 uicb_tag_prev_selected(int screen
, char *arg
__attribute__ ((unused
)))
347 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
350 tag
->selected
= tag
->was_selected
;
351 tag
->was_selected
= t
;
354 ewmh_update_net_current_desktop(get_phys_screen(screen
));
358 * \param screen Screen ID
360 * \ingroup ui_callback
363 uicb_tag_viewnext(int screen
, char *arg
__attribute__ ((unused
)))
365 Tag
**curtags
= get_current_tags(screen
);
367 if(!curtags
[0]->next
)
370 curtags
[0]->selected
= False
;
371 curtags
[0]->next
->selected
= True
;
375 saveawesomeprops(screen
);
377 ewmh_update_net_current_desktop(get_phys_screen(screen
));
380 /** View previous tag
381 * \param screen Screen ID
383 * \ingroup ui_callback
386 uicb_tag_viewprev(int screen
, char *arg
__attribute__ ((unused
)))
388 Tag
*tag
, **curtags
= get_current_tags(screen
);
390 for(tag
= globalconf
.screens
[screen
].tags
; tag
&& tag
->next
!= curtags
[0]; tag
= tag
->next
);
393 tag
->selected
= True
;
394 curtags
[0]->selected
= False
;
395 saveawesomeprops(screen
);
399 ewmh_update_net_current_desktop(get_phys_screen(screen
));
401 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80