Changeset 5d9403d5 in mainline


Ignore:
Timestamp:
2023-10-13T20:27:14Z (15 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7aa9fa1b
Parents:
788c76e3
Message:

Open start menu using Enter, fix input device ID

Pressing Enter opens start menu, but only if it is focused.
Need to fix input device ID so that the menu is opened in the
correct seat, both in case of clicking and in case a key is
pressed to open the menu.

Location:
uspace/app/taskbar
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskbar/taskbar.c

    r788c76e3 r5d9403d5  
    4949
    5050static void taskbar_wnd_close(ui_window_t *, void *);
     51static void taskbar_wnd_kbd(ui_window_t *, void *, kbd_event_t *);
    5152static void taskbar_wnd_pos(ui_window_t *, void *, pos_event_t *);
    5253
    5354static ui_window_cb_t window_cb = {
    5455        .close = taskbar_wnd_close,
     56        .kbd = taskbar_wnd_kbd,
    5557        .pos = taskbar_wnd_pos
    5658};
     
    6668
    6769        ui_quit(taskbar->ui);
     70}
     71
     72/** Window received keyboard event.
     73 *
     74 * @param window Window
     75 * @param arg Argument (taskbar)
     76 * @param event Keyboard event
     77 */
     78static void taskbar_wnd_kbd(ui_window_t *window, void *arg, kbd_event_t *event)
     79{
     80        taskbar_t *taskbar = (taskbar_t *) arg;
     81        ui_evclaim_t claim;
     82
     83        /* Remember ID of device that sent the last event */
     84        taskbar->wndlist->ev_idev_id = event->kbd_id;
     85        taskbar->tbsmenu->ev_idev_id = event->kbd_id;
     86
     87        claim = ui_window_def_kbd(window, event);
     88        if (claim == ui_claimed)
     89                return;
     90
     91        if (event->type == KEY_PRESS && (event->mods & KM_CTRL) == 0 &&
     92            (event->mods & KM_ALT) == 0 && (event->mods & KM_SHIFT) == 0 &&
     93            event->key == KC_ENTER) {
     94                if (!tbsmenu_is_open(taskbar->tbsmenu))
     95                        tbsmenu_open(taskbar->tbsmenu);
     96        }
    6897}
    6998
     
    79108
    80109        /* Remember ID of device that sent the last event */
    81         taskbar->wndlist->ev_pos_id = event->pos_id;
     110        taskbar->wndlist->ev_idev_id = event->pos_id;
     111        taskbar->tbsmenu->ev_idev_id = event->pos_id;
    82112
    83113        ui_window_def_pos(window, event);
  • uspace/app/taskbar/tbsmenu.c

    r788c76e3 r5d9403d5  
    9292            (void *)tbsmenu);
    9393
     94        ui_pbutton_set_default(tbsmenu->sbutton, true);
     95
    9496        rc = ui_fixed_add(fixed, ui_pbutton_ctl(tbsmenu->sbutton));
    9597        if (rc != EOK)
     
    166168        tbsmenu->rect = *rect;
    167169        ui_pbutton_set_rect(tbsmenu->sbutton, rect);
     170}
     171
     172/** Open taskbar start menu.
     173 *
     174 * @param tbsmenu Start menu
     175 */
     176void tbsmenu_open(tbsmenu_t *tbsmenu)
     177{
     178        (void) ui_menu_open(tbsmenu->smenu, &tbsmenu->rect,
     179            tbsmenu->ev_idev_id);
     180}
     181
     182/** Close taskbar start menu.
     183 *
     184 * @param tbsmenu Start menu
     185 */
     186void tbsmenu_close(tbsmenu_t *tbsmenu)
     187{
     188        ui_menu_close(tbsmenu->smenu);
     189}
     190
     191/** Determine if taskbar start menu is open.
     192 *
     193 * @param tbsmenu Start menu
     194 * @return @c true iff start menu is open
     195 */
     196bool tbsmenu_is_open(tbsmenu_t *tbsmenu)
     197{
     198        return ui_menu_is_open(tbsmenu->smenu);
    168199}
    169200
     
    352383        tbsmenu_t *tbsmenu = (tbsmenu_t *)arg;
    353384
    354         if (!ui_menu_is_open(tbsmenu->smenu)) {
    355                 // XXX ev_pos_id is not set!!!
    356                 (void) ui_menu_open(tbsmenu->smenu, &tbsmenu->rect,
    357                     tbsmenu->ev_pos_id);
     385        if (!tbsmenu_is_open(tbsmenu)) {
     386                tbsmenu_open(tbsmenu);
    358387        } else {
    359388                /* menu is open */
    360                 ui_menu_close(tbsmenu->smenu);
     389                tbsmenu_close(tbsmenu);
    361390        }
    362391}
  • uspace/app/taskbar/tbsmenu.h

    r788c76e3 r5d9403d5  
    4949extern errno_t tbsmenu_load(tbsmenu_t *, const char *);
    5050extern void tbsmenu_set_rect(tbsmenu_t *, gfx_rect_t *);
     51extern void tbsmenu_open(tbsmenu_t *);
     52extern void tbsmenu_close(tbsmenu_t *);
     53extern bool tbsmenu_is_open(tbsmenu_t *);
    5154extern void tbsmenu_destroy(tbsmenu_t *);
    5255extern errno_t tbsmenu_add(tbsmenu_t *, const char *, const char *,
  • uspace/app/taskbar/test/tbsmenu.c

    r788c76e3 r5d9403d5  
    6969}
    7070
     71/** Test tbsmenu_open/close/is_open() */
     72PCUT_TEST(open_close_is_open)
     73{
     74        errno_t rc;
     75        ui_t *ui = NULL;
     76        ui_wnd_params_t params;
     77        ui_window_t *window = NULL;
     78        ui_fixed_t *fixed = NULL;
     79        tbsmenu_t *tbsmenu = NULL;
     80
     81        rc = ui_create_disp(NULL, &ui);
     82        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     83
     84        ui_wnd_params_init(&params);
     85        params.caption = "Hello";
     86
     87        rc = ui_window_create(ui, &params, &window);
     88        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     89        PCUT_ASSERT_NOT_NULL(window);
     90
     91        rc = ui_fixed_create(&fixed);
     92        ui_window_add(window, ui_fixed_ctl(fixed));
     93
     94        rc = tbsmenu_create(window, fixed, &tbsmenu);
     95        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     96
     97        PCUT_ASSERT_FALSE(tbsmenu_is_open(tbsmenu));
     98        tbsmenu_open(tbsmenu);
     99        PCUT_ASSERT_TRUE(tbsmenu_is_open(tbsmenu));
     100        tbsmenu_close(tbsmenu);
     101        PCUT_ASSERT_FALSE(tbsmenu_is_open(tbsmenu));
     102
     103        tbsmenu_destroy(tbsmenu);
     104        ui_window_destroy(window);
     105        ui_destroy(ui);
     106}
     107
    71108PCUT_EXPORT(tbsmenu);
  • uspace/app/taskbar/types/tbsmenu.h

    r788c76e3 r5d9403d5  
    8080        list_t entries;
    8181
    82         // TODO libstartmenu instance
    83 
    84         /** Position ID of last position event */
    85         sysarg_t ev_pos_id;
     82        /** Device ID of last input event */
     83        sysarg_t ev_idev_id;
    8684} tbsmenu_t;
    8785
  • uspace/app/taskbar/types/wndlist.h

    r788c76e3 r5d9403d5  
    8484        wndmgt_t *wndmgt;
    8585
    86         /** Position ID of last position event */
    87         sysarg_t ev_pos_id;
     86        /** Device ID of last input event */
     87        sysarg_t ev_idev_id;
    8888} wndlist_t;
    8989
  • uspace/app/taskbar/wndlist.c

    r788c76e3 r5d9403d5  
    720720
    721721        /* ID of device that clicked the button */
    722         dev_id = entry->wndlist->ev_pos_id;
     722        dev_id = entry->wndlist->ev_idev_id;
    723723
    724724        (void) wndmgt_activate_window(entry->wndlist->wndmgt,
Note: See TracChangeset for help on using the changeset viewer.