Changeset 5de852c in mainline


Ignore:
Timestamp:
2022-01-11T13:12:15Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bfc0fc6
Parents:
59768c7
git-author:
Jiri Svoboda <jiri@…> (2022-01-10 20:11:54)
git-committer:
Jiri Svoboda <jiri@…> (2022-01-11 13:12:15)
Message:

Coordinate keyboard event delivery between application and UI framework

If an application sets its own keyboard event handler, it needs to call
ui_window_def_kbd() to deliver events to the window's UI control tree.
Menubar should be able to capture these events so that they are not
accidentally acted upon by the application keyboard handler.

Location:
uspace
Files:
8 edited

Legend:

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

    r59768c7 r5de852c  
    186186        calc_t *calc = (calc_t *) arg;
    187187
     188        if (ui_window_def_kbd(window, event) == ui_claimed)
     189                return;
     190
    188191        if (event->type == KEY_PRESS && (event->mods & KM_CTRL) != 0) {
    189192                switch (event->key) {
  • uspace/app/edit/edit.c

    r59768c7 r5de852c  
    22302230        pane.keymod = event->mods;
    22312231
     2232        if (ui_window_def_kbd(window, event) == ui_claimed)
     2233                return;
     2234
    22322235        if (event->type == KEY_PRESS) {
    22332236                key_handle_press(event);
  • uspace/lib/ui/include/ui/menu.h

    r59768c7 r5de852c  
    3939#include <errno.h>
    4040#include <gfx/coord.h>
     41#include <io/kbd_event.h>
    4142#include <io/pos_event.h>
    4243#include <stdbool.h>
     
    5758extern bool ui_menu_is_open(ui_menu_t *);
    5859extern errno_t ui_menu_paint(ui_menu_t *, gfx_coord2_t *);
     60extern ui_evclaim_t ui_menu_kbd_event(ui_menu_t *, kbd_event_t *);
    5961extern ui_evclaim_t ui_menu_pos_event(ui_menu_t *, gfx_coord2_t *,
    6062    pos_event_t *);
  • uspace/lib/ui/include/ui/window.h

    r59768c7 r5de852c  
    6565extern void ui_window_set_ctl_cursor(ui_window_t *, ui_stock_cursor_t);
    6666extern errno_t ui_window_paint(ui_window_t *);
    67 extern void ui_window_def_kbd(ui_window_t *, kbd_event_t *);
     67extern ui_evclaim_t ui_window_def_kbd(ui_window_t *, kbd_event_t *);
    6868extern errno_t ui_window_def_paint(ui_window_t *);
    6969extern void ui_window_def_pos(ui_window_t *, pos_event_t *);
  • uspace/lib/ui/src/menu.c

    r59768c7 r5de852c  
    6666static void ui_menu_popup_kbd(ui_popup_t *, void *, kbd_event_t *);
    6767static void ui_menu_popup_pos(ui_popup_t *, void *, pos_event_t *);
     68static void ui_menu_key_press_unmod(ui_menu_t *, kbd_event_t *);
    6869
    6970static ui_popup_cb_t ui_menu_popup_cb = {
     
    493494}
    494495
    495 /** Handle close event in menu popup window.
    496  *
    497  * @param popup Menu popup window
    498  * @param arg Argument (ui_menu_t *)
    499  */
    500 static void ui_menu_popup_close(ui_popup_t *popup, void *arg)
    501 {
    502         ui_menu_t *menu = (ui_menu_t *)arg;
    503 
    504         /* Deactivate menu bar, close menu */
    505         ui_menu_bar_deactivate(menu->mbar);
     496/** Handle keyboard event in menu.
     497 *
     498 * @param menu Menu
     499 * @param event Keyboard event
     500 * @return ui_claimed iff the event was claimed
     501 */
     502ui_evclaim_t ui_menu_kbd_event(ui_menu_t *menu, kbd_event_t *event)
     503{
     504        if (event->type == KEY_PRESS && (event->mods &
     505            (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
     506                ui_menu_key_press_unmod(menu, event);
     507        }
     508
     509        return ui_claimed;
    506510}
    507511
     
    612616}
    613617
     618/** Handle close event in menu popup window.
     619 *
     620 * @param popup Menu popup window
     621 * @param arg Argument (ui_menu_t *)
     622 */
     623static void ui_menu_popup_close(ui_popup_t *popup, void *arg)
     624{
     625        ui_menu_t *menu = (ui_menu_t *)arg;
     626
     627        /* Deactivate menu bar, close menu */
     628        ui_menu_bar_deactivate(menu->mbar);
     629}
     630
    614631/** Handle keyboard event in menu popup window.
    615632 *
     
    622639        ui_menu_t *menu = (ui_menu_t *)arg;
    623640
    624         if (event->type == KEY_PRESS && (event->mods &
    625             (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
    626                 ui_menu_key_press_unmod(menu, event);
    627         }
     641        ui_menu_kbd_event(menu, event);
    628642}
    629643
  • uspace/lib/ui/src/menubar.c

    r59768c7 r5de852c  
    371371        if (event->type == KEY_PRESS && (event->mods &
    372372            (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
    373                 ui_menu_bar_key_press_unmod(mbar, event);
     373                return ui_menu_bar_key_press_unmod(mbar, event);
     374        }
     375
     376        if (mbar->active)
    374377                return ui_claimed;
    375         }
    376 
    377         return ui_claimed;
     378
     379        return ui_unclaimed;
    378380}
    379381
  • uspace/lib/ui/src/window.c

    r59768c7 r5de852c  
    963963                window->cb->kbd(window, window->arg, kbd);
    964964        else
    965                 return ui_window_def_kbd(window, kbd);
     965                ui_window_def_kbd(window, kbd);
    966966}
    967967
     
    10051005 *
    10061006 * @param window Window
    1007  */
    1008 void ui_window_def_kbd(ui_window_t *window, kbd_event_t *kbd)
     1007 * @return ui_claimed iff event was claimed
     1008 */
     1009ui_evclaim_t ui_window_def_kbd(ui_window_t *window, kbd_event_t *kbd)
    10091010{
    10101011        if (window->control != NULL)
    1011                 ui_control_kbd_event(window->control, kbd);
     1012                return ui_control_kbd_event(window->control, kbd);
     1013
     1014        return ui_unclaimed;
    10121015}
    10131016
  • uspace/lib/ui/test/menubar.c

    r59768c7 r5de852c  
    188188        event.type = KEY_PRESS;
    189189        event.key = KC_ESCAPE;
    190         claimed = ui_menu_kbd_pos_event(mbar, &event);
     190        claimed = ui_menu_bar_kbd_event(mbar, &event);
    191191        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    192192        PCUT_ASSERT_EQUALS(ui_claimed, claimed);
Note: See TracChangeset for help on using the changeset viewer.