Changeset 46a47c0 in mainline


Ignore:
Timestamp:
2023-01-16T20:34:01Z (15 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b0ae23f
Parents:
b3eeae5
Message:

Make sure window is only show as inactive when it loses last focus

This currently affects the title bar and also the cursor in Terminal.

Location:
uspace
Files:
22 edited

Legend:

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

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * Copyright (c) 2012 Petr Koupy
    44 * All rights reserved.
     
    118118
    119119static void terminal_close_event(ui_window_t *, void *);
    120 static void terminal_focus_event(ui_window_t *, void *);
     120static void terminal_focus_event(ui_window_t *, void *, unsigned);
    121121static void terminal_kbd_event(ui_window_t *, void *, kbd_event_t *);
    122122static void terminal_pos_event(ui_window_t *, void *, pos_event_t *);
    123 static void terminal_unfocus_event(ui_window_t *, void *);
     123static void terminal_unfocus_event(ui_window_t *, void *, unsigned);
    124124
    125125static ui_window_cb_t terminal_window_cb = {
     
    833833
    834834/** Handle window focus event. */
    835 static void terminal_focus_event(ui_window_t *window, void *arg)
     835static void terminal_focus_event(ui_window_t *window, void *arg,
     836    unsigned nfocus)
    836837{
    837838        terminal_t *term = (terminal_t *) arg;
    838839
     840        (void)nfocus;
    839841        term->is_focused = true;
    840842        term_update(term);
     
    878880
    879881/** Handle window unfocus event. */
    880 static void terminal_unfocus_event(ui_window_t *window, void *arg)
     882static void terminal_unfocus_event(ui_window_t *window, void *arg,
     883    unsigned nfocus)
    881884{
    882885        terminal_t *term = (terminal_t *) arg;
    883886
    884         term->is_focused = false;
    885         term_update(term);
    886         gfx_update(term->gc);
     887        if (nfocus == 0) {
     888                term->is_focused = false;
     889                term_update(term);
     890                gfx_update(term->gc);
     891        }
    887892}
    888893
  • uspace/lib/display/include/types/display.h

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6060        void (*close_event)(void *);
    6161        /** Focus event */
    62         void (*focus_event)(void *);
     62        void (*focus_event)(void *, unsigned);
    6363        /** Keyboard event */
    6464        void (*kbd_event)(void *, kbd_event_t *);
     
    6868        void (*resize_event)(void *, gfx_rect_t *);
    6969        /** Unfocus event */
    70         void (*unfocus_event)(void *);
     70        void (*unfocus_event)(void *, unsigned);
    7171} display_wnd_cb_t;
    7272
  • uspace/lib/display/include/types/display/event.h

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5656} display_wnd_ev_type_t;
    5757
     58/** Display window focus event */
     59typedef struct {
     60        /** New number of foci */
     61        unsigned nfocus;
     62} display_wnd_focus_ev_t;
     63
    5864/** Display window resize event */
    5965typedef struct {
    6066        gfx_rect_t rect;
    6167} display_wnd_resize_ev_t;
     68
     69/** Display window unfocus event */
     70typedef struct {
     71        /** Number of remaining foci */
     72        unsigned nfocus;
     73} display_wnd_unfocus_ev_t;
    6274
    6375/** Display window event */
     
    6678        display_wnd_ev_type_t etype;
    6779        union {
     80                /** Focus event data */
     81                display_wnd_focus_ev_t focus;
    6882                /** Keyboard event data */
    6983                kbd_event_t kbd;
     
    7286                /** Resize event data */
    7387                display_wnd_resize_ev_t resize;
     88                /** Unfocus event data */
     89                display_wnd_unfocus_ev_t unfocus;
    7490        } ev;
    7591} display_wnd_ev_t;
  • uspace/lib/display/src/display.c

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    716716                case wev_focus:
    717717                        if (window->cb != NULL && window->cb->focus_event != NULL) {
    718                                 window->cb->focus_event(window->cb_arg);
     718                                window->cb->focus_event(window->cb_arg,
     719                                    event.ev.focus.nfocus);
    719720                        }
    720721                        break;
     
    739740                case wev_unfocus:
    740741                        if (window->cb != NULL && window->cb->unfocus_event != NULL) {
    741                                 window->cb->unfocus_event(window->cb_arg);
     742                                window->cb->unfocus_event(window->cb_arg,
     743                                    event.ev.unfocus.nfocus);
    742744                        }
    743745                        break;
  • uspace/lib/display/test/display.c

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5151
    5252static void test_close_event(void *);
    53 static void test_focus_event(void *);
     53static void test_focus_event(void *, unsigned);
    5454static void test_kbd_event(void *, kbd_event_t *);
    5555static void test_pos_event(void *, pos_event_t *);
    56 static void test_unfocus_event(void *);
     56static void test_unfocus_event(void *, unsigned);
    5757
    5858static errno_t test_window_create(void *, display_wnd_params_t *, sysarg_t *);
     
    166166        bool set_color_called;
    167167        bool close_event_called;
     168
    168169        bool focus_event_called;
    169170        bool kbd_event_called;
     
    16771678        resp.event_cnt = 1;
    16781679        resp.event.etype = wev_focus;
     1680        resp.event.ev.focus.nfocus = 42;
    16791681        resp.wnd_id = wnd->id;
    16801682        resp.focus_event_called = false;
     
    16931695        PCUT_ASSERT_INT_EQUALS(resp.event.etype,
    16941696            resp.revent.etype);
     1697        PCUT_ASSERT_INT_EQUALS(resp.event.ev.focus.nfocus,
     1698            resp.revent.ev.focus.nfocus);
    16951699
    16961700        rc = display_window_destroy(wnd);
     
    18961900        resp.event_cnt = 1;
    18971901        resp.event.etype = wev_unfocus;
     1902        resp.event.ev.unfocus.nfocus = 42;
    18981903        resp.wnd_id = wnd->id;
    18991904        resp.unfocus_event_called = false;
     
    19121917        PCUT_ASSERT_INT_EQUALS(resp.event.etype,
    19131918            resp.revent.etype);
     1919        PCUT_ASSERT_INT_EQUALS(resp.event.ev.focus.nfocus,
     1920            resp.revent.ev.focus.nfocus);
    19141921
    19151922        rc = display_window_destroy(wnd);
     
    20572064}
    20582065
    2059 static void test_focus_event(void *arg)
     2066static void test_focus_event(void *arg, unsigned nfocus)
    20602067{
    20612068        test_response_t *resp = (test_response_t *) arg;
    20622069
    20632070        resp->revent.etype = wev_focus;
     2071        resp->revent.ev.focus.nfocus = nfocus;
    20642072
    20652073        fibril_mutex_lock(&resp->event_lock);
     
    20952103}
    20962104
    2097 static void test_unfocus_event(void *arg)
     2105static void test_unfocus_event(void *arg, unsigned nfocus)
    20982106{
    20992107        test_response_t *resp = (test_response_t *) arg;
    21002108
    21012109        resp->revent.etype = wev_unfocus;
     2110        resp->revent.ev.unfocus.nfocus = nfocus;
    21022111
    21032112        fibril_mutex_lock(&resp->event_lock);
  • uspace/lib/ui/include/types/ui/control.h

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5656        ui_evclaim_t (*pos_event)(void *, pos_event_t *);
    5757        /** Unfocus */
    58         void (*unfocus)(void *);
     58        void (*unfocus)(void *, unsigned);
    5959} ui_control_ops_t;
    6060
  • uspace/lib/ui/include/types/ui/window.h

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    9797        void (*unmaximize)(ui_window_t *, void *);
    9898        void (*close)(ui_window_t *, void *);
    99         void (*focus)(ui_window_t *, void *);
     99        void (*focus)(ui_window_t *, void *, unsigned);
    100100        void (*kbd)(ui_window_t *, void *, kbd_event_t *);
    101101        errno_t (*paint)(ui_window_t *, void *);
    102102        void (*pos)(ui_window_t *, void *, pos_event_t *);
    103         void (*unfocus)(ui_window_t *, void *);
     103        void (*unfocus)(ui_window_t *, void *, unsigned);
    104104} ui_window_cb_t;
    105105
  • uspace/lib/ui/include/ui/control.h

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4949extern ui_evclaim_t ui_control_kbd_event(ui_control_t *, kbd_event_t *);
    5050extern ui_evclaim_t ui_control_pos_event(ui_control_t *, pos_event_t *);
    51 extern void ui_control_unfocus(ui_control_t *);
     51extern void ui_control_unfocus(ui_control_t *, unsigned);
    5252
    5353#endif
  • uspace/lib/ui/include/ui/fixed.h

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5151extern ui_evclaim_t ui_fixed_kbd_event(ui_fixed_t *, kbd_event_t *);
    5252extern ui_evclaim_t ui_fixed_pos_event(ui_fixed_t *, pos_event_t *);
    53 extern void ui_fixed_unfocus(ui_fixed_t *);
     53extern void ui_fixed_unfocus(ui_fixed_t *, unsigned);
    5454
    5555#endif
  • uspace/lib/ui/include/ui/window.h

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7171extern errno_t ui_window_def_paint(ui_window_t *);
    7272extern void ui_window_def_pos(ui_window_t *, pos_event_t *);
    73 extern void ui_window_def_unfocus(ui_window_t *);
     73extern void ui_window_def_unfocus(ui_window_t *, unsigned);
    7474
    7575#endif
  • uspace/lib/ui/private/window.h

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    116116extern void ui_window_send_unmaximize(ui_window_t *);
    117117extern void ui_window_send_close(ui_window_t *);
    118 extern void ui_window_send_focus(ui_window_t *);
     118extern void ui_window_send_focus(ui_window_t *, unsigned);
    119119extern void ui_window_send_kbd(ui_window_t *, kbd_event_t *);
    120120extern errno_t ui_window_send_paint(ui_window_t *);
    121121extern void ui_window_send_pos(ui_window_t *, pos_event_t *);
    122 extern void ui_window_send_unfocus(ui_window_t *);
     122extern void ui_window_send_unfocus(ui_window_t *, unsigned);
    123123extern errno_t ui_window_size_change(ui_window_t *, gfx_rect_t *,
    124124    ui_wnd_sc_op_t);
  • uspace/lib/ui/src/control.c

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    130130 *
    131131 * @param control Control
     132 * @param nfocus Number of remaining foci
    132133 */
    133 void ui_control_unfocus(ui_control_t *control)
     134void ui_control_unfocus(ui_control_t *control, unsigned nfocus)
    134135{
    135136        if (control->ops->unfocus != NULL)
    136                 control->ops->unfocus(control->ext);
     137                control->ops->unfocus(control->ext, nfocus);
    137138}
    138139
  • uspace/lib/ui/src/fixed.c

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4848static ui_evclaim_t ui_fixed_ctl_kbd_event(void *, kbd_event_t *);
    4949static ui_evclaim_t ui_fixed_ctl_pos_event(void *, pos_event_t *);
    50 static void ui_fixed_ctl_unfocus(void *);
     50static void ui_fixed_ctl_unfocus(void *, unsigned);
    5151
    5252/** Push button control ops */
     
    262262 *
    263263 * @param fixed Fixed layout
    264  */
    265 void ui_fixed_unfocus(ui_fixed_t *fixed)
    266 {
    267         ui_fixed_elem_t *elem;
    268 
    269         elem = ui_fixed_first(fixed);
    270         while (elem != NULL) {
    271                 ui_control_unfocus(elem->control);
     264 * @param nfocus Number of remaining foci
     265 */
     266void ui_fixed_unfocus(ui_fixed_t *fixed, unsigned nfocus)
     267{
     268        ui_fixed_elem_t *elem;
     269
     270        elem = ui_fixed_first(fixed);
     271        while (elem != NULL) {
     272                ui_control_unfocus(elem->control, nfocus);
    272273
    273274                elem = ui_fixed_next(elem);
     
    327328 *
    328329 * @param arg Argument (ui_fixed_t *)
    329  */
    330 void ui_fixed_ctl_unfocus(void *arg)
    331 {
    332         ui_fixed_t *fixed = (ui_fixed_t *) arg;
    333 
    334         ui_fixed_unfocus(fixed);
     330 * @param nfocus Number of remaining foci
     331 */
     332void ui_fixed_ctl_unfocus(void *arg, unsigned nfocus)
     333{
     334        ui_fixed_t *fixed = (ui_fixed_t *) arg;
     335
     336        ui_fixed_unfocus(fixed, nfocus);
    335337}
    336338
  • uspace/lib/ui/src/window.c

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5959
    6060static void dwnd_close_event(void *);
    61 static void dwnd_focus_event(void *);
     61static void dwnd_focus_event(void *, unsigned);
    6262static void dwnd_kbd_event(void *, kbd_event_t *);
    6363static void dwnd_pos_event(void *, pos_event_t *);
    6464static void dwnd_resize_event(void *, gfx_rect_t *);
    65 static void dwnd_unfocus_event(void *);
     65static void dwnd_unfocus_event(void *, unsigned);
    6666
    6767static display_wnd_cb_t dwnd_cb = {
     
    833833
    834834/** Handle window focus event. */
    835 static void dwnd_focus_event(void *arg)
     835static void dwnd_focus_event(void *arg, unsigned nfocus)
    836836{
    837837        ui_window_t *window = (ui_window_t *) arg;
     
    839839
    840840        ui_lock(ui);
     841        (void)nfocus;
    841842
    842843        if (window->wdecor != NULL) {
     
    845846        }
    846847
    847         ui_window_send_focus(window);
     848        ui_window_send_focus(window, nfocus);
    848849        ui_unlock(ui);
    849850}
     
    903904
    904905/** Handle window unfocus event. */
    905 static void dwnd_unfocus_event(void *arg)
     906static void dwnd_unfocus_event(void *arg, unsigned nfocus)
    906907{
    907908        ui_window_t *window = (ui_window_t *) arg;
     
    910911        ui_lock(ui);
    911912
    912         if (window->wdecor != NULL) {
     913        if (window->wdecor != NULL && nfocus == 0) {
    913914                ui_wdecor_set_active(window->wdecor, false);
    914915                ui_wdecor_paint(window->wdecor);
    915916        }
    916917
    917         ui_window_send_unfocus(window);
     918        ui_window_send_unfocus(window, nfocus);
    918919        ui_unlock(ui);
    919920}
     
    11041105 *
    11051106 * @param window Window
    1106  */
    1107 void ui_window_send_focus(ui_window_t *window)
     1107 * @param nfocus New number of foci
     1108 */
     1109void ui_window_send_focus(ui_window_t *window, unsigned nfocus)
    11081110{
    11091111        if (window->cb != NULL && window->cb->focus != NULL)
    1110                 window->cb->focus(window, window->arg);
     1112                window->cb->focus(window, window->arg, nfocus);
    11111113}
    11121114
     
    11501152 *
    11511153 * @param window Window
    1152  */
    1153 void ui_window_send_unfocus(ui_window_t *window)
     1154 * @param nfocus Number of remaining foci
     1155 */
     1156void ui_window_send_unfocus(ui_window_t *window, unsigned nfocus)
    11541157{
    11551158        if (window->cb != NULL && window->cb->unfocus != NULL)
    1156                 window->cb->unfocus(window, window->arg);
     1159                window->cb->unfocus(window, window->arg, nfocus);
    11571160        else
    1158                 return ui_window_def_unfocus(window);
     1161                return ui_window_def_unfocus(window, nfocus);
    11591162}
    11601163
     
    12921295 *
    12931296 * @param window Window
     1297 * @param nfocus Number of remaining foci
    12941298 * @return EOK on success or an error code
    12951299 */
    1296 void ui_window_def_unfocus(ui_window_t *window)
     1300void ui_window_def_unfocus(ui_window_t *window, unsigned nfocus)
    12971301{
    12981302        if (window->control != NULL)
    1299                 ui_control_unfocus(window->control);
     1303                ui_control_unfocus(window->control, nfocus);
    13001304}
    13011305
  • uspace/lib/ui/test/control.c

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4444static ui_evclaim_t test_ctl_kbd_event(void *, kbd_event_t *);
    4545static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
    46 static void test_ctl_unfocus(void *);
     46static void test_ctl_unfocus(void *, unsigned);
    4747
    4848static ui_control_ops_t test_ctl_ops = {
     
    7979        /** @c true iff unfocus was called */
    8080        bool unfocus;
     81        /** Number of remaining foci that was sent */
     82        unsigned unfocus_nfocus;
    8183} test_resp_t;
    8284
     
    223225        resp.unfocus = false;
    224226
    225         ui_control_unfocus(control);
     227        ui_control_unfocus(control, 42);
    226228        PCUT_ASSERT_TRUE(resp.unfocus);
     229        PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);
    227230
    228231        ui_control_delete(control);
     
    264267}
    265268
    266 static void test_ctl_unfocus(void *arg)
     269static void test_ctl_unfocus(void *arg, unsigned nfocus)
    267270{
    268271        test_resp_t *resp = (test_resp_t *) arg;
    269272
    270273        resp->unfocus = true;
     274        resp->unfocus_nfocus = nfocus;
    271275}
    272276
  • uspace/lib/ui/test/fixed.c

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4141static errno_t test_ctl_paint(void *);
    4242static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
    43 static void test_ctl_unfocus(void *);
     43static void test_ctl_unfocus(void *, unsigned);
    4444
    4545static ui_control_ops_t test_ctl_ops = {
     
    6666        /** @c true iff unfocus was called */
    6767        bool unfocus;
     68        /** Number of remaining foci */
     69        unsigned unfocus_nfocus;
    6870} test_resp_t;
    6971
     
    253255        resp.unfocus = false;
    254256
    255         ui_fixed_unfocus(fixed);
     257        ui_fixed_unfocus(fixed, 42);
    256258        PCUT_ASSERT_TRUE(resp.unfocus);
     259        PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);
    257260
    258261        ui_fixed_destroy(fixed);
     
    284287}
    285288
    286 static void test_ctl_unfocus(void *arg)
     289static void test_ctl_unfocus(void *arg, unsigned nfocus)
    287290{
    288291        test_resp_t *resp = (test_resp_t *) arg;
    289292
    290293        resp->unfocus = true;
     294        resp->unfocus_nfocus = nfocus;
    291295}
    292296
  • uspace/lib/ui/test/popup.c

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6464static errno_t test_ctl_paint(void *);
    6565static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
    66 static void test_ctl_unfocus(void *);
     66static void test_ctl_unfocus(void *, unsigned);
    6767
    6868static ui_control_ops_t test_ctl_ops = {
     
    9191        pos_event_t pos_event;
    9292        bool unfocus;
     93        unsigned unfocus_nfocus;
    9394} test_ctl_resp_t;
    9495
     
    341342}
    342343
    343 static void test_ctl_unfocus(void *arg)
     344static void test_ctl_unfocus(void *arg, unsigned nfocus)
    344345{
    345346        test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
    346347
    347348        resp->unfocus = true;
     349        resp->unfocus_nfocus = nfocus;
    348350}
    349351
  • uspace/lib/ui/test/window.c

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4949static void test_window_unmaximize(ui_window_t *, void *);
    5050static void test_window_close(ui_window_t *, void *);
    51 static void test_window_focus(ui_window_t *, void *);
     51static void test_window_focus(ui_window_t *, void *, unsigned);
    5252static void test_window_kbd(ui_window_t *, void *, kbd_event_t *);
    5353static errno_t test_window_paint(ui_window_t *, void *);
    5454static void test_window_pos(ui_window_t *, void *, pos_event_t *);
    55 static void test_window_unfocus(ui_window_t *, void *);
     55static void test_window_unfocus(ui_window_t *, void *, unsigned);
    5656
    5757static ui_window_cb_t test_window_cb = {
     
    7272static errno_t test_ctl_paint(void *);
    7373static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
    74 static void test_ctl_unfocus(void *);
     74static void test_ctl_unfocus(void *, unsigned);
    7575
    7676static ui_control_ops_t test_ctl_ops = {
     
    8787        bool close;
    8888        bool focus;
     89        unsigned focus_nfocus;
    8990        bool kbd;
    9091        kbd_event_t kbd_event;
     
    9394        pos_event_t pos_event;
    9495        bool unfocus;
     96        unsigned unfocus_nfocus;
    9597} test_cb_resp_t;
    9698
     
    102104        pos_event_t pos_event;
    103105        bool unfocus;
     106        unsigned unfocus_nfocus;
    104107} test_ctl_resp_t;
    105108
     
    530533        resp.unfocus = false;
    531534
    532         ui_window_def_unfocus(window);
     535        ui_window_def_unfocus(window, 42);
    533536        PCUT_ASSERT_TRUE(resp.unfocus);
     537        PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);
    534538
    535539        /* Need to remove first because we didn't implement the destructor */
     
    704708
    705709        /* Focus callback with no callbacks set */
    706         ui_window_send_focus(window);
     710        ui_window_send_focus(window, 42);
    707711
    708712        /* Focus callback with focus callback not implemented */
    709713        ui_window_set_cb(window, &dummy_window_cb, NULL);
    710         ui_window_send_focus(window);
     714        ui_window_send_focus(window, 42);
    711715
    712716        /* Focus callback with real callback set */
    713717        resp.focus = false;
    714718        ui_window_set_cb(window, &test_window_cb, &resp);
    715         ui_window_send_focus(window);
     719        ui_window_send_focus(window, 42);
    716720        PCUT_ASSERT_TRUE(resp.focus);
     721        PCUT_ASSERT_INT_EQUALS(42, resp.focus_nfocus);
    717722
    718723        ui_window_destroy(window);
     
    872877
    873878        /* Unfocus callback with no callbacks set */
    874         ui_window_send_unfocus(window);
     879        ui_window_send_unfocus(window, 42);
    875880
    876881        /* Unfocus callback with unfocus callback not implemented */
    877882        ui_window_set_cb(window, &dummy_window_cb, NULL);
    878         ui_window_send_unfocus(window);
     883        ui_window_send_unfocus(window, 42);
    879884
    880885        /* Unfocus callback with real callback set */
    881886        resp.close = false;
    882887        ui_window_set_cb(window, &test_window_cb, &resp);
    883         ui_window_send_unfocus(window);
     888        ui_window_send_unfocus(window, 42);
    884889        PCUT_ASSERT_TRUE(resp.unfocus);
     890        PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);
    885891
    886892        ui_window_destroy(window);
     
    916922}
    917923
    918 static void test_window_focus(ui_window_t *window, void *arg)
     924static void test_window_focus(ui_window_t *window, void *arg, unsigned nfocus)
    919925{
    920926        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
    921927
    922928        resp->focus = true;
     929        resp->focus_nfocus = nfocus;
    923930}
    924931
     
    949956}
    950957
    951 static void test_window_unfocus(ui_window_t *window, void *arg)
     958static void test_window_unfocus(ui_window_t *window, void *arg, unsigned nfocus)
    952959{
    953960        test_cb_resp_t *resp = (test_cb_resp_t *) arg;
    954961
    955962        resp->unfocus = true;
     963        resp->unfocus_nfocus = nfocus;
    956964}
    957965
     
    974982}
    975983
    976 static void test_ctl_unfocus(void *arg)
     984static void test_ctl_unfocus(void *arg, unsigned nfocus)
    977985{
    978986        test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
    979987
    980988        resp->unfocus = true;
     989        resp->unfocus_nfocus = nfocus;
    981990}
    982991
  • uspace/srv/hid/display/client.c

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    257257 * @param client Client
    258258 * @param ewindow Window that the message is targetted to
    259  *
    260  * @return EOK on success or an error code
    261  */
    262 errno_t ds_client_post_focus_event(ds_client_t *client, ds_window_t *ewindow)
     259 * @param event Focus event data
     260 *
     261 * @return EOK on success or an error code
     262 */
     263errno_t ds_client_post_focus_event(ds_client_t *client, ds_window_t *ewindow,
     264    display_wnd_focus_ev_t *event)
    263265{
    264266        ds_window_ev_t *wevent;
     
    270272        wevent->window = ewindow;
    271273        wevent->event.etype = wev_focus;
     274        wevent->event.ev.focus = *event;
    272275        list_append(&wevent->levents, &client->events);
    273276
     
    373376 * @param client Client
    374377 * @param ewindow Window that the message is targetted to
    375  *
    376  * @return EOK on success or an error code
    377  */
    378 errno_t ds_client_post_unfocus_event(ds_client_t *client, ds_window_t *ewindow)
     378 * @param event Unfocus event data
     379 *
     380 * @return EOK on success or an error code
     381 */
     382errno_t ds_client_post_unfocus_event(ds_client_t *client, ds_window_t *ewindow,
     383    display_wnd_unfocus_ev_t *event)
    379384{
    380385        ds_window_ev_t *wevent;
     
    386391        wevent->window = ewindow;
    387392        wevent->event.etype = wev_unfocus;
     393        wevent->event.ev.unfocus = *event;
    388394        list_append(&wevent->levents, &client->events);
    389395
  • uspace/srv/hid/display/client.h

    rb3eeae5 r46a47c0  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5555extern void ds_client_purge_window_events(ds_client_t *, ds_window_t *);
    5656extern errno_t ds_client_post_close_event(ds_client_t *, ds_window_t *);
    57 extern errno_t ds_client_post_focus_event(ds_client_t *, ds_window_t *);
     57extern errno_t ds_client_post_focus_event(ds_client_t *, ds_window_t *,
     58    display_wnd_focus_ev_t *);
    5859extern errno_t ds_client_post_kbd_event(ds_client_t *, ds_window_t *,
    5960    kbd_event_t *);
     
    6263extern errno_t ds_client_post_resize_event(ds_client_t *, ds_window_t *,
    6364    gfx_rect_t *);
    64 extern errno_t ds_client_post_unfocus_event(ds_client_t *, ds_window_t *);
     65extern errno_t ds_client_post_unfocus_event(ds_client_t *, ds_window_t *,
     66    display_wnd_unfocus_ev_t *);
    6567
    6668#endif
  • uspace/srv/hid/display/test/client.c

    rb3eeae5 r46a47c0  
    240240        display_wnd_params_t params;
    241241        ds_window_t *rwindow;
     242        display_wnd_focus_ev_t efocus;
    242243        display_wnd_ev_t revent;
    243244        bool called_cb = NULL;
     
    271272        PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
    272273
    273         rc = ds_client_post_focus_event(client, wnd);
     274        efocus.nfocus = 42;
     275
     276        rc = ds_client_post_focus_event(client, wnd, &efocus);
    274277        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    275278        PCUT_ASSERT_TRUE(called_cb);
     
    279282        PCUT_ASSERT_EQUALS(wnd, rwindow);
    280283        PCUT_ASSERT_EQUALS(wev_focus, revent.etype);
     284        PCUT_ASSERT_INT_EQUALS(efocus.nfocus, revent.ev.focus.nfocus);
    281285
    282286        rc = ds_client_get_event(client, &rwindow, &revent);
     
    504508        display_wnd_params_t params;
    505509        ds_window_t *rwindow;
     510        display_wnd_unfocus_ev_t eunfocus;
    506511        display_wnd_ev_t revent;
    507512        bool called_cb = NULL;
     
    535540        PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
    536541
    537         rc = ds_client_post_unfocus_event(client, wnd);
     542        eunfocus.nfocus = 42;
     543
     544        rc = ds_client_post_unfocus_event(client, wnd, &eunfocus);
    538545        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    539546        PCUT_ASSERT_TRUE(called_cb);
     
    543550        PCUT_ASSERT_EQUALS(wnd, rwindow);
    544551        PCUT_ASSERT_EQUALS(wev_unfocus, revent.etype);
     552        PCUT_ASSERT_INT_EQUALS(eunfocus.nfocus, revent.ev.unfocus.nfocus);
    545553
    546554        rc = ds_client_get_event(client, &rwindow, &revent);
  • uspace/srv/hid/display/window.c

    rb3eeae5 r46a47c0  
    680680errno_t ds_window_post_focus_event(ds_window_t *wnd)
    681681{
     682        display_wnd_focus_ev_t efocus;
    682683        errno_t rc;
    683684        ds_wmclient_t *wmclient;
     
    685686        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_post_focus_event");
    686687
    687         rc = ds_client_post_focus_event(wnd->client, wnd);
     688        /* Increase focus counter */
     689        ++wnd->nfocus;
     690        efocus.nfocus = wnd->nfocus;
     691
     692        rc = ds_client_post_focus_event(wnd->client, wnd, &efocus);
    688693        if (rc != EOK)
    689694                return rc;
    690 
    691         /* Increase focus counter */
    692         ++wnd->nfocus;
    693695
    694696        /* Notify window managers about window information change */
     
    709711errno_t ds_window_post_unfocus_event(ds_window_t *wnd)
    710712{
     713        display_wnd_unfocus_ev_t eunfocus;
    711714        errno_t rc;
    712715        ds_wmclient_t *wmclient;
     
    714717        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_post_unfocus_event");
    715718
    716         rc = ds_client_post_unfocus_event(wnd->client, wnd);
     719        /* Decrease focus counter */
     720        --wnd->nfocus;
     721        eunfocus.nfocus = wnd->nfocus;
     722
     723        rc = ds_client_post_unfocus_event(wnd->client, wnd, &eunfocus);
    717724        if (rc != EOK)
    718725                return rc;
    719 
    720         /* Decrease focus counter */
    721         --wnd->nfocus;
    722726
    723727        /* Notify window managers about window information change */
Note: See TracChangeset for help on using the changeset viewer.