awesome/focus.c

153 lines
3.7 KiB
C
Raw Normal View History

2007-12-14 21:51:54 +01:00
/*
* focus.c - focus management
*
2008-01-02 16:59:43 +01:00
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
2007-12-14 21:51:54 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "tag.h"
#include "focus.h"
2008-01-01 17:25:48 +01:00
#include "client.h"
2007-12-14 21:51:54 +01:00
extern AwesomeConf globalconf;
2008-01-12 23:10:59 +01:00
static client_node_t *
focus_get_node_by_client(client_t *c)
2007-12-14 21:51:54 +01:00
{
2008-01-12 23:10:59 +01:00
client_node_t *node;
2007-12-14 21:51:54 +01:00
2008-01-12 23:10:59 +01:00
for(node = globalconf.focus; node; node = node->next)
if(node->client == c)
return node;
2007-12-14 21:51:54 +01:00
return NULL;
}
void
focus_add_client(client_t *c)
2007-12-14 21:51:54 +01:00
{
2008-01-12 23:10:59 +01:00
client_node_t *node;
2007-12-14 21:51:54 +01:00
/* if we don't find this node, create a new one */
2008-01-12 23:10:59 +01:00
if(!(node = focus_get_node_by_client(c)))
2007-12-14 21:51:54 +01:00
{
2008-01-12 23:10:59 +01:00
node = p_new(client_node_t, 1);
node->client = c;
2007-12-14 21:51:54 +01:00
}
else /* if we've got a node, detach it */
2008-01-12 23:10:59 +01:00
client_node_list_detach(&globalconf.focus, node);
2007-12-14 21:51:54 +01:00
2008-01-12 23:10:59 +01:00
client_node_list_push(&globalconf.focus, node);
2007-12-14 21:51:54 +01:00
}
void
focus_delete_client(client_t *c)
2007-12-14 21:51:54 +01:00
{
2008-01-12 23:10:59 +01:00
client_node_t *node = focus_get_node_by_client(c);
2007-12-28 12:39:40 +01:00
2008-01-12 23:10:59 +01:00
if(node)
{
2008-01-12 23:10:59 +01:00
client_node_list_detach(&globalconf.focus, node);
p_delete(&node);
}
2007-12-14 21:51:54 +01:00
}
static client_t *
focus_get_latest_client_for_tags(tag_t **t, int nindex)
2007-12-14 21:51:54 +01:00
{
2008-01-12 23:10:59 +01:00
client_node_t *node;
tag_t **tags;
int i = 0;
2007-12-14 21:51:54 +01:00
2008-01-12 23:10:59 +01:00
for(node = globalconf.focus; node; node = node->next)
if(node->client && ((!node->client->skip
&& node->client != globalconf.scratch.client)
2008-04-02 02:57:40 +02:00
|| globalconf.scratch.isvisible))
for(tags = t; *tags; tags++)
2008-01-12 23:10:59 +01:00
if(is_client_tagged(node->client, *tags))
{
if(i == nindex)
2008-01-12 23:10:59 +01:00
return node->client;
else
i--;
}
2007-12-14 21:51:54 +01:00
return NULL;
}
client_t *
2007-12-27 19:57:46 +01:00
focus_get_current_client(int screen)
{
tag_t **curtags = tags_get_current(screen);
client_t *sel = focus_get_latest_client_for_tags(curtags, 0);
2007-12-27 19:57:46 +01:00
p_delete(&curtags);
return sel;
}
/** Jump back in the focus history stack.
* Set arg to 0 for previous, -1 for previous of previous, etc.
* \param screen Screen ID
* \param arg Integer argument
* \ingroup ui_callback
*/
void
uicb_focus_history(int screen, char *arg)
{
int i;
tag_t **curtags;
client_t *c;
if(arg)
{
i = atoi(arg);
if(i < 0)
{
curtags = tags_get_current(screen);
c = focus_get_latest_client_for_tags(curtags, i);
p_delete(&curtags);
if(c)
2008-03-21 16:50:17 +01:00
client_focus(c, screen, true);
}
}
}
/** Focus one of the visible clients by its name.
* \param screen screen id
* \param arg client's name
* \ingroup ui_callback
*/
2007-12-23 16:16:02 +01:00
void
uicb_focus_client_byname(int screen, char *arg)
{
client_t *c;
tag_t **curtags, **tag;
2007-12-23 16:16:02 +01:00
if(arg)
{
curtags = tags_get_current(screen);
2008-01-29 08:21:05 +01:00
if((c = client_get_byname(globalconf.clients, arg)))
for(tag = curtags; *tag; tag++)
2007-12-27 23:05:34 +01:00
if(is_client_tagged(c, *tag))
2008-03-21 16:50:17 +01:00
client_focus(c, screen, true);
p_delete(&curtags);
}
2007-12-23 16:16:02 +01:00
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80