[PATCH 2/3] don't delete the last group

Ali Gholami Rudi <[email protected]>
Newsgroups gmane.comp.window-managers.ratpoison.devel
Message-ID <[email protected]>
Currently gdelete deletes the last group and creates a new empty
group.  This patch changes gdelete to show a message, instead.
---
 src/actions.c |    3 +++
 src/globals.h |    1 +
 src/group.c   |   13 ++++---------
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/actions.c b/src/actions.c
index c7534bc..cacd4b0 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -5024,6 +5024,9 @@ cmd_gdelete (int interactive, struct cmdarg **args)
     case GROUP_DELETE_GROUP_NONEMPTY:
       return cmdret_new (RET_FAILURE, "gdelete: non-empty group");
       break;
+    case GROUP_DELETE_LAST_GROUP:
+      return cmdret_new (RET_FAILURE, "gdelete: cannot delete the last group");
+      break;
     default:
       return cmdret_new (RET_FAILURE, "gdelete: unknown return code (this shouldn't happen)");
     }
diff --git a/src/globals.h b/src/globals.h
index b7aaa00..c56bbca 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -64,6 +64,7 @@
 /* Error codes for group_delete_group() */
 #define GROUP_DELETE_GROUP_OK         0
 #define GROUP_DELETE_GROUP_NONEMPTY   1
+#define GROUP_DELETE_LAST_GROUP       2
 
 /* The list of groups. */
 extern struct list_head rp_groups;
diff --git a/src/group.c b/src/group.c
index de8b9a6..00d1476 100644
--- a/src/group.c
+++ b/src/group.c
@@ -543,6 +543,10 @@ group_delete_group (rp_group *g)
   if (list_empty (&(g->mapped_windows))
       && list_empty (&(g->unmapped_windows)))
     {
+      /* don't delete the last group */
+      if (list_size (&rp_groups) == 1)
+        return GROUP_DELETE_LAST_GROUP;
+
       /* we can safely delete the group */
       if (g == rp_current_group)
         {
@@ -552,15 +556,6 @@ group_delete_group (rp_group *g)
 
       list_del (&(g->node));
       group_free (g);
-
-      if (list_empty (&rp_groups))
-        {
-          /* Create the first group in the list (We always need at least
-             one). */
-          g = group_new (numset_request (group_numset), DEFAULT_GROUP_NAME);
-          set_current_group_1 (g);
-          list_add_tail (&g->node, &rp_groups);
-        }
       return GROUP_DELETE_GROUP_OK;
     }
   else
-- 
1.6.0.2.307.gc427.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.