2 * focus.c - focus management
4 * Copyright © 2007-2008 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
, int nindex
)
105 for(fl
= globalconf
.focus
; fl
; fl
= fl
->prev
)
106 if(fl
->client
&& !fl
->client
->skip
)
107 for(tags
= t
; *tags
; tags
++)
108 if(is_client_tagged(fl
->client
, *tags
))
120 focus_get_current_client(int screen
)
122 Tag
**curtags
= get_current_tags(screen
);
123 Client
*sel
= focus_get_latest_client_for_tags(curtags
, 0);
129 /** Jump in focus history stack
130 * \param screen Screen ID
131 * \param arg Integer argument
132 * \ingroup ui_callback
135 uicb_focus_history(int screen
, char *arg
)
147 curtags
= get_current_tags(screen
);
148 c
= focus_get_latest_client_for_tags(curtags
, i
);
151 focus(c
, True
, screen
);
157 uicb_focus_client_byname(int screen
, char *arg
)
160 Tag
**curtags
, **tag
;
164 curtags
= get_current_tags(screen
);
165 if((c
= get_client_byname(globalconf
.clients
, arg
)))
166 for(tag
= curtags
; *tag
; tag
++)
167 if(is_client_tagged(c
, *tag
))
168 focus(c
, True
, screen
);
173 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80