[PATCH] add gother command

Ali Gholami Rudi <[email protected]>
Newsgroups gmane.comp.window-managers.ratpoison.devel
Message-ID <[email protected]>
---
 src/actions.c |    8 ++++++++
 src/actions.h |    1 +
 src/data.h    |    2 ++
 src/group.c   |   35 +++++++++++++++++++++++++++++++----
 src/group.h   |    1 +
 5 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/src/actions.c b/src/actions.c
index 4365679..36c5899 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -252,6 +252,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);
@@ -4757,6 +4758,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 1d5a1a8..801fdf3 100644
--- a/src/data.h
+++ b/src/data.h
@@ -135,6 +135,8 @@ struct rp_group
   char *name;
   int number;
 
+  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..a8fab1d 100644
--- a/src/group.c
+++ b/src/group.c
@@ -24,6 +24,15 @@
 
 static struct numset *group_numset;
 
+static void
+assign_current_group (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;
+  assign_current_group (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;
+  assign_current_group (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 ();
+          assign_current_group (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;
+          assign_current_group (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);
 
-- 
1.5.6.2.291.g7eef3.dirty
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.