summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Gholami Rudi <aliqrudi@gmail.com>2008-09-20 22:18:43 +0430
committerShawn <sabetts@juicebox.(none)>2008-10-10 14:15:23 -0700
commitb57b21ee318287d035269cb526444a756a93cae9 (patch)
treef9b69bdb88bd18e48084a4198df83ef1c43a5d95
parentddf7f1104af0663ba730b5b82607843fe988109e (diff)
downloadratpoison-b57b21ee318287d035269cb526444a756a93cae9.zip
add gother command
-rw-r--r--src/actions.c8
-rw-r--r--src/actions.h1
-rw-r--r--src/data.h3
-rw-r--r--src/group.c35
-rw-r--r--src/group.h1
5 files changed, 44 insertions, 4 deletions
diff --git a/src/actions.c b/src/actions.c
index 7d73fd2..5d7b335 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -256,6 +256,7 @@ init_user_commands(void)
"Name: ", arg_STRING);
add_command ("gnext", cmd_gnext, 0, 0, 0);
add_command ("gprev", cmd_gprev, 0, 0, 0);
+ add_command ("gother", cmd_gother, 0, 0, 0);
add_command ("gravity", cmd_gravity, 1, 0, 0,
"Gravity: ", arg_GRAVITY);
add_command ("groups", cmd_groups, 0, 0, 0);
@@ -4825,6 +4826,13 @@ cmd_gprev (int interactive, struct cmdarg **args)
}
cmdret *
+cmd_gother (int interactive, struct cmdarg **args)
+{
+ set_current_group (group_last_group ());
+ return cmdret_new (RET_SUCCESS, NULL);
+}
+
+cmdret *
cmd_gnew (int interactive, struct cmdarg **args)
{
set_current_group (group_add_new_group (ARG_STRING(0)));
diff --git a/src/actions.h b/src/actions.h
index b212087..76ee85f 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -138,6 +138,7 @@ RP_CMD (gnew);
RP_CMD (gnewbg);
RP_CMD (gnext);
RP_CMD (gprev);
+RP_CMD (gother);
RP_CMD (gravity);
RP_CMD (groups);
RP_CMD (gselect);
diff --git a/src/data.h b/src/data.h
index cddfa1b..793cd51 100644
--- a/src/data.h
+++ b/src/data.h
@@ -135,6 +135,9 @@ struct rp_group
char *name;
int number;
+ /* For determining the last group. */
+ int last_access;
+
/* The list of windows participating in this group. */
struct list_head mapped_windows, unmapped_windows;
diff --git a/src/group.c b/src/group.c
index 4f0f816..e5d66f9 100644
--- a/src/group.c
+++ b/src/group.c
@@ -24,6 +24,15 @@
static struct numset *group_numset;
+static void
+set_current_group_1 (rp_group *g)
+{
+ static int counter = 1;
+ rp_current_group = g;
+ if (g)
+ g->last_access = counter++;
+}
+
void
init_groups(void)
{
@@ -35,7 +44,7 @@ init_groups(void)
/* Create the first group in the list (We always need at least
one). */
g = group_new (numset_request (group_numset), DEFAULT_GROUP_NAME);
- rp_current_group = g;
+ set_current_group_1 (g);
list_add_tail (&g->node, &rp_groups);
}
@@ -62,6 +71,7 @@ group_new (int number, char *name)
g->name = xstrdup (name);
else
g->name = NULL;
+ g->last_access = 0;
g->number = number;
g->numset = numset_new();
INIT_LIST_HEAD (&g->unmapped_windows);
@@ -104,6 +114,23 @@ group_prev_group (void)
}
rp_group *
+group_last_group (void)
+{
+ int last_access = 0;
+ rp_group *most_recent = NULL;
+ rp_group *cur;
+
+ list_for_each_entry (cur, &rp_groups, node)
+ {
+ if (cur != rp_current_group && cur->last_access > last_access) {
+ most_recent = cur;
+ last_access = cur->last_access;
+ }
+ }
+ return most_recent;
+}
+
+rp_group *
groups_find_group_by_name (char *s)
{
rp_group *cur;
@@ -504,7 +531,7 @@ set_current_group (rp_group *g)
if (rp_current_group == g || g == NULL)
return;
- rp_current_group = g;
+ set_current_group_1 (g);
/* Call the switch group hook. */
hook_run (&rp_switch_group_hook);
@@ -519,7 +546,7 @@ group_delete_group (rp_group *g)
/* we can safely delete the group */
if (g == rp_current_group)
{
- rp_current_group = group_next_group ();
+ set_current_group_1 (group_next_group ());
}
list_del (&(g->node));
@@ -530,7 +557,7 @@ group_delete_group (rp_group *g)
/* Create the first group in the list (We always need at least
one). */
g = group_new (numset_request (group_numset), DEFAULT_GROUP_NAME);
- rp_current_group = g;
+ set_current_group_1 (g);
list_add_tail (&g->node, &rp_groups);
}
return GROUP_DELETE_GROUP_OK;
diff --git a/src/group.h b/src/group.h
index 8e781c0..4e6ad81 100644
--- a/src/group.h
+++ b/src/group.h
@@ -50,6 +50,7 @@ rp_window *group_last_window (rp_group *g, rp_screen *screen);
rp_group *group_prev_group (void);
rp_group *group_next_group (void);
+rp_group *group_last_group (void);
rp_group *group_add_new_group (char *name);