From c35690b4a4c0260adb9233443a4bae05a57411db Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Tue, 24 May 2022 07:19:52 +0200 Subject: [PATCH] containers: Fix creating new iconboxes When creating a new iconbox without giving a name (eesh ibox new) as done by the desktop menu this would not work if an iconbox named _IB_ ( being the number of containers) already existed. --- src/container.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/container.c b/src/container.c index 1339e51b..5e6330e6 100644 --- a/src/container.c +++ b/src/container.c @@ -1920,6 +1920,19 @@ ContainersGetList(int *pnum) return LIST_GET_ITEMS(Container, &container_list, pnum); } +static void +_ContainersNewName(char *nbuf, unsigned int nlen, const char *pfx) +{ + int i; + + for (i = 1;; i++) + { + Esnprintf(nbuf, nlen, "%s%i", pfx, i); + if (!_ContainerFind(nbuf)) + break; + } +} + /* * IPC functions */ @@ -1928,7 +1941,7 @@ _ContainerIpc(const char *params) { const char *p; char cmd[128], prm[128]; - int len, num; + int len; cmd[0] = prm[0] = '\0'; p = params; @@ -1954,10 +1967,7 @@ _ContainerIpc(const char *params) Container *ct; if (!prm[0]) - { - num = LIST_GET_COUNT(&container_list); - Esnprintf(prm, sizeof(prm), "_IB_%i", num); - } + _ContainersNewName(prm, sizeof(prm), "_IB_"); ct = _ContainerCreate(prm); _ContainerShow(ct); _ContainersConfigSave();