build: set minimal cmake version to 2.4.7
[awesome.git] / focus.c
blobacb64bb4546dc5ef06b05f434e658be436a33a68
1 /*
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.
22 #include "focus.h"
23 #include "cnode.h"
24 #include "tag.h"
26 extern awesome_t globalconf;
28 /** Push the client at the beginning of the client focus history stack.
29 * \param c The client to push.
31 void
32 focus_client_push(client_t *c)
34 client_node_t *node = client_node_client_add(&globalconf.focus, c);
35 client_node_list_push(&globalconf.focus, node);
38 /** Append the client at the end of the client focus history stack.
39 * \param c The client to append.
41 void
42 focus_client_append(client_t *c)
44 client_node_t *node = client_node_client_add(&globalconf.focus, c);
45 client_node_list_append(&globalconf.focus, node);
48 /** Remove a client from focus history.
49 * \param c The client.
51 void
52 focus_client_delete(client_t *c)
54 client_node_t *node = client_node_client_getby(globalconf.focus, c);
56 if(node)
58 client_node_list_detach(&globalconf.focus, node);
59 p_delete(&node);
63 static client_t *
64 focus_get_latest_client_for_tags(tag_t **t, int nindex)
66 client_node_t *node;
67 tag_t **tags;
68 int i = 0;
70 for(node = globalconf.focus; node; node = node->next)
71 if(node->client && !node->client->skip && !node->client->ishidden)
72 for(tags = t; *tags; tags++)
73 if(is_client_tagged(node->client, *tags))
74 if(i-- == nindex)
75 return node->client;
76 return NULL;
79 /** Get the latest focused client on a screen.
80 * \param screen The virtual screen number.
81 * \return A pointer to an existing client.
83 client_t *
84 focus_get_current_client(int screen)
86 tag_t **curtags = tags_get_current(screen);
87 client_t *sel = focus_get_latest_client_for_tags(curtags, 0);
88 p_delete(&curtags);
90 return sel;
93 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80