Changeset 4055fe63 in mainline


Ignore:
Timestamp:
2021-06-04T20:02:36Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Children:
4b72e81
Parents:
2e6394e
Message:

Deliver close event to popup window when appropriate

That is, when focus changes or when user clicks outside of the
popup window.

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/menu.c

    r2e6394e r4055fe63  
    6161};
    6262
     63static void ui_menu_popup_close(ui_popup_t *, void *);
    6364static void ui_menu_popup_pos(ui_popup_t *, void *, pos_event_t *);
    6465
    6566static ui_popup_cb_t ui_menu_popup_cb = {
     67        .close = ui_menu_popup_close,
    6668        .pos = ui_menu_popup_pos
    6769};
     
    366368        } else {
    367369                /* Press outside menu - close it */
    368 //              if (event->type == POS_PRESS)
    369 //                      ui_menu_bar_select(menu->mbar, NULL, NULL);
     370                if (event->type == POS_PRESS)
     371                        ui_menu_bar_select(menu->mbar, NULL, NULL);
    370372        }
    371373
    372374        return ui_unclaimed;
     375}
     376
     377/** Handle close event in menu popup window.
     378 *
     379 * @param popup Menu popup window
     380 * @param arg Argument (ui_menu_t *)
     381 */
     382static void ui_menu_popup_close(ui_popup_t *popup, void *arg)
     383{
     384        ui_menu_t *menu = (ui_menu_t *)arg;
     385
     386        /* Close the menu */
     387        ui_menu_bar_select(menu->mbar, NULL, NULL);
    373388}
    374389
  • uspace/lib/ui/src/menubar.c

    r2e6394e r4055fe63  
    6161static errno_t ui_menu_bar_ctl_paint(void *);
    6262static ui_evclaim_t ui_menu_bar_ctl_pos_event(void *, pos_event_t *);
    63 static void ui_menu_bar_ctl_unfocus(void *);
    6463
    6564/** Menu bar control ops */
     
    6867        .paint = ui_menu_bar_ctl_paint,
    6968        .pos_event = ui_menu_bar_ctl_pos_event,
    70         .unfocus = ui_menu_bar_ctl_unfocus
    7169};
    7270
     
    317315}
    318316
    319 /** Handle menu bar window unfocus notification.
    320  *
    321  * @param mbar Menu bar
    322  */
    323 void ui_menu_bar_unfocus(ui_menu_bar_t *mbar)
    324 {
    325 //      ui_menu_bar_select(mbar, NULL, NULL);
    326 }
    327 
    328317/** Destroy menu bar control.
    329318 *
     
    362351}
    363352
    364 /** Handle menu bar control window unfocus notification.
    365  *
    366  * @param arg Argument (ui_menu_bar_t *)
    367  */
    368 void ui_menu_bar_ctl_unfocus(void *arg)
    369 {
    370         ui_menu_bar_t *mbar = (ui_menu_bar_t *) arg;
    371 
    372         ui_menu_bar_unfocus(mbar);
    373 }
    374 
    375353/** @}
    376354 */
  • uspace/lib/ui/src/popup.c

    r2e6394e r4055fe63  
    4646#include "../private/popup.h"
    4747
     48static void ui_popup_window_close(ui_window_t *, void *);
    4849static void ui_popup_window_pos(ui_window_t *, void *, pos_event_t *);
    4950
    5051static ui_window_cb_t ui_popup_window_cb = {
     52        .close = ui_popup_window_close,
    5153        .pos = ui_popup_window_pos
    5254};
     
    185187}
    186188
     189/** Handle close event in popup window.
     190 *
     191 * @param window Window
     192 * @param arg Argument (ui_popup_t *)
     193 */
     194static void ui_popup_window_close(ui_window_t *window, void *arg)
     195{
     196        ui_popup_t *popup = (ui_popup_t *)arg;
     197
     198        if (popup->cb != NULL && popup->cb->close != NULL)
     199                popup->cb->close(popup, popup->arg);
     200}
     201
    187202/** Handle position event in popup window.
    188203 *
  • uspace/srv/hid/display/seat.c

    r2e6394e r4055fe63  
    104104                ds_window_bring_to_top(wnd);
    105105        }
     106
     107        /* When focus changes, popup window should be closed */
     108        ds_seat_set_popup(seat, NULL);
    106109}
    107110
     
    113116void ds_seat_set_popup(ds_seat_t *seat, ds_window_t *wnd)
    114117{
     118        if (wnd == seat->popup)
     119                return;
     120
     121        if (seat->popup != NULL) {
     122                /* Window is no longer the popup window, send close request */
     123                ds_client_post_close_event(seat->popup->client,
     124                    seat->popup);
     125        }
     126
    115127        seat->popup = wnd;
    116128}
     
    139151
    140152        if (seat->popup == wnd)
    141                 seat->popup = NULL;
     153                ds_seat_set_popup(seat, NULL);
    142154}
    143155
     
    427439
    428440        wnd = ds_display_window_by_pos(seat->display, &seat->pntpos);
    429         /*
    430          * Deliver event to popup window, unless the pointer is over
    431          * it (in which case it will be delivered to that window
    432          * below, anyway.
    433          */
     441
     442        /* Click outside popup window */
     443        if (event->type == POS_PRESS && wnd != seat->popup) {
     444                /* Close popup window */
     445                ds_seat_set_popup(seat, NULL);
     446        }
     447
     448        /* Deliver event to popup window. */
    434449        if (seat->popup != NULL) {
    435450                rc = ds_window_post_pos_event(seat->popup, event);
Note: See TracChangeset for help on using the changeset viewer.