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>
31 /** Returns True if a client is tagged
32 * with one of the tags
34 * \param tags tag to check
35 * \param ntags number of tags in *tags
36 * \return True or False
39 isvisible(Client
* c
, int screen
, Tag
* tags
, int ntags
)
43 if(c
->screen
!= screen
)
46 for(i
= 0; i
< ntags
; i
++)
47 if(c
->tags
[i
] && tags
[i
].selected
)
53 tag_client_with_current_selected(Client
*c
, awesome_config
*awesomeconf
)
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
64 * \ingroup ui_callback
67 uicb_tag(awesome_config
*awesomeconf
,
71 Client
*sel
= get_current_tag(awesomeconf
->tags
, awesomeconf
->ntags
)->client_sel
;
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
)
84 saveprops(sel
, awesomeconf
->ntags
);
88 /** Toggle floating state of a client
90 * \ingroup ui_callback
93 uicb_togglefloating(awesome_config
* awesomeconf
,
94 const char *arg
__attribute__ ((unused
)))
96 Client
*sel
= get_current_tag(awesomeconf
->tags
, awesomeconf
->ntags
)->client_sel
;
101 sel
->isfloating
= !sel
->isfloating
;
104 client_resize(sel
, sel
->rx
, sel
->ry
, sel
->rw
, sel
->rh
, awesomeconf
, True
, False
);
106 client_resize(sel
, sel
->x
, sel
->y
, sel
->w
, sel
->h
, awesomeconf
, True
, True
);
108 saveprops(sel
, awesomeconf
->ntags
);
109 arrange(awesomeconf
);
113 * \param arg Tag name
114 * \ingroup ui_callback
117 uicb_toggletag(awesome_config
*awesomeconf
,
120 Client
*sel
= get_current_tag(awesomeconf
->tags
, awesomeconf
->ntags
)->client_sel
;
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
)
131 saveprops(sel
, awesomeconf
->ntags
);
132 arrange(awesomeconf
);
135 /** Add a tag to viewed tags
136 * \param arg Tag name
137 * \ingroup ui_callback
140 uicb_toggleview(awesome_config
*awesomeconf
,
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
);
156 * \param awesomeconf awesome config ref
157 * \param arg tag to view
158 * \ingroup ui_callback
161 uicb_view(awesome_config
*awesomeconf
,
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
;
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
186 * \ingroup ui_callback
189 uicb_tag_prev_selected(awesome_config
*awesomeconf
,
190 const char *arg
__attribute__ ((unused
)))
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
);
206 * \ingroup ui_callback
209 uicb_tag_viewnext(awesome_config
*awesomeconf
,
210 const char *arg
__attribute__ ((unused
)))
215 for(i
= 0; i
< awesomeconf
->ntags
; i
++)
217 if(firsttag
< 0 && awesomeconf
->tags
[i
].selected
)
219 awesomeconf
->tags
[i
].selected
= False
;
221 if(++firsttag
>= awesomeconf
->ntags
)
223 awesomeconf
->tags
[firsttag
].selected
= True
;
224 saveawesomeprops(awesomeconf
);
225 arrange(awesomeconf
);
228 /** View previous tag
230 * \ingroup ui_callback
233 uicb_tag_viewprev(awesome_config
*awesomeconf
,
234 const char *arg
__attribute__ ((unused
)))
239 for(i
= awesomeconf
->ntags
- 1; i
>= 0; i
--)
241 if(firsttag
< 0 && awesomeconf
->tags
[i
].selected
)
243 awesomeconf
->tags
[i
].selected
= False
;
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