Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/seat.c

    r554a5f1 rd7f82635  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    104104                ds_window_bring_to_top(wnd);
    105105        }
    106 }
    107 
    108 /** Evacuate focus from window.
     106
     107        /* When focus changes, popup window should be closed */
     108        ds_seat_set_popup(seat, NULL);
     109}
     110
     111/** Set seat popup window.
     112 *
     113 * @param seat Seat
     114 * @param wnd Popup window
     115 */
     116void ds_seat_set_popup(ds_seat_t *seat, ds_window_t *wnd)
     117{
     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
     127        seat->popup = wnd;
     128}
     129
     130/** Evacuate seat references to window.
    109131 *
    110132 * If seat's focus is @a wnd, it will be set to a different window.
     133 * If seat's popup window is @a wnd, it will be set to NULL.
    111134 *
    112135 * @param seat Seat
    113136 * @param wnd Window to evacuate focus from
    114137 */
    115 void ds_seat_evac_focus(ds_seat_t *seat, ds_window_t *wnd)
     138void ds_seat_evac_wnd_refs(ds_seat_t *seat, ds_window_t *wnd)
    116139{
    117140        ds_window_t *nwnd;
    118141
    119142        if (seat->focus == wnd) {
    120                 nwnd = ds_display_next_window(wnd);
     143                nwnd = ds_display_prev_window(wnd);
    121144                if (nwnd == NULL)
    122                         nwnd = ds_display_first_window(wnd->display);
     145                        nwnd = ds_display_last_window(wnd->display);
    123146                if (nwnd == wnd)
    124147                        nwnd = NULL;
     
    126149                ds_seat_set_focus(seat, nwnd);
    127150        }
     151
     152        if (seat->popup == wnd)
     153                ds_seat_set_popup(seat, NULL);
     154}
     155
     156/** Switch focus to another window.
     157 *
     158 * @param seat Seat
     159 * @param wnd Window to evacuate focus from
     160 */
     161void ds_seat_switch_focus(ds_seat_t *seat)
     162{
     163        ds_window_t *nwnd;
     164
     165        if (seat->focus != NULL)
     166                nwnd = ds_display_prev_window(seat->focus);
     167        else
     168                nwnd = NULL;
     169
     170        if (nwnd == NULL)
     171                nwnd = ds_display_last_window(seat->display);
     172
     173        if (nwnd != NULL)
     174                ds_seat_set_focus(seat, nwnd);
    128175}
    129176
     
    143190        if (event->type == KEY_PRESS && alt_or_shift && event->key == KC_TAB) {
    144191                /* On Alt-Tab or Shift-Tab, switch focus to next window */
    145                 ds_seat_evac_focus(seat, seat->focus);
     192                ds_seat_switch_focus(seat);
    146193                return EOK;
    147194        }
    148195
    149         dwindow = seat->focus;
     196        dwindow = seat->popup;
     197        if (dwindow == NULL)
     198                dwindow = seat->focus;
     199
    150200        if (dwindow == NULL)
    151201                return EOK;
     
    307357        /* Focus window on button press */
    308358        if (event->type == PTD_PRESS && event->btn_num == 1) {
    309                 if (wnd != NULL) {
     359                if (wnd != NULL && (wnd->flags & wndf_popup) == 0) {
    310360                        ds_seat_set_focus(seat, wnd);
    311361                }
     
    390440        wnd = ds_display_window_by_pos(seat->display, &seat->pntpos);
    391441
    392         if (seat->focus != wnd) {
     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. */
     449        if (seat->popup != NULL) {
     450                rc = ds_window_post_pos_event(seat->popup, event);
     451                if (rc != EOK)
     452                        return rc;
     453        }
     454
     455        if (seat->focus != wnd && seat->focus != NULL) {
    393456                rc = ds_window_post_pos_event(seat->focus, event);
    394457                if (rc != EOK)
     
    404467                ds_seat_set_client_cursor(seat, wnd->cursor);
    405468
    406                 rc = ds_window_post_pos_event(wnd, event);
    407                 if (rc != EOK)
    408                         return rc;
     469                /*
     470                 * Only deliver event if we didn't already deliver it
     471                 * to the same window above.
     472                 */
     473                if (wnd != seat->popup) {
     474                        rc = ds_window_post_pos_event(wnd, event);
     475                        if (rc != EOK)
     476                                return rc;
     477                }
    409478        } else {
    410479                /* Not over a window */
Note: See TracChangeset for help on using the changeset viewer.