Changeset 34aad53d in mainline for uspace/app/taskbar/tbsmenu.c
- Timestamp:
- 2024-04-07T09:45:45Z (7 months ago)
- Children:
- c37c24c
- Parents:
- e4cc266 (diff), 522eecf (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/tbsmenu.c
re4cc266 r34aad53d 64 64 static void tbsmenu_smenu_entry_cb(ui_menu_entry_t *, void *); 65 65 static errno_t tbsmenu_entry_start(tbsmenu_entry_t *); 66 static void tbsmenu_cmd_fini(tbsmenu_cmd_t *); 66 67 67 68 /** Create taskbar start menu. … … 69 70 * @param window Containing window 70 71 * @param fixed Fixed layout to which start button will be added 72 * @param dspec Display specification (for passing to applications) 71 73 * @param rtbsmenu Place to store pointer to new start menu 72 74 * @return @c EOK on success or an error code 73 75 */ 74 76 errno_t tbsmenu_create(ui_window_t *window, ui_fixed_t *fixed, 75 tbsmenu_t **rtbsmenu)77 const char *dspec, tbsmenu_t **rtbsmenu) 76 78 { 77 79 ui_resource_t *res = ui_window_get_res(window); … … 85 87 } 86 88 89 tbsmenu->display_spec = str_dup(dspec); 90 if (tbsmenu->display_spec == NULL) { 91 rc = ENOMEM; 92 goto error; 93 } 94 87 95 rc = ui_pbutton_create(res, "Start", &tbsmenu->sbutton); 88 96 if (rc != EOK) … … 111 119 return EOK; 112 120 error: 121 if (tbsmenu != NULL && tbsmenu->display_spec != NULL) 122 free(tbsmenu->display_spec); 113 123 if (tbsmenu != NULL) 114 124 ui_pbutton_destroy(tbsmenu->sbutton); … … 134 144 bool terminal; 135 145 errno_t rc; 146 147 if (tbsmenu->repopath != NULL) 148 free(tbsmenu->repopath); 149 150 tbsmenu->repopath = str_dup(repopath); 151 if (tbsmenu->repopath == NULL) 152 return ENOMEM; 153 154 /* Remove existing entries */ 155 tentry = tbsmenu_first(tbsmenu); 156 while (tentry != NULL) { 157 tbsmenu_remove(tbsmenu, tentry, false); 158 tentry = tbsmenu_first(tbsmenu); 159 } 136 160 137 161 rc = tbarcfg_open(repopath, &tbcfg); … … 170 194 } 171 195 196 /** Reload start menu from repository (or schedule reload). 197 * 198 * @param tbsmenu Start menu 199 */ 200 void tbsmenu_reload(tbsmenu_t *tbsmenu) 201 { 202 if (!tbsmenu_is_open(tbsmenu)) 203 (void) tbsmenu_load(tbsmenu, tbsmenu->repopath); 204 else 205 tbsmenu->needs_reload = true; 206 } 207 172 208 /** Set start menu rectangle. 173 209 * … … 198 234 { 199 235 ui_menu_close(tbsmenu->smenu); 236 237 if (tbsmenu->needs_reload) 238 (void) tbsmenu_load(tbsmenu, tbsmenu->repopath); 200 239 } 201 240 … … 447 486 static errno_t tbsmenu_cmd_split(const char *str, tbsmenu_cmd_t *cmd) 448 487 { 488 char *buf; 449 489 char *arg; 450 490 char *next; 451 491 size_t cnt; 452 492 453 cmd->buf = str_dup(str);454 if ( cmd->buf == NULL)493 buf = str_dup(str); 494 if (buf == NULL) 455 495 return ENOMEM; 456 496 457 497 /* Count the entries */ 458 498 cnt = 0; 459 arg = str_tok( cmd->buf, " ", &next);499 arg = str_tok(buf, " ", &next); 460 500 while (arg != NULL) { 461 501 ++cnt; … … 464 504 465 505 /* Need to copy again as buf was mangled */ 466 free( cmd->buf);467 cmd->buf = str_dup(str);468 if ( cmd->buf == NULL)506 free(buf); 507 buf = str_dup(str); 508 if (buf == NULL) 469 509 return ENOMEM; 470 510 471 511 cmd->argv = calloc(cnt + 1, sizeof(char *)); 472 512 if (cmd->argv == NULL) { 473 free( cmd->buf);513 free(buf); 474 514 return ENOMEM; 475 515 } 476 516 477 /* Fill in pointers */517 /* Copy individual arguments */ 478 518 cnt = 0; 479 arg = str_tok( cmd->buf, " ", &next);519 arg = str_tok(buf, " ", &next); 480 520 while (arg != NULL) { 481 cmd->argv[cnt++] = arg; 521 cmd->argv[cnt] = str_dup(arg); 522 if (cmd->argv[cnt] == NULL) { 523 tbsmenu_cmd_fini(cmd); 524 return ENOMEM; 525 } 526 ++cnt; 527 482 528 arg = str_tok(next, " ", &next); 483 529 } … … 494 540 static void tbsmenu_cmd_fini(tbsmenu_cmd_t *cmd) 495 541 { 542 char **cp; 543 544 /* Free all pointers in NULL-terminated list */ 545 cp = cmd->argv; 546 while (*cp != NULL) { 547 free(*cp); 548 ++cp; 549 } 550 551 /* Free the array of pointers */ 496 552 free(cmd->argv); 497 free(cmd->buf); 553 } 554 555 /** Free command structure. 556 * 557 * @param cmd Command 558 * @param entry Start menu entry 559 * @param dspec Display specification 560 * @return EOK on success or an error code 561 */ 562 static errno_t tbsmenu_cmd_subst(tbsmenu_cmd_t *cmd, tbsmenu_entry_t *entry, 563 const char *dspec) 564 { 565 char **cp; 566 567 (void)entry; 568 569 /* Walk NULL-terminated list of arguments */ 570 cp = cmd->argv; 571 while (*cp != NULL) { 572 if (str_cmp(*cp, "%d") == 0) { 573 /* Display specification */ 574 free(*cp); 575 *cp = str_dup(dspec); 576 if (*cp == NULL) 577 return ENOMEM; 578 } 579 ++cp; 580 } 581 582 return EOK; 498 583 } 499 584 … … 516 601 char **cp; 517 602 const char **targv = NULL; 603 char *dspec = NULL; 604 sysarg_t idev_id; 605 int rv; 518 606 errno_t rc; 519 607 ui_t *ui; … … 522 610 suspended = false; 523 611 612 idev_id = ui_menu_get_idev_id(entry->tbsmenu->smenu); 613 614 rv = asprintf(&dspec, "%s?idev=%zu", 615 entry->tbsmenu->display_spec, (size_t)idev_id); 616 if (rv < 0) 617 return ENOMEM; 618 619 /* Split command string into individual arguments */ 524 620 rc = tbsmenu_cmd_split(entry->cmd, &cmd); 525 if (rc != EOK) 621 if (rc != EOK) { 622 free(dspec); 526 623 return rc; 624 } 625 626 /* Substitute metacharacters in command */ 627 rc = tbsmenu_cmd_subst(&cmd, entry, dspec); 628 if (rc != EOK) 629 goto error; 527 630 528 631 /* Free up and clean console for the child task. */ … … 542 645 } 543 646 544 targv = calloc(cnt + 3, sizeof(char **));647 targv = calloc(cnt + 5, sizeof(char **)); 545 648 if (targv == NULL) 546 649 goto error; 547 650 548 651 targv[0] = "/app/terminal"; 549 targv[1] = "-c"; 652 targv[1] = "-d"; 653 targv[2] = dspec; 654 targv[3] = "-c"; 550 655 551 656 for (i = 0; i <= cnt; i++) { 552 targv[ 2+ i] = cmd.argv[i];657 targv[4 + i] = cmd.argv[i]; 553 658 } 554 659 … … 578 683 return EOK; 579 684 error: 685 free(dspec); 580 686 if (targv != NULL) 581 687 free(targv);
Note:
See TracChangeset
for help on using the changeset viewer.