From b57b21ee318287d035269cb526444a756a93cae9 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Sat, 20 Sep 2008 22:18:43 +0430 Subject: add gother command --- src/actions.c | 8 ++++++++ src/actions.h | 1 + src/data.h | 3 +++ src/group.c | 35 +++++++++++++++++++++++++++++++---- src/group.h | 1 + 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); @@ -4824,6 +4825,13 @@ cmd_gprev (int interactive, struct cmdarg **args) return cmdret_new (RET_SUCCESS, NULL); } +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) { 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); @@ -103,6 +113,23 @@ group_prev_group (void) return list_prev_entry (rp_current_group, &rp_groups, node); } +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) { @@ -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); -- cgit v1.2.3