summaryrefslogtreecommitdiff
path: root/src/group.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2003-05-25 10:56:19 +0000
committersabetts <sabetts>2003-05-25 10:56:19 +0000
commite6f71abbce1ae8f8dc840b56aa4f3ccd36ebd735 (patch)
tree5270321337709993548139d4caee6be1353d94b1 /src/group.c
parentb6d1a9b5096e8e26acbe392ca44216d8573427e4 (diff)
downloadratpoison-e6f71abbce1ae8f8dc840b56aa4f3ccd36ebd735.zip
* src/window.c: do not include ctype.h
* src/ratpoison.h (str_comp): new prototype * src/messages.h (MESSAGE_PROMPT_SWITCH_TO_GROUP): new define * src/main.c: include ctype.h (str_comp): moved from window.c * src/group.h (groups_find_group_by_name): new prototype. (groups_find_group_by_number): likewise. (groups_merge): likewise (group_move_window): likewise * src/group.c: include string.h (group_new): new argument, name. All callers updated. prototype updated. (init_groups): create the first group with DEFAULT_GROUP_NAME as its name. (group_new): new argument, name. All callers updated. Prototype updated. (group_free): free the group's name. (group_add_new_group): new argument, name. All callers updated. Prototype updated. (groups_find_group_by_name): new function (groups_find_group_by_number): likewise (group_move_window): likewise (groups_merge): likewise * src/conf.h (DEFAULT_GROUP_NAME): new define * src/actions.h (cmd_gselect): new prototype (cmd_groups): likewise (cmd_gmove): likewise (cmd_gmerge): likewise (cmd_gnewbg): likewise * src/actions.c (user_commands): new commands gselect, groups, gmove, gmerge, gnewbg. (cmd_gnewbg): new function (find_group): likewise (cmd_gselect): likewise (cmd_groups): likewise (cmd_gmove): likewise (cmd_gmerge): likewise
Diffstat (limited to 'src/group.c')
-rw-r--r--src/group.c126
1 files changed, 121 insertions, 5 deletions
diff --git a/src/group.c b/src/group.c
index cbf645e..b69212e 100644
--- a/src/group.c
+++ b/src/group.c
@@ -1,5 +1,27 @@
+/* Copyright (C) 2000, 2001, 2002, 2003 Shawn Betts
+ *
+ * This file is part of ratpoison.
+ *
+ * ratpoison 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, or (at your option)
+ * any later version.
+ *
+ * ratpoison 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 software; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307 USA
+ */
+
#include "ratpoison.h"
+#include <string.h>
+
static struct numset *group_numset;
void init_groups()
@@ -11,18 +33,22 @@ void init_groups()
/* Create the first group in the list (We always need at least
one). */
- g = group_new (numset_request (group_numset));
+ g = group_new (numset_request (group_numset), DEFAULT_GROUP_NAME);
rp_current_group = g;
list_add_tail (&g->node, &rp_groups);
}
rp_group *
-group_new (int number)
+group_new (int number, char *name)
{
rp_group *g;
g = xmalloc (sizeof (rp_group));
+ if (name)
+ g->name = xstrdup (name);
+ else
+ g->name = NULL;
g->number = number;
g->numset = numset_new();
INIT_LIST_HEAD (&g->unmapped_windows);
@@ -34,18 +60,19 @@ group_new (int number)
void
group_free (rp_group *g)
{
- /* free (g->name); */
+ if (g->name)
+ free (g->name);
numset_free (g->numset);
numset_release (group_numset, g->number);
free (g);
}
rp_group *
-group_add_new_group ()
+group_add_new_group (char *name)
{
rp_group *g;
- g = group_new (numset_request (group_numset));
+ g = group_new (numset_request (group_numset), name);
list_add_tail (&g->node, &rp_groups);
return g;
@@ -63,6 +90,37 @@ group_prev_group ()
return list_prev_entry (rp_current_group, &rp_groups, node);
}
+rp_group *
+groups_find_group_by_name (char *s)
+{
+ rp_group *cur;
+
+ list_for_each_entry (cur, &rp_groups, node)
+ {
+ if (cur->name)
+ {
+ if (str_comp (s, cur->name, strlen (s)))
+ return cur;
+ }
+ }
+
+ return NULL;
+}
+
+rp_group *
+groups_find_group_by_number (int n)
+{
+ rp_group *cur;
+
+ list_for_each_entry (cur, &rp_groups, node)
+ {
+ if (cur->number == n)
+ return cur;
+ }
+
+ return NULL;
+}
+
rp_window_elem *
group_find_window (struct list_head *list, rp_window *win)
{
@@ -331,3 +389,61 @@ group_prev_window (rp_group *g, rp_window *win)
return NULL;
}
+
+void
+group_move_window (rp_group *to, rp_window *win)
+{
+ rp_group *cur, *from = NULL;
+ rp_window_elem *we = NULL;
+
+ /* Find the group that the window belongs to. FIXME: If the window
+ exists in multiple groups, then we're going to find the first
+ group with this window in it. */
+ list_for_each_entry (cur, &rp_groups, node)
+ {
+ we = group_find_window (&cur->mapped_windows, win);
+ if (we)
+ {
+ from = cur;
+ break;
+ }
+ }
+
+ if (we == NULL || from == NULL)
+ {
+ PRINT_DEBUG (("Unable to find window in mapped window lists.\n"));
+ return;
+ }
+
+ /* Manually remove the window from one group...*/
+ numset_release (from->numset, we->number);
+ list_del (&we->node);
+
+ /* and shove it into the other one. */
+ we->number = numset_request (to->numset);
+ group_insert_window (&to->mapped_windows, we);
+}
+
+void
+groups_merge (rp_group *from, rp_group *to)
+{
+ rp_window_elem *cur;
+ struct list_head *iter, *tmp;
+
+ /* Move the unmapped windows. */
+ list_for_each_safe_entry (cur, iter, tmp, &from->unmapped_windows, node)
+ {
+ list_del (&cur->node);
+ list_add_tail (&cur->node, &to->unmapped_windows);
+ }
+
+ /* Move the mapped windows. */
+ list_for_each_safe_entry (cur, iter, tmp, &from->mapped_windows, node)
+ {
+ numset_release (from->numset, cur->number);
+ list_del (&cur->node);
+
+ cur->number = numset_request (to->numset);
+ group_insert_window (&to->mapped_windows, cur);
+ }
+}