Changeset d92b8e8f in mainline
- Timestamp:
- 2024-03-04T14:12:26Z (10 months ago)
- Branches:
- master
- Children:
- e229148
- Parents:
- ee3b28a9
- git-author:
- Jiri Svoboda <jiri@…> (2024-03-03 18:12:02)
- git-committer:
- Jiri Svoboda <jiri@…> (2024-03-04 14:12:26)
- Location:
- uspace
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/taskbar.c
ree3b28a9 rd92b8e8f 131 131 gfx_rect_t scr_rect; 132 132 gfx_rect_t rect; 133 char *dspec = NULL; 134 char *qmark; 133 135 errno_t rc; 134 136 135 137 taskbar = calloc(1, sizeof(taskbar_t)); 136 138 if (taskbar == NULL) { 139 printf("Out of memory.\n"); 137 140 rc = ENOMEM; 138 141 goto error; 139 142 } 143 144 dspec = str_dup(display_spec); 145 if (dspec == NULL) { 146 printf("Out of memory.\n"); 147 rc = ENOMEM; 148 goto error; 149 } 150 151 /* Remove additional arguments */ 152 qmark = str_chr(dspec, '?'); 153 if (qmark != NULL) 154 *qmark = '\0'; 140 155 141 156 rc = ui_create(display_spec, &taskbar->ui); … … 198 213 } 199 214 200 rc = tbsmenu_create(taskbar->window, taskbar->fixed, &taskbar->tbsmenu); 215 rc = tbsmenu_create(taskbar->window, taskbar->fixed, dspec, 216 &taskbar->tbsmenu); 201 217 if (rc != EOK) { 202 218 printf("Error creating start menu.\n"); … … 293 309 } 294 310 311 free(dspec); 295 312 *rtaskbar = taskbar; 296 313 return EOK; 297 314 error: 315 if (dspec != NULL) 316 free(dspec); 298 317 if (taskbar->lst != NULL) 299 318 tbarcfg_listener_destroy(taskbar->lst); … … 308 327 if (taskbar->ui != NULL) 309 328 ui_destroy(taskbar->ui); 329 free(taskbar); 310 330 return rc; 311 331 -
uspace/app/taskbar/taskbar.sif
ree3b28a9 rd92b8e8f 1 [sif](){[entries](){[entry]([caption]=[~N~avigator][cmd]=[/app/nav][terminal]=[y]){}[entry]([caption]=[Text ~E~ditor][cmd]=[/app/edit][terminal]=[y]){}[entry]([caption]=[Co~m~mand Line][cmd]=[/app/bdsh][terminal]=[y]){}[entry]([caption]=[~C~alculator][cmd]=[/app/calculator ][terminal]=[n]){}[entry]([separator]=[y]){}[entry]([caption]=[~U~I Demo][cmd]=[/app/uidemo][terminal]=[n]){}[entry]([caption]=[~G~FX Demo][cmd]=[/app/gfxdemo ui][terminal]=[n]){}[entry]([caption]=[~B~arber Pole][cmd]=[/app/barber][terminal]=[n]){}[entry]([caption]=[~T~etris][cmd]=[/app/tetris][terminal]=[y]){}[entry]([separator]=[y]){}[entry]([caption]=[~D~isplay Configuration][cmd]=[/app/display-cfg][terminal]=[n]){}[entry]([caption]=[Ta~s~kbar Configuration][cmd]=[/app/taskbar-cfg][terminal]=[n]){}[entry]([separator]=[y]){}[entry]([caption]=[Tas~k~ Monitor (top)][cmd]=[/app/top][terminal]=[y]){}[entry]([caption]=[~F~disk Disk Editor][cmd]=[/app/fdisk][terminal]=[y]){}}}1 [sif](){[entries](){[entry]([caption]=[~N~avigator][cmd]=[/app/nav][terminal]=[y]){}[entry]([caption]=[Text ~E~ditor][cmd]=[/app/edit][terminal]=[y]){}[entry]([caption]=[Co~m~mand Line][cmd]=[/app/bdsh][terminal]=[y]){}[entry]([caption]=[~C~alculator][cmd]=[/app/calculator -d %d][terminal]=[n]){}[entry]([separator]=[y]){}[entry]([caption]=[~U~I Demo][cmd]=[/app/uidemo -d %d][terminal]=[n]){}[entry]([caption]=[~G~FX Demo][cmd]=[/app/gfxdemo -d %d ui][terminal]=[n]){}[entry]([caption]=[~B~arber Pole][cmd]=[/app/barber -d %d][terminal]=[n]){}[entry]([caption]=[~T~etris][cmd]=[/app/tetris][terminal]=[y]){}[entry]([separator]=[y]){}[entry]([caption]=[~D~isplay Configuration][cmd]=[/app/display-cfg -d %d][terminal]=[n]){}[entry]([caption]=[Ta~s~kbar Configuration][cmd]=[/app/taskbar-cfg -d %d][terminal]=[n]){}[entry]([separator]=[y]){}[entry]([caption]=[Tas~k~ Monitor (top)][cmd]=[/app/top][terminal]=[y]){}[entry]([caption]=[~F~disk Disk Editor][cmd]=[/app/fdisk][terminal]=[y]){}}} -
uspace/app/taskbar/tbsmenu.c
ree3b28a9 rd92b8e8f 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); … … 476 486 static errno_t tbsmenu_cmd_split(const char *str, tbsmenu_cmd_t *cmd) 477 487 { 488 char *buf; 478 489 char *arg; 479 490 char *next; 480 491 size_t cnt; 481 492 482 cmd->buf = str_dup(str);483 if ( cmd->buf == NULL)493 buf = str_dup(str); 494 if (buf == NULL) 484 495 return ENOMEM; 485 496 486 497 /* Count the entries */ 487 498 cnt = 0; 488 arg = str_tok( cmd->buf, " ", &next);499 arg = str_tok(buf, " ", &next); 489 500 while (arg != NULL) { 490 501 ++cnt; … … 493 504 494 505 /* Need to copy again as buf was mangled */ 495 free( cmd->buf);496 cmd->buf = str_dup(str);497 if ( cmd->buf == NULL)506 free(buf); 507 buf = str_dup(str); 508 if (buf == NULL) 498 509 return ENOMEM; 499 510 500 511 cmd->argv = calloc(cnt + 1, sizeof(char *)); 501 512 if (cmd->argv == NULL) { 502 free( cmd->buf);513 free(buf); 503 514 return ENOMEM; 504 515 } 505 516 506 /* Fill in pointers */517 /* Copy individual arguments */ 507 518 cnt = 0; 508 arg = str_tok( cmd->buf, " ", &next);519 arg = str_tok(buf, " ", &next); 509 520 while (arg != NULL) { 510 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 511 528 arg = str_tok(next, " ", &next); 512 529 } … … 523 540 static void tbsmenu_cmd_fini(tbsmenu_cmd_t *cmd) 524 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 */ 525 552 free(cmd->argv); 526 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; 527 583 } 528 584 … … 545 601 char **cp; 546 602 const char **targv = NULL; 603 char *dspec = NULL; 604 sysarg_t idev_id; 605 int rv; 547 606 errno_t rc; 548 607 ui_t *ui; … … 551 610 suspended = false; 552 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 */ 553 620 rc = tbsmenu_cmd_split(entry->cmd, &cmd); 554 if (rc != EOK) 621 if (rc != EOK) { 622 free(dspec); 555 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; 556 630 557 631 /* Free up and clean console for the child task. */ … … 571 645 } 572 646 573 targv = calloc(cnt + 3, sizeof(char **));647 targv = calloc(cnt + 5, sizeof(char **)); 574 648 if (targv == NULL) 575 649 goto error; 576 650 577 651 targv[0] = "/app/terminal"; 578 targv[1] = "-c"; 652 targv[1] = "-d"; 653 targv[2] = dspec; 654 targv[3] = "-c"; 579 655 580 656 for (i = 0; i <= cnt; i++) { 581 targv[ 2+ i] = cmd.argv[i];657 targv[4 + i] = cmd.argv[i]; 582 658 } 583 659 … … 607 683 return EOK; 608 684 error: 685 free(dspec); 609 686 if (targv != NULL) 610 687 free(targv); -
uspace/app/taskbar/tbsmenu.h
ree3b28a9 rd92b8e8f 46 46 #include "types/tbsmenu.h" 47 47 48 extern errno_t tbsmenu_create(ui_window_t *, ui_fixed_t *, tbsmenu_t **); 48 extern errno_t tbsmenu_create(ui_window_t *, ui_fixed_t *, const char *, 49 tbsmenu_t **); 49 50 extern errno_t tbsmenu_load(tbsmenu_t *, const char *); 50 51 extern void tbsmenu_reload(tbsmenu_t *); -
uspace/app/taskbar/test/tbsmenu.c
ree3b28a9 rd92b8e8f 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 61 61 ui_window_add(window, ui_fixed_ctl(fixed)); 62 62 63 rc = tbsmenu_create(window, fixed, &tbsmenu);63 rc = tbsmenu_create(window, fixed, UI_DISPLAY_DEFAULT, &tbsmenu); 64 64 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 65 65 … … 92 92 ui_window_add(window, ui_fixed_ctl(fixed)); 93 93 94 rc = tbsmenu_create(window, fixed, &tbsmenu);94 rc = tbsmenu_create(window, fixed, UI_DISPLAY_DEFAULT, &tbsmenu); 95 95 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 96 96 -
uspace/app/taskbar/types/tbsmenu.h
ree3b28a9 rd92b8e8f 91 91 /** Need to reload menu when possible */ 92 92 bool needs_reload; 93 94 /** Display specification */ 95 char *display_spec; 93 96 } tbsmenu_t; 94 97 95 98 /** Command split into individual parts */ 96 99 typedef struct { 97 /** Buffer holding broken down command */98 char *buf;99 100 /** NULL-terminated array of string pointers */ 100 101 char **argv; -
uspace/lib/ui/include/ui/menu.h
ree3b28a9 rd92b8e8f 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 59 59 extern ui_evclaim_t ui_menu_pos_event(ui_menu_t *, gfx_coord2_t *, 60 60 pos_event_t *); 61 extern sysarg_t ui_menu_get_idev_id(ui_menu_t *); 61 62 62 63 #endif -
uspace/lib/ui/include/ui/popup.h
ree3b28a9 rd92b8e8f 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 54 54 extern ui_resource_t *ui_popup_get_res(ui_popup_t *); 55 55 extern gfx_context_t *ui_popup_get_gc(ui_popup_t *); 56 extern sysarg_t ui_popup_get_idev_id(ui_popup_t *); 56 57 57 58 #endif -
uspace/lib/ui/private/menu.h
ree3b28a9 rd92b8e8f 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 70 70 /** Callback argument */ 71 71 void *arg; 72 /** ID of device that activated entry */ 73 sysarg_t idev_id; 72 74 }; 73 75 -
uspace/lib/ui/private/popup.h
ree3b28a9 rd92b8e8f 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 58 58 /** Placement rectangle */ 59 59 gfx_rect_t place; 60 /** ID of device that sent input event */ 61 sysarg_t idev_id; 60 62 }; 61 63 -
uspace/lib/ui/src/menu.c
ree3b28a9 rd92b8e8f 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 578 578 ui_menu_t *menu = (ui_menu_t *)arg; 579 579 580 menu->idev_id = ui_popup_get_idev_id(menu->popup); 580 581 ui_menu_kbd_event(menu, event); 581 582 } … … 592 593 gfx_coord2_t spos; 593 594 595 menu->idev_id = ui_popup_get_idev_id(menu->popup); 596 594 597 spos.x = 0; 595 598 spos.y = 0; … … 641 644 } 642 645 646 /** Get ID of last device that input event. 647 * 648 * @param menu Menu 649 * @return Input device ID 650 */ 651 sysarg_t ui_menu_get_idev_id(ui_menu_t *menu) 652 { 653 return menu->idev_id; 654 } 655 643 656 /** @} 644 657 */ -
uspace/lib/ui/src/popup.c
ree3b28a9 rd92b8e8f 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 190 190 } 191 191 192 /** Get ID of device that sent the last position event. 193 * 194 * @param popup Popup window 195 * @return Input device ID 196 */ 197 sysarg_t ui_popup_get_idev_id(ui_popup_t *popup) 198 { 199 return popup->idev_id; 200 } 201 192 202 /** Handle close event in popup window. 193 203 * … … 214 224 ui_popup_t *popup = (ui_popup_t *)arg; 215 225 226 /* Remember ID of device that sent the last event */ 227 popup->idev_id = event->kbd_id; 228 216 229 if (popup->cb != NULL && popup->cb->kbd != NULL) 217 230 popup->cb->kbd(popup, popup->arg, event); … … 229 242 ui_popup_t *popup = (ui_popup_t *)arg; 230 243 244 /* Remember ID of device that sent the last event */ 245 popup->idev_id = event->pos_id; 246 231 247 if (popup->cb != NULL && popup->cb->pos != NULL) 232 248 popup->cb->pos(popup, popup->arg, event);
Note:
See TracChangeset
for help on using the changeset viewer.