2007-12-14 21:51:54 +01:00
|
|
|
/*
|
|
|
|
* focus.c - focus management
|
|
|
|
*
|
|
|
|
* Copyright © 2007 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* 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 "util.h"
|
|
|
|
#include "tag.h"
|
2007-12-15 20:32:49 +01:00
|
|
|
#include "layout.h"
|
2007-12-14 21:51:54 +01:00
|
|
|
#include "focus.h"
|
|
|
|
|
2007-12-19 04:46:44 +01:00
|
|
|
extern AwesomeConf globalconf;
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2007-12-14 21:51:54 +01:00
|
|
|
static FocusList *
|
2007-12-17 03:56:29 +01:00
|
|
|
focus_get_node_by_client(Client *c)
|
2007-12-14 21:51:54 +01:00
|
|
|
{
|
2007-12-28 12:39:40 +01:00
|
|
|
FocusList *fl;
|
2007-12-14 21:51:54 +01:00
|
|
|
|
2007-12-28 12:39:40 +01:00
|
|
|
for(fl = globalconf.focus; fl; fl = fl->prev)
|
|
|
|
if(fl->client == c)
|
|
|
|
return fl;
|
2007-12-14 21:51:54 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FocusList *
|
2007-12-17 03:56:29 +01:00
|
|
|
focus_detach_node(FocusList *fl)
|
2007-12-14 21:51:54 +01:00
|
|
|
{
|
|
|
|
FocusList *tmp;
|
|
|
|
|
2007-12-17 03:56:29 +01:00
|
|
|
if(globalconf.focus == fl)
|
|
|
|
globalconf.focus = fl->prev;
|
2007-12-14 21:51:54 +01:00
|
|
|
else
|
|
|
|
{
|
2007-12-17 03:56:29 +01:00
|
|
|
for(tmp = globalconf.focus; tmp && tmp->prev != fl; tmp = tmp->prev);
|
2007-12-14 21:51:54 +01:00
|
|
|
tmp->prev = fl->prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FocusList *
|
2007-12-17 03:56:29 +01:00
|
|
|
focus_attach_node(FocusList *fl)
|
2007-12-14 21:51:54 +01:00
|
|
|
{
|
|
|
|
FocusList *old_head;
|
|
|
|
|
2007-12-17 03:56:29 +01:00
|
|
|
old_head = globalconf.focus;
|
|
|
|
globalconf.focus = fl;
|
2007-12-14 21:51:54 +01:00
|
|
|
fl->prev = old_head;
|
|
|
|
|
|
|
|
return fl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-17 03:56:29 +01:00
|
|
|
focus_add_client(Client *c)
|
2007-12-14 21:51:54 +01:00
|
|
|
{
|
|
|
|
FocusList *new_fh;
|
|
|
|
|
|
|
|
/* if we don't find this node, create a new one */
|
2007-12-17 03:56:29 +01:00
|
|
|
if(!(new_fh = focus_get_node_by_client(c)))
|
2007-12-14 21:51:54 +01:00
|
|
|
{
|
|
|
|
new_fh = p_new(FocusList, 1);
|
|
|
|
new_fh->client = c;
|
|
|
|
}
|
|
|
|
else /* if we've got a node, detach it */
|
2007-12-17 03:56:29 +01:00
|
|
|
focus_detach_node(new_fh);
|
2007-12-14 21:51:54 +01:00
|
|
|
|
2007-12-17 03:56:29 +01:00
|
|
|
focus_attach_node(new_fh);
|
2007-12-14 21:51:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-17 03:56:29 +01:00
|
|
|
focus_delete_client(Client *c)
|
2007-12-14 21:51:54 +01:00
|
|
|
{
|
2007-12-28 12:39:40 +01:00
|
|
|
FocusList *target = focus_get_node_by_client(c);
|
|
|
|
|
|
|
|
if(target)
|
2007-12-15 08:06:20 +01:00
|
|
|
{
|
2007-12-28 12:39:40 +01:00
|
|
|
focus_detach_node(target);
|
2007-12-15 08:06:20 +01:00
|
|
|
p_delete(&target);
|
|
|
|
}
|
2007-12-14 21:51:54 +01:00
|
|
|
}
|
|
|
|
|
2007-12-27 19:57:46 +01:00
|
|
|
static Client *
|
2007-12-27 23:05:34 +01:00
|
|
|
focus_get_latest_client_for_tags(Tag **t)
|
2007-12-14 21:51:54 +01:00
|
|
|
{
|
|
|
|
FocusList *fl;
|
|
|
|
|
2007-12-17 03:56:29 +01:00
|
|
|
for(fl = globalconf.focus; fl; fl = fl->prev)
|
2007-12-27 19:23:10 +01:00
|
|
|
for(; *t; t++)
|
2007-12-28 11:15:15 +01:00
|
|
|
if(is_client_tagged(fl->client, *t))
|
|
|
|
return fl->client;
|
2007-12-14 21:51:54 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-27 19:57:46 +01:00
|
|
|
Client *
|
|
|
|
focus_get_current_client(int screen)
|
|
|
|
{
|
|
|
|
Tag **curtags = get_current_tags(screen);
|
2007-12-27 23:05:34 +01:00
|
|
|
Client *sel = focus_get_latest_client_for_tags(curtags);
|
2007-12-27 19:57:46 +01:00
|
|
|
p_delete(&curtags);
|
|
|
|
|
|
|
|
return sel;
|
|
|
|
}
|
|
|
|
|
2007-12-19 04:39:59 +01:00
|
|
|
/** Jump in focus history stack
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Integer argument
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
2007-12-15 20:32:49 +01:00
|
|
|
void
|
2007-12-17 01:17:54 +01:00
|
|
|
uicb_focus_history(int screen, char *arg)
|
2007-12-15 20:32:49 +01:00
|
|
|
{
|
|
|
|
int i;
|
2007-12-16 02:45:38 +01:00
|
|
|
FocusList *fl = globalconf.focus;
|
2007-12-27 13:09:39 +01:00
|
|
|
Tag **curtags, **tag;
|
2007-12-15 20:32:49 +01:00
|
|
|
|
|
|
|
if(arg)
|
|
|
|
{
|
|
|
|
i = atoi(arg);
|
|
|
|
|
|
|
|
if(i < 0)
|
|
|
|
{
|
2007-12-27 13:09:39 +01:00
|
|
|
curtags = get_current_tags(screen);
|
2007-12-15 20:32:49 +01:00
|
|
|
for(; fl && i < 0; fl = fl->prev)
|
2007-12-27 13:09:39 +01:00
|
|
|
for(tag = curtags; *tag; tag++)
|
2007-12-27 23:05:34 +01:00
|
|
|
if(is_client_tagged(fl->client, *tag))
|
2007-12-27 13:09:39 +01:00
|
|
|
i++;
|
|
|
|
p_delete(&curtags);
|
2007-12-15 20:32:49 +01:00
|
|
|
if(fl)
|
2007-12-16 02:45:38 +01:00
|
|
|
focus(fl->client, True, screen);
|
2007-12-15 20:32:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-23 16:16:02 +01:00
|
|
|
void
|
|
|
|
uicb_focus_client_byname(int screen, char *arg)
|
|
|
|
{
|
|
|
|
Client *c;
|
2007-12-27 13:09:39 +01:00
|
|
|
Tag **curtags, **tag;
|
2007-12-23 16:16:02 +01:00
|
|
|
|
2007-12-27 13:09:39 +01:00
|
|
|
if(arg)
|
|
|
|
{
|
|
|
|
curtags = get_current_tags(screen);
|
|
|
|
if((c = get_client_byname(globalconf.clients, arg)))
|
|
|
|
for(tag = curtags; *tag; tag++)
|
2007-12-27 23:05:34 +01:00
|
|
|
if(is_client_tagged(c, *tag))
|
2007-12-27 13:09:39 +01:00
|
|
|
focus(c, True, screen);
|
|
|
|
p_delete(&curtags);
|
|
|
|
}
|
2007-12-23 16:16:02 +01:00
|
|
|
}
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|