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>
30 applyrules(Client
* c
, awesome_config
*awesomeconf
)
35 XClassHint ch
= { 0, 0 };
38 XGetClassHint(c
->display
, c
->win
, &ch
);
40 len
= a_strlen(ch
.res_class
) + a_strlen(ch
.res_name
) + a_strlen(c
->name
);
42 prop
= p_new(char, len
+ 3);
45 snprintf(prop
, len
+ 3, "%s:%s:%s",
46 ch
.res_class
? ch
.res_class
: "", ch
.res_name
? ch
.res_name
: "", c
->name
);
47 for(i
= 0; i
< awesomeconf
->nrules
; i
++)
48 if(awesomeconf
->rules
[i
].propregex
&& !regexec(awesomeconf
->rules
[i
].propregex
, prop
, 1, &tmp
, 0))
50 c
->isfloating
= awesomeconf
->rules
[i
].isfloating
;
51 for(j
= 0; awesomeconf
->rules
[i
].tagregex
&& j
< awesomeconf
->ntags
; j
++)
52 if(!regexec(awesomeconf
->rules
[i
].tagregex
, awesomeconf
->tags
[j
].name
, 1, &tmp
, 0))
66 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
67 c
->tags
[i
] = awesomeconf
->tags
[i
].selected
;
71 compileregs(Rule
* rules
, int nrules
)
76 for(i
= 0; i
< nrules
; i
++)
80 reg
= p_new(regex_t
, 1);
81 if(regcomp(reg
, rules
[i
].prop
, REG_EXTENDED
))
84 rules
[i
].propregex
= reg
;
88 reg
= p_new(regex_t
, 1);
89 if(regcomp(reg
, rules
[i
].tags
, REG_EXTENDED
))
92 rules
[i
].tagregex
= reg
;
98 /** Returns True if a client is tagged
99 * with one of the tags
101 * \param tags tag to check
102 * \param ntags number of tags in *tags
103 * \return True or False
106 isvisible(Client
* c
, int screen
, Tag
* tags
, int ntags
)
110 if(c
->screen
!= screen
)
113 for(i
= 0; i
< ntags
; i
++)
114 if(c
->tags
[i
] && tags
[i
].selected
)
120 /** Tag selected window with tag
121 * \param arg Tag name
122 * \ingroup ui_callback
125 uicb_tag(awesome_config
*awesomeconf
,
129 Client
*sel
= get_current_tag(awesomeconf
->tags
, awesomeconf
->ntags
)->client_sel
;
134 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
135 sel
->tags
[i
] = arg
== NULL
;
137 i
= arg
? atoi(arg
) - 1 : 0;
139 if(i
>= 0 && i
< awesomeconf
->ntags
)
142 saveprops(sel
, awesomeconf
->ntags
);
143 arrange(awesomeconf
);
146 /** Toggle floating state of a client
148 * \ingroup ui_callback
151 uicb_togglefloating(awesome_config
* awesomeconf
,
152 const char *arg
__attribute__ ((unused
)))
154 Client
*sel
= get_current_tag(awesomeconf
->tags
, awesomeconf
->ntags
)->client_sel
;
159 sel
->isfloating
= !sel
->isfloating
;
162 client_resize(sel
, sel
->rx
, sel
->ry
, sel
->rw
, sel
->rh
, awesomeconf
, True
, False
);
164 client_resize(sel
, sel
->x
, sel
->y
, sel
->w
, sel
->h
, awesomeconf
, True
, True
);
166 saveprops(sel
, awesomeconf
->ntags
);
167 arrange(awesomeconf
);
171 * \param arg Tag name
172 * \ingroup ui_callback
175 uicb_toggletag(awesome_config
*awesomeconf
,
178 Client
*sel
= get_current_tag(awesomeconf
->tags
, awesomeconf
->ntags
)->client_sel
;
184 i
= arg
? atoi(arg
) - 1 : 0;
185 sel
->tags
[i
] = !sel
->tags
[i
];
186 for(j
= 0; j
< awesomeconf
->ntags
&& !sel
->tags
[j
]; j
++);
187 if(j
== awesomeconf
->ntags
)
189 saveprops(sel
, awesomeconf
->ntags
);
190 arrange(awesomeconf
);
193 /** Add a tag to viewed tags
194 * \param arg Tag name
195 * \ingroup ui_callback
198 uicb_toggleview(awesome_config
*awesomeconf
,
204 i
= arg
? atoi(arg
) - 1: 0;
205 awesomeconf
->tags
[i
].selected
= !awesomeconf
->tags
[i
].selected
;
206 for(j
= 0; j
< awesomeconf
->ntags
&& !awesomeconf
->tags
[j
].selected
; j
++);
207 if(j
== awesomeconf
->ntags
)
208 awesomeconf
->tags
[i
].selected
= True
;
209 saveawesomeprops(awesomeconf
);
210 arrange(awesomeconf
);
214 * \param awesomeconf awesome config ref
215 * \param arg tag to view
216 * \ingroup ui_callback
219 uicb_view(awesome_config
*awesomeconf
,
224 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
226 awesomeconf
->tags
[i
].was_selected
= awesomeconf
->tags
[i
].selected
;
227 awesomeconf
->tags
[i
].selected
= arg
== NULL
;
233 if(i
>= 0 && i
< awesomeconf
->ntags
)
234 awesomeconf
->tags
[i
].selected
= True
;
237 saveawesomeprops(awesomeconf
);
238 arrange(awesomeconf
);
241 /** View previously selected tags
242 * \param awesomeconf awesome config ref
244 * \ingroup ui_callback
247 uicb_tag_prev_selected(awesome_config
*awesomeconf
,
248 const char *arg
__attribute__ ((unused
)))
253 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
255 t
= awesomeconf
->tags
[i
].selected
;
256 awesomeconf
->tags
[i
].selected
= awesomeconf
->tags
[i
].was_selected
;
257 awesomeconf
->tags
[i
].was_selected
= t
;
259 arrange(awesomeconf
);
264 * \ingroup ui_callback
267 uicb_tag_viewnext(awesome_config
*awesomeconf
,
268 const char *arg
__attribute__ ((unused
)))
273 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
275 if(firsttag
< 0 && awesomeconf
->tags
[i
].selected
)
277 awesomeconf
->tags
[i
].selected
= False
;
279 if(++firsttag
>= awesomeconf
->ntags
)
281 awesomeconf
->tags
[firsttag
].selected
= True
;
282 saveawesomeprops(awesomeconf
);
283 arrange(awesomeconf
);
286 /** View previous tag
288 * \ingroup ui_callback
291 uicb_tag_viewprev(awesome_config
*awesomeconf
,
292 const char *arg
__attribute__ ((unused
)))
297 for(i
= awesomeconf
->ntags
- 1; i
>= 0; i
--)
299 if(firsttag
< 0 && awesomeconf
->tags
[i
].selected
)
301 awesomeconf
->tags
[i
].selected
= False
;
304 firsttag
= awesomeconf
->ntags
- 1;
305 awesomeconf
->tags
[firsttag
].selected
= True
;
306 saveawesomeprops(awesomeconf
);
307 arrange(awesomeconf
);
309 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99