2 * focus.c - focus 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.
27 extern AwesomeConf globalconf
;
30 focus_get_node_by_client(Client
*c
)
34 for(fl
= globalconf
.focus
; fl
; fl
= fl
->prev
)
42 focus_detach_node(FocusList
*fl
)
46 if(globalconf
.focus
== fl
)
47 globalconf
.focus
= fl
->prev
;
50 for(tmp
= globalconf
.focus
; tmp
&& tmp
->prev
!= fl
; tmp
= tmp
->prev
);
58 focus_attach_node(FocusList
*fl
)
62 old_head
= globalconf
.focus
;
63 globalconf
.focus
= fl
;
70 focus_add_client(Client
*c
)
74 /* if we don't find this node, create a new one */
75 if(!(new_fh
= focus_get_node_by_client(c
)))
77 new_fh
= p_new(FocusList
, 1);
80 else /* if we've got a node, detach it */
81 focus_detach_node(new_fh
);
83 focus_attach_node(new_fh
);
87 focus_delete_client(Client
*c
)
89 FocusList
*target
= focus_get_node_by_client(c
);
93 focus_detach_node(target
);
99 focus_get_latest_client_for_tags(Tag
**t
)
104 for(fl
= globalconf
.focus
; fl
; fl
= fl
->prev
)
105 for(tags
= t
; *tags
; tags
++)
106 if(is_client_tagged(fl
->client
, *t
))
113 focus_get_current_client(int screen
)
115 Tag
**curtags
= get_current_tags(screen
);
116 Client
*sel
= focus_get_latest_client_for_tags(curtags
);
122 /** Jump in focus history stack
123 * \param screen Screen ID
124 * \param arg Integer argument
125 * \ingroup ui_callback
128 uicb_focus_history(int screen
, char *arg
)
131 FocusList
*fl
= globalconf
.focus
;
132 Tag
**curtags
, **tag
;
140 curtags
= get_current_tags(screen
);
141 for(; fl
&& i
< 0; fl
= fl
->prev
)
142 for(tag
= curtags
; *tag
; tag
++)
143 if(is_client_tagged(fl
->client
, *tag
))
147 focus(fl
->client
, True
, screen
);
153 uicb_focus_client_byname(int screen
, char *arg
)
156 Tag
**curtags
, **tag
;
160 curtags
= get_current_tags(screen
);
161 if((c
= get_client_byname(globalconf
.clients
, arg
)))
162 for(tag
= curtags
; *tag
; tag
++)
163 if(is_client_tagged(c
, *tag
))
164 focus(c
, True
, screen
);
169 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80