summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2013-05-15 23:26:11 +0200
committercos <cos>2013-05-26 19:37:40 +0200
commit14cce1cb74c2924e76fdee467ef06b5775c76421 (patch)
treec0527187fa70c854ac96593e188573fd1f1615d1
parent74e7f50fedca5052bebbaffd4ef2e9483686c62a (diff)
downloadratpoison-14cce1cb74c2924e76fdee467ef06b5775c76421.zip
Add initial cmd_gnumber implementation.
-rw-r--r--src/actions.c58
-rw-r--r--src/actions.h1
-rw-r--r--src/group.c27
-rw-r--r--src/group.h4
4 files changed, 89 insertions, 1 deletions
diff --git a/src/actions.c b/src/actions.c
index e31df72..ee3efc9 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -261,6 +261,9 @@ init_user_commands(void)
"Name: ", arg_STRING);
add_command ("gnewbg", cmd_gnewbg, 1, 1, 1,
"Name: ", arg_STRING);
+ add_command ("gnumber", cmd_gnumber, 2, 1, 1,
+ "Number: ", arg_NUMBER,
+ "Number: ", arg_NUMBER);
add_command ("grename", cmd_grename, 1, 1, 1,
"Change group name to: ", arg_REST);
add_command ("gnext", cmd_gnext, 0, 0, 0);
@@ -5077,6 +5080,61 @@ cmd_gnewbg (int interactive UNUSED, struct cmdarg **args)
}
cmdret *
+cmd_gnumber (int interactive UNUSED, struct cmdarg **args)
+{
+ int old_number, new_number;
+ rp_group *other_g, *g;
+
+ struct numset *g_numset = group_get_numset();
+
+/* FIXME Implement this. */
+// if (args[0] == NULL)
+// {
+// /* XXX: Fix this. */
+// print_window_information (rp_current_group, current_window());
+// return cmdret_new (RET_SUCCESS, NULL);
+// }
+
+ /* Gather the args. */
+ new_number = ARG(0,number);
+ if (args[1])
+ g = groups_find_group_by_number (ARG(1,number));
+ else
+ g = rp_current_group;
+
+ /* Make the switch. */
+ if (new_number >= 0 && g)
+ {
+ /* Find other window with same number and give it old number. */
+ other_g = groups_find_group_by_number (new_number);
+ if (other_g != NULL)
+ {
+ old_number = g->number;
+ other_g->number = old_number;
+
+ /* Resort the window in the list */
+ group_resort_group (other_g);
+ }
+ else
+ {
+ numset_release (g_numset, g->number);
+ }
+
+ g->number = new_number;
+ numset_add_num (g_numset, new_number);
+
+ /* resort the the window in the list */
+ group_resort_group (g);
+
+/* FIXME Implement updating of groups bar. */
+// /* Update the window list. */
+// update_window_names (win->win->scr, defaults.window_fmt);
+ }
+
+ return cmdret_new (RET_SUCCESS, NULL);
+}
+
+cmdret *
cmd_grename (int interactive UNUSED, struct cmdarg **args)
{
if (groups_find_group_by_name (ARG_STRING (0), 1))
diff --git a/src/actions.h b/src/actions.h
index 5db4a56..519c1a7 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -138,6 +138,7 @@ RP_CMD (gmove);
RP_CMD (gnew);
RP_CMD (gnewbg);
RP_CMD (gnext);
+RP_CMD (gnumber);
RP_CMD (gprev);
RP_CMD (gother);
RP_CMD (gravity);
diff --git a/src/group.c b/src/group.c
index 872746c..e882e8d 100644
--- a/src/group.c
+++ b/src/group.c
@@ -60,6 +60,12 @@ free_groups(void)
}
}
+struct numset *
+group_get_numset(void)
+{
+ return group_numset;
+}
+
rp_group *
group_new (int number, char *name)
{
@@ -100,7 +106,7 @@ group_add_new_group (char *name)
list_for_each_entry (cur, &rp_groups, node)
{
- if(cur->number > g->number)
+ if (cur->number > g->number)
{
list_add_tail (&g->node, &cur->node);
return g;
@@ -113,6 +119,25 @@ group_add_new_group (char *name)
}
void
+group_resort_group (rp_group *g)
+{
+ rp_group *cur;
+ struct list_head *last = &rp_groups;
+
+ list_del (&g->node);
+ list_for_each_entry (cur, &rp_groups, node)
+ {
+ if (cur->number > g->number)
+ {
+ list_add (&g->node, last);
+ return;
+ }
+ last = &cur->node;
+ }
+ list_add (&g->node, last);
+}
+
+void
group_rename (rp_group *g, char *name)
{
if (g->name)
diff --git a/src/group.h b/src/group.h
index 364100f..015bbac 100644
--- a/src/group.h
+++ b/src/group.h
@@ -39,6 +39,8 @@ void groups_map_window (rp_window *win);
void group_unmap_window (rp_group *g, rp_window *win);
void groups_unmap_window (rp_window *win);
+struct numset *group_get_numset (void);
+
rp_window *group_prev_window (rp_group *g, rp_window *win);
rp_window *group_next_window (rp_group *g, rp_window *win);
rp_group *groups_find_group_by_name (char *s, int exact_match);
@@ -52,6 +54,8 @@ rp_group *group_prev_group (void);
rp_group *group_next_group (void);
rp_group *group_last_group (void);
+void group_resort_group (rp_group *g);
+
rp_group *group_add_new_group (char *name);
void group_rename (rp_group *g, char *name);