From 72be933ef203350ba732ed893ab039456d66f2f3 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 25 May 2008 18:08:49 +0200 Subject: [PATCH] [focus] Split client_node functions out Signed-off-by: Julien Danjou --- Makefile.am | 1 + cnode.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ cnode.h | 33 ++++++++++++++++++++++++++++ focus.c | 47 +++++---------------------------------- focus.h | 4 +--- 5 files changed, 103 insertions(+), 45 deletions(-) create mode 100644 cnode.c create mode 100644 cnode.h diff --git a/Makefile.am b/Makefile.am index 6c2d2556..20300b95 100644 --- a/Makefile.am +++ b/Makefile.am @@ -115,6 +115,7 @@ awesome_SOURCES = \ titlebar.c titlebar.h \ placement.c placement.h \ focus.c focus.h \ + cnode.c cnode.h \ event.c event.h \ layout.c layout.h \ awesome.c \ diff --git a/cnode.c b/cnode.c new file mode 100644 index 00000000..65ee26a9 --- /dev/null +++ b/cnode.c @@ -0,0 +1,63 @@ +/* + * cnode.c - client node lists management + * + * Copyright © 2008 Julien Danjou + * + * 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 diff --git a/cnode.h b/cnode.h new file mode 100644 index 00000000..67bf7ca7 --- /dev/null +++ b/cnode.h @@ -0,0 +1,33 @@ +/* + * cnode.h - client node lists management header + * + * Copyright © 2008 Julien Danjou + * + * 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 diff --git a/focus.c b/focus.c index a67f3504..05a073a5 100644 --- a/focus.c +++ b/focus.c @@ -19,56 +19,19 @@ * */ -#include "tag.h" #include "focus.h" -#include "client.h" +#include "cnode.h" +#include "tag.h" 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. * \param c The client to push. */ void 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); } @@ -78,7 +41,7 @@ focus_client_push(client_t *c) void 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); } @@ -88,7 +51,7 @@ focus_client_append(client_t *c) void 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) { diff --git a/focus.h b/focus.h index 66cf6338..2662d16d 100644 --- a/focus.h +++ b/focus.h @@ -22,14 +22,12 @@ #ifndef AWESOME_FOCUS_H #define AWESOME_FOCUS_H -#include "structs.h" +#include "client.h" void focus_client_push(client_t *); void focus_client_append(client_t *); void focus_client_delete(client_t *); client_t * focus_get_current_client(int); -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