From ed115929f3da52f494f3ff98a16a56f7dc5a3dd0 Mon Sep 17 00:00:00 2001 From: "Carlos R. Mafra" Date: Fri, 7 Jun 2013 14:32:07 +0100 Subject: [PATCH] Fix workspace renaming with Ctrl+left click The Workspaces entry in the main menu allows to rename workspaces by clicking on the workspace name while pressing the Ctrl key. However since commit 63219247c6c7 ("Added shortcut to switch to last used workspace") there is one more entry before the workspace name list, and that leads to picking a wrong name to rename -- clicking on the first workspace asks to rename the second workspace and so forth. Trying to rename the last workspace leads to a segfault. This happens because there is an explicit offset in the current code (- 2) to account for the "non-workspace" entries in the menu. If one adds one more entry that offset should be changed too (this is a prime example of fragile code leading to bugs). --- src/menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/menu.c b/src/menu.c index 337b9e3a..c250fa41 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1766,7 +1766,7 @@ static void menuMouseDown(WObjDescriptor * desc, XEvent * event) if (!close_on_exit && (bev->state & ControlMask) && smenu && entry->flags.editable) { char buffer[128]; char *name; - int number = entry_no - 2; /* Entries "New" and "Destroy Last" appear before workspaces */ + int number = entry_no - 3; /* Entries "New", "Destroy Last" and "Last Used" appear before workspaces */ name = wstrdup(scr->workspaces[number]->name); snprintf(buffer, sizeof(buffer), _("Type the name for workspace %i:"), number + 1);