summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2013-05-15 23:26:11 +0200
committercos <cos>2013-05-15 23:26:11 +0200
commit8ddd38d8c96020d2cfba6c148e4409d410fd9900 (patch)
treeb0c16578a396fac2575484764c9167c490be9446
parent3a8ba7e627a5948957c18fe81ae487628ce36648 (diff)
downloadratpoison-8ddd38d8c96020d2cfba6c148e4409d410fd9900.zip
Add initial cmd_gnumber implementation.
-rw-r--r--src/actions.c59
-rw-r--r--src/actions.h1
-rw-r--r--src/group.c22
3 files changed, 81 insertions, 1 deletions
diff --git a/src/actions.c b/src/actions.c
index e31df72..d847fa7 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -79,6 +79,9 @@ static cmdret * set_historyexpansion (struct cmdarg **args);
LIST_HEAD(set_vars);
+/* FIXME This variable should really be kept static for group.c */
+extern struct numset *group_numset;
+
static void
add_set_var (char *name, cmdret * (*fn)(struct cmdarg **), int nargs, ...)
{
@@ -261,6 +264,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 +5083,59 @@ 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;
+
+/* 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 (group_numset, g->number);
+ }
+
+ g->number = new_number;
+ numset_add_num (group_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..5448006 100644
--- a/src/group.c
+++ b/src/group.c
@@ -22,7 +22,8 @@
#include <string.h>
-static struct numset *group_numset;
+/* XXX Should be static */
+struct numset *group_numset;
static void
set_current_group_1 (rp_group *g)
@@ -113,6 +114,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)