[focus] Split client_node functions out

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-25 18:08:49 +02:00
parent f6f74c4565
commit 72be933ef2
5 changed files with 103 additions and 45 deletions

View File

@ -115,6 +115,7 @@ awesome_SOURCES = \
titlebar.c titlebar.h \ titlebar.c titlebar.h \
placement.c placement.h \ placement.c placement.h \
focus.c focus.h \ focus.c focus.h \
cnode.c cnode.h \
event.c event.h \ event.c event.h \
layout.c layout.h \ layout.c layout.h \
awesome.c \ awesome.c \

63
cnode.c Normal file
View File

@ -0,0 +1,63 @@
/*
* cnode.c - client node lists management
*
* Copyright © 2008 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 "cnode.h"
/** Get the client's node focus.
* \arap, list The client list.
* \param c The client.
* \return The client node focus.
*/
client_node_t *
client_node_client_getby(client_node_t *list, client_t *c)
{
client_node_t *node;
for(node = list; node; node = node->next)
if(node->client == c)
return node;
return NULL;
}
/** Create a client node for focus.
* \arap, list The client list.
* \param c The client
* \return The client focus node.
*/
client_node_t *
client_node_client_add(client_node_t **list, client_t *c)
{
client_node_t *node;
/* if we don't find this node, create a new one */
if(!(node = client_node_client_getby(*list, c)))
{
node = p_new(client_node_t, 1);
node->client = c;
}
else /* if we've got a node, detach it */
client_node_list_detach(list, node);
return node;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

33
cnode.h Normal file
View File

@ -0,0 +1,33 @@
/*
* cnode.h - client node lists management header
*
* Copyright © 2008 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.
*
*/
#ifndef AWESOME_CNODE_H
#define AWESOME_CNODE_H
#include "client.h"
client_node_t * client_node_client_getby(client_node_t *, client_t *);
client_node_t * client_node_client_add(client_node_t **, client_t *);
DO_SLIST(client_node_t, client_node, p_delete)
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

47
focus.c
View File

@ -19,56 +19,19 @@
* *
*/ */
#include "tag.h"
#include "focus.h" #include "focus.h"
#include "client.h" #include "cnode.h"
#include "tag.h"
extern awesome_t globalconf; extern awesome_t globalconf;
/** Get the client's node focus.
* \param c The client.
* \return The client node focus.
*/
static client_node_t *
focus_get_node_by_client(client_t *c)
{
client_node_t *node;
for(node = globalconf.focus; node; node = node->next)
if(node->client == c)
return node;
return NULL;
}
/** Create a client node for focus.
* \param c The client
* \return The client focus node.
*/
static client_node_t *
focus_client_add(client_t *c)
{
client_node_t *node;
/* if we don't find this node, create a new one */
if(!(node = focus_get_node_by_client(c)))
{
node = p_new(client_node_t, 1);
node->client = c;
}
else /* if we've got a node, detach it */
client_node_list_detach(&globalconf.focus, node);
return node;
}
/** Push the client at the beginning of the client focus history stack. /** Push the client at the beginning of the client focus history stack.
* \param c The client to push. * \param c The client to push.
*/ */
void void
focus_client_push(client_t *c) focus_client_push(client_t *c)
{ {
client_node_t *node = focus_client_add(c); client_node_t *node = client_node_client_add(&globalconf.focus, c);
client_node_list_push(&globalconf.focus, node); client_node_list_push(&globalconf.focus, node);
} }
@ -78,7 +41,7 @@ focus_client_push(client_t *c)
void void
focus_client_append(client_t *c) focus_client_append(client_t *c)
{ {
client_node_t *node = focus_client_add(c); client_node_t *node = client_node_client_add(&globalconf.focus, c);
client_node_list_append(&globalconf.focus, node); client_node_list_append(&globalconf.focus, node);
} }
@ -88,7 +51,7 @@ focus_client_append(client_t *c)
void void
focus_client_delete(client_t *c) focus_client_delete(client_t *c)
{ {
client_node_t *node = focus_get_node_by_client(c); client_node_t *node = client_node_client_getby(globalconf.focus, c);
if(node) if(node)
{ {

View File

@ -22,14 +22,12 @@
#ifndef AWESOME_FOCUS_H #ifndef AWESOME_FOCUS_H
#define AWESOME_FOCUS_H #define AWESOME_FOCUS_H
#include "structs.h" #include "client.h"
void focus_client_push(client_t *); void focus_client_push(client_t *);
void focus_client_append(client_t *); void focus_client_append(client_t *);
void focus_client_delete(client_t *); void focus_client_delete(client_t *);
client_t * focus_get_current_client(int); client_t * focus_get_current_client(int);
DO_SLIST(client_node_t, client_node, p_delete)
#endif #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80