Changeset 9bec33a in mainline
- Timestamp:
- 2023-10-09T11:13:19Z (13 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 983052c
- Parents:
- 7d78e466
- git-author:
- Jiri Svoboda <jiri@…> (2023-10-08 17:13:00)
- git-committer:
- Jiri Svoboda <jiri@…> (2023-10-09 11:13:19)
- Location:
- uspace/app/taskbar
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/startmenu.sif
r7d78e466 r9bec33a 1 [sif](){[entries](){[entry]([caption]=[~N~avigator][cmd]=[/app/ nav]){}[entry]([caption]=[Text ~E~ditor][cmd]=[/app/edit]){}[entry]([caption]=[~T~erminal][cmd]=[/app/terminal]){}[entry]([caption]=[~C~alculator][cmd]=[/app/calculator]){}[entry]([caption]=[~U~I Demo][cmd]=[/app/uidemo]){}[entry]([caption]=[~G~FX Demo][cmd]=[/app/gfxdemo]){}}}1 [sif](){[entries](){[entry]([caption]=[~N~avigator][cmd]=[/app/terminal -c /app/nav]){}[entry]([caption]=[Text ~E~ditor][cmd]=[/app/terminal -c /app/edit]){}[entry]([caption]=[~T~erminal][cmd]=[/app/terminal]){}[entry]([caption]=[~C~alculator][cmd]=[/app/calculator]){}[entry]([caption]=[~U~I Demo][cmd]=[/app/uidemo]){}[entry]([caption]=[~G~FX Demo][cmd]=[/app/gfxdemo ui]){}}} -
uspace/app/taskbar/tbsmenu.c
r7d78e466 r9bec33a 38 38 #include <stddef.h> 39 39 #include <stdlib.h> 40 #include <str.h> 41 #include <task.h> 40 42 #include <ui/fixed.h> 41 43 #include <ui/menu.h> … … 59 61 .clicked = tbsmenu_button_clicked 60 62 }; 63 64 static void tbsmenu_smenu_entry_cb(ui_menu_entry_t *, void *); 65 static errno_t tbsmenu_entry_start(tbsmenu_entry_t *); 61 66 62 67 /** Create task bar start menu. … … 119 124 errno_t tbsmenu_load(tbsmenu_t *tbsmenu, const char *repopath) 120 125 { 121 ui_menu_entry_t *tentry;126 tbsmenu_entry_t *tentry; 122 127 startmenu_t *smenu = NULL; 123 128 startmenu_entry_t *sme; … … 135 140 cmd = startmenu_entry_get_cmd(sme); 136 141 137 rc = ui_menu_entry_create(tbsmenu->smenu, caption, "", &tentry);142 rc = tbsmenu_add(tbsmenu, caption, cmd, &tentry); 138 143 if (rc != EOK) 139 144 goto error; 140 145 141 (void) cmd;146 (void)tentry; 142 147 143 148 sme = startmenu_next(sme); … … 171 176 tbsmenu_entry_t *entry; 172 177 173 // TODO Close libstartmenu174 175 178 /* Destroy entries */ 176 179 entry = tbsmenu_first(tbsmenu); 177 180 while (entry != NULL) { 178 (void)tbsmenu_remove(tbsmenu, entry, false);181 tbsmenu_remove(tbsmenu, entry, false); 179 182 entry = tbsmenu_first(tbsmenu); 180 183 } … … 187 190 } 188 191 189 /** Remove entry from strat menu. 192 /** Add entry to start menu. 193 * 194 * @param tbsmenu Start menu 195 * @param caption Caption 196 * @param cmd Command to run 197 * @param entry Start menu entry 198 * @return @c EOK on success or an error code 199 */ 200 errno_t tbsmenu_add(tbsmenu_t *tbsmenu, const char *caption, 201 const char *cmd, tbsmenu_entry_t **rentry) 202 { 203 errno_t rc; 204 tbsmenu_entry_t *entry; 205 206 entry = calloc(1, sizeof(tbsmenu_entry_t)); 207 if (entry == NULL) 208 return ENOMEM; 209 210 entry->caption = str_dup(caption); 211 if (entry->caption == NULL) { 212 rc = ENOMEM; 213 goto error; 214 } 215 216 entry->cmd = str_dup(cmd); 217 if (entry->cmd == NULL) { 218 rc = ENOMEM; 219 goto error; 220 } 221 222 rc = ui_menu_entry_create(tbsmenu->smenu, caption, "", &entry->mentry); 223 if (rc != EOK) 224 goto error; 225 226 ui_menu_entry_set_cb(entry->mentry, tbsmenu_smenu_entry_cb, 227 (void *)entry); 228 229 entry->tbsmenu = tbsmenu; 230 list_append(&entry->lentries, &tbsmenu->entries); 231 *rentry = entry; 232 return EOK; 233 error: 234 if (entry->caption != NULL) 235 free(entry->caption); 236 if (entry->cmd != NULL) 237 free(entry->cmd); 238 free(entry); 239 return rc; 240 } 241 242 /** Remove entry from start menu. 190 243 * 191 244 * @param tbsmenu Start menu 192 245 * @param entry Start menu entry 193 246 * @param paint @c true to repaint start menu 194 * @return @c EOK on success or an error code 195 */ 196 errno_t tbsmenu_remove(tbsmenu_t *tbsmenu, tbsmenu_entry_t *entry, 247 */ 248 void tbsmenu_remove(tbsmenu_t *tbsmenu, tbsmenu_entry_t *entry, 197 249 bool paint) 198 250 { 199 errno_t rc = EOK;200 201 251 assert(entry->tbsmenu == tbsmenu); 202 252 203 253 list_remove(&entry->lentries); 204 254 205 // TODO Destroy menu entry 255 ui_menu_entry_destroy(entry->mentry); 256 free(entry->caption); 257 free(entry->cmd); 206 258 free(entry); 207 return rc;208 259 } 209 260 … … 220 271 (void)tbsmenu; 221 272 ui_menu_close(menu); 273 } 274 275 /** Start menu entry was activated. 276 * 277 * @param smentry Start menu entry 278 * @param arg Argument (tbsmenu_entry_t *) 279 */ 280 static void tbsmenu_smenu_entry_cb(ui_menu_entry_t *smentry, void *arg) 281 { 282 tbsmenu_entry_t *entry = (tbsmenu_entry_t *)arg; 283 284 (void)tbsmenu_entry_start(entry); 222 285 } 223 286 … … 299 362 } 300 363 364 /** Split command string into individual parts. 365 * 366 * Command arguments are separated by spaces. There is no way 367 * to provide an argument containing spaces. 368 * 369 * @param str Command with arguments separated by spaces 370 * @param cmd Command structure to fill in 371 * @return EOK on success or an error code 372 */ 373 static errno_t tbsmenu_cmd_split(const char *str, tbsmenu_cmd_t *cmd) 374 { 375 char *arg; 376 char *next; 377 size_t cnt; 378 379 cmd->buf = str_dup(str); 380 if (cmd->buf == NULL) 381 return ENOMEM; 382 383 /* Count the entries */ 384 cnt = 0; 385 arg = str_tok(cmd->buf, " ", &next); 386 while (arg != NULL) { 387 ++cnt; 388 arg = str_tok(next, " ", &next); 389 } 390 391 /* Need to copy again as buf was mangled */ 392 free(cmd->buf); 393 cmd->buf = str_dup(str); 394 if (cmd->buf == NULL) 395 return ENOMEM; 396 397 cmd->argv = calloc(cnt + 1, sizeof(char *)); 398 if (cmd->argv == NULL) { 399 free(cmd->buf); 400 return ENOMEM; 401 } 402 403 /* Fill in pointers */ 404 cnt = 0; 405 arg = str_tok(cmd->buf, " ", &next); 406 while (arg != NULL) { 407 cmd->argv[cnt++] = arg; 408 arg = str_tok(next, " ", &next); 409 } 410 411 return EOK; 412 } 413 414 /** Free command structure. 415 * 416 * @param cmd Command 417 */ 418 static void tbsmenu_cmd_fini(tbsmenu_cmd_t *cmd) 419 { 420 free(cmd->argv); 421 free(cmd->buf); 422 } 423 424 /** Execute start menu entry. 425 * 426 * @param entry Start menu entry 427 * 428 * @return EOK on success or an error code 429 */ 430 static errno_t tbsmenu_entry_start(tbsmenu_entry_t *entry) 431 { 432 task_id_t id; 433 task_wait_t wait; 434 task_exit_t texit; 435 tbsmenu_cmd_t cmd; 436 int retval; 437 bool suspended; 438 errno_t rc; 439 ui_t *ui; 440 441 ui = ui_window_get_ui(entry->tbsmenu->window); 442 suspended = false; 443 444 rc = tbsmenu_cmd_split(entry->cmd, &cmd); 445 if (rc != EOK) 446 return rc; 447 448 /* Free up and clean console for the child task. */ 449 rc = ui_suspend(ui); 450 if (rc != EOK) 451 goto error; 452 453 suspended = true; 454 455 rc = task_spawnv(&id, &wait, cmd.argv[0], (const char *const *) 456 cmd.argv); 457 if (rc != EOK) 458 goto error; 459 460 rc = task_wait(&wait, &texit, &retval); 461 if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) 462 goto error; 463 464 /* Resume UI operation */ 465 rc = ui_resume(ui); 466 if (rc != EOK) 467 goto error; 468 469 (void) ui_paint(ui); 470 return EOK; 471 error: 472 tbsmenu_cmd_fini(&cmd); 473 if (suspended) 474 (void) ui_resume(ui); 475 (void) ui_paint(ui); 476 return rc; 477 } 478 301 479 /** @} 302 480 */ -
uspace/app/taskbar/tbsmenu.h
r7d78e466 r9bec33a 50 50 extern void tbsmenu_set_rect(tbsmenu_t *, gfx_rect_t *); 51 51 extern void tbsmenu_destroy(tbsmenu_t *); 52 extern errno_t tbsmenu_remove(tbsmenu_t *, tbsmenu_entry_t *, bool); 52 extern errno_t tbsmenu_add(tbsmenu_t *, const char *, const char *, 53 tbsmenu_entry_t **); 54 extern void tbsmenu_remove(tbsmenu_t *, tbsmenu_entry_t *, bool); 53 55 extern tbsmenu_entry_t *tbsmenu_first(tbsmenu_t *); 54 56 extern tbsmenu_entry_t *tbsmenu_last(tbsmenu_t *); -
uspace/app/taskbar/types/tbsmenu.h
r7d78e466 r9bec33a 43 43 #include <ui/fixed.h> 44 44 #include <ui/menu.h> 45 #include <ui/menuentry.h> 45 46 #include <ui/window.h> 46 47 … … 51 52 /** Link to tbsmenu->entries */ 52 53 link_t lentries; 54 /** Menu entry */ 55 ui_menu_entry_t *mentry; 56 /** Caption */ 57 char *caption; 58 /** Command to run */ 59 char *cmd; 53 60 } tbsmenu_entry_t; 54 61 … … 79 86 } tbsmenu_t; 80 87 88 /** Command split into individual parts */ 89 typedef struct { 90 /** Buffer holding broken down command */ 91 char *buf; 92 /** NULL-terminated array of string pointers */ 93 char **argv; 94 } tbsmenu_cmd_t; 95 81 96 #endif 82 97
Note:
See TracChangeset
for help on using the changeset viewer.