Changeset f1f433d in mainline
- Timestamp:
- 2022-11-04T20:54:04Z (2 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3a6d44b7
- Parents:
- fc00f0d
- Location:
- uspace
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/wndlist.c
rfc00f0d rf1f433d 48 48 static void wndlist_wm_window_added(void *, sysarg_t); 49 49 static void wndlist_wm_window_removed(void *, sysarg_t); 50 static void wndlist_wm_window_changed(void *, sysarg_t); 50 51 51 52 static wndmgt_cb_t wndlist_wndmgt_cb = { 52 53 .window_added = wndlist_wm_window_added, 53 .window_removed = wndlist_wm_window_removed 54 .window_removed = wndlist_wm_window_removed, 55 .window_changed = wndlist_wm_window_changed 54 56 }; 55 57 … … 233 235 if (!paint) 234 236 return EOK; 237 238 return wndlist_repaint(wndlist); 239 } 240 241 /** Update window list entry. 242 * 243 * @param wndlist Window list 244 * @param entry Window list entry 245 * @return @c EOK on success or an error code 246 */ 247 errno_t wndlist_update(wndlist_t *wndlist, wndlist_entry_t *entry, 248 const char *caption) 249 { 250 errno_t rc; 251 assert(entry->wndlist == wndlist); 252 253 rc = ui_pbutton_set_caption(entry->button, caption); 254 if (rc != EOK) 255 return rc; 256 257 rc = ui_pbutton_paint(entry->button); 258 if (rc != EOK) 259 return rc; 235 260 236 261 return wndlist_repaint(wndlist); … … 325 350 } 326 351 352 /** Handle WM window changed event. 353 * 354 * @param arg Argument (wndlist_t *) 355 * @param wnd_id Window ID 356 */ 357 static void wndlist_wm_window_changed(void *arg, sysarg_t wnd_id) 358 { 359 wndlist_t *wndlist = (wndlist_t *)arg; 360 wndmgt_window_info_t *winfo = NULL; 361 wndlist_entry_t *entry; 362 errno_t rc; 363 364 printf("wm_window_changed: wndlist=%p wnd_id=%zu\n", 365 (void *)wndlist, wnd_id); 366 367 entry = wndlist_entry_by_id(wndlist, wnd_id); 368 if (entry == NULL) 369 return; 370 371 rc = wndmgt_get_window_info(wndlist->wndmgt, wnd_id, &winfo); 372 if (rc != EOK) 373 return; 374 375 (void) wndlist_update(wndlist, entry, winfo->caption); 376 wndmgt_free_window_info(winfo); 377 } 378 327 379 /** Find window list entry by ID. 328 380 * -
uspace/app/taskbar/wndlist.h
rfc00f0d rf1f433d 49 49 extern errno_t wndlist_append(wndlist_t *, sysarg_t, const char *, bool); 50 50 extern errno_t wndlist_remove(wndlist_t *, wndlist_entry_t *, bool); 51 extern errno_t wndlist_update(wndlist_t *, wndlist_entry_t *, const char *); 51 52 extern void wndlist_set_entry_rect(wndlist_t *, wndlist_entry_t *); 52 53 extern wndlist_entry_t *wndlist_entry_by_id(wndlist_t *, sysarg_t); -
uspace/lib/ui/include/ui/pbutton.h
rfc00f0d rf1f433d 56 56 extern void ui_pbutton_set_rect(ui_pbutton_t *, gfx_rect_t *); 57 57 extern void ui_pbutton_set_default(ui_pbutton_t *, bool); 58 extern errno_t ui_pbutton_set_caption(ui_pbutton_t *, const char *); 58 59 extern errno_t ui_pbutton_paint(ui_pbutton_t *); 59 60 extern void ui_pbutton_press(ui_pbutton_t *); -
uspace/lib/ui/private/pbutton.h
rfc00f0d rf1f433d 62 62 gfx_rect_t rect; 63 63 /** Caption */ 64 c onst char *caption;64 char *caption; 65 65 /** Button is selected as default */ 66 66 bool isdefault; -
uspace/lib/ui/src/pbutton.c
rfc00f0d rf1f433d 114 114 115 115 ui_control_delete(pbutton->control); 116 free(pbutton->caption); 116 117 free(pbutton); 117 118 } … … 183 184 { 184 185 pbutton->isdefault = isdefault; 186 } 187 188 /** Set push button caption. 189 * 190 * @param pbutton Button 191 * @param caption New caption 192 * @return EOK on success, ENOMEM if out of memory 193 */ 194 errno_t ui_pbutton_set_caption(ui_pbutton_t *pbutton, const char *caption) 195 { 196 char *dcaption; 197 198 dcaption = str_dup(caption); 199 if (dcaption == NULL) 200 return ENOMEM; 201 202 free(pbutton->caption); 203 pbutton->caption = dcaption; 204 return EOK; 185 205 } 186 206 -
uspace/lib/ui/test/pbutton.c
rfc00f0d rf1f433d 190 190 } 191 191 192 /** Set caption sets internal field */ 193 PCUT_TEST(set_caption) 194 { 195 ui_pbutton_t *pbutton; 196 errno_t rc; 197 198 rc = ui_pbutton_create(NULL, "Hello", &pbutton); 199 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 200 201 PCUT_ASSERT_STR_EQUALS("Hello", pbutton->caption); 202 203 rc = ui_pbutton_set_caption(pbutton, "World"); 204 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 205 206 PCUT_ASSERT_STR_EQUALS("World", pbutton->caption); 207 208 ui_pbutton_destroy(pbutton); 209 } 210 192 211 /** Paint button */ 193 212 PCUT_TEST(paint) -
uspace/lib/wndmgt/include/types/wndmgt.h
rfc00f0d rf1f433d 53 53 /** Window removed */ 54 54 void (*window_removed)(void *, sysarg_t); 55 /** Window changed */ 56 void (*window_changed)(void *, sysarg_t); 55 57 } wndmgt_cb_t; 56 58 … … 60 62 wmev_window_added, 61 63 /** Window removed */ 62 wmev_window_removed 64 wmev_window_removed, 65 /** Window changed */ 66 wmev_window_changed 63 67 } wndmgt_ev_type_t; 64 68 -
uspace/lib/wndmgt/src/wndmgt.c
rfc00f0d rf1f433d 387 387 } 388 388 break; 389 case wmev_window_changed: 390 if (wndmgt->cb != NULL && 391 wndmgt->cb->window_changed != NULL) { 392 wndmgt->cb->window_changed(wndmgt->cb_arg, 393 event.wnd_id); 394 } 395 break; 389 396 } 390 397 } -
uspace/lib/wndmgt/test/wndmgt.c
rfc00f0d rf1f433d 54 54 static void test_window_added(void *, sysarg_t); 55 55 static void test_window_removed(void *, sysarg_t); 56 static void test_window_changed(void *, sysarg_t); 56 57 57 58 static wndmgt_ops_t test_wndmgt_srv_ops = { … … 65 66 static wndmgt_cb_t test_wndmgt_cb = { 66 67 .window_added = test_window_added, 67 .window_removed = test_window_removed 68 .window_removed = test_window_removed, 69 .window_changed = test_window_changed 68 70 }; 69 71 … … 98 100 bool window_removed_called; 99 101 sysarg_t window_removed_wnd_id; 102 103 bool window_changed_called; 104 sysarg_t window_changed_wnd_id; 100 105 101 106 fibril_condvar_t event_cv; … … 529 534 } 530 535 536 /** Window changed event can be delivered from server to client callback function */ 537 PCUT_TEST(window_changed_deliver) 538 { 539 errno_t rc; 540 service_id_t sid; 541 wndmgt_t *wndmgt = NULL; 542 test_response_t resp; 543 544 async_set_fallback_port_handler(test_wndmgt_conn, &resp); 545 546 // FIXME This causes this test to be non-reentrant! 547 rc = loc_server_register(test_wndmgt_server); 548 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 549 550 rc = loc_service_register(test_wndmgt_svc, &sid); 551 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 552 553 rc = wndmgt_open(test_wndmgt_svc, &test_wndmgt_cb, &resp, &wndmgt); 554 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 555 PCUT_ASSERT_NOT_NULL(wndmgt); 556 PCUT_ASSERT_NOT_NULL(resp.srv); 557 558 resp.event_cnt = 1; 559 resp.event.etype = wmev_window_changed; 560 resp.event.wnd_id = 42; 561 resp.window_changed_called = false; 562 fibril_mutex_initialize(&resp.event_lock); 563 fibril_condvar_initialize(&resp.event_cv); 564 wndmgt_srv_ev_pending(resp.srv); 565 566 /* Wait for the event handler to be called. */ 567 fibril_mutex_lock(&resp.event_lock); 568 while (!resp.window_changed_called) { 569 fibril_condvar_wait(&resp.event_cv, &resp.event_lock); 570 } 571 fibril_mutex_unlock(&resp.event_lock); 572 573 /* Verify that the event was delivered correctly */ 574 PCUT_ASSERT_INT_EQUALS(resp.event.etype, 575 resp.revent.etype); 576 577 wndmgt_close(wndmgt); 578 579 rc = loc_service_unregister(sid); 580 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 581 } 582 531 583 /** Test window management service connection. */ 532 584 static void test_wndmgt_conn(ipc_call_t *icall, void *arg) … … 569 621 resp->window_removed_called = true; 570 622 resp->window_removed_wnd_id = wnd_id; 623 fibril_condvar_broadcast(&resp->event_cv); 624 fibril_mutex_unlock(&resp->event_lock); 625 } 626 627 static void test_window_changed(void *arg, sysarg_t wnd_id) 628 { 629 test_response_t *resp = (test_response_t *) arg; 630 631 resp->revent.etype = wmev_window_changed; 632 633 fibril_mutex_lock(&resp->event_lock); 634 resp->window_changed_called = true; 635 resp->window_changed_wnd_id = wnd_id; 571 636 fibril_condvar_broadcast(&resp->event_cv); 572 637 fibril_mutex_unlock(&resp->event_lock); -
uspace/srv/hid/display/test/wmclient.c
rfc00f0d rf1f433d 107 107 } 108 108 109 /** Test ds_wmclient_get_event(), ds_wmclient_post_wnd_removed_event(). */ 110 PCUT_TEST(client_get_post_wnd_removed_event) 111 { 112 ds_display_t *disp; 113 ds_wmclient_t *wmclient; 114 wndmgt_ev_t revent; 115 bool called_cb = NULL; 116 sysarg_t wnd_id; 117 errno_t rc; 118 119 rc = ds_display_create(NULL, df_none, &disp); 120 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 121 122 rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, &called_cb, 123 &wmclient); 124 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 125 126 called_cb = false; 127 wnd_id = 42; 128 129 rc = ds_wmclient_get_event(wmclient, &revent); 130 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 131 132 rc = ds_wmclient_post_wnd_removed_event(wmclient, wnd_id); 133 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 134 PCUT_ASSERT_TRUE(called_cb); 135 136 rc = ds_wmclient_get_event(wmclient, &revent); 137 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 138 PCUT_ASSERT_EQUALS(wnd_id, revent.wnd_id); 139 PCUT_ASSERT_EQUALS(wmev_window_removed, revent.etype); 140 141 rc = ds_wmclient_get_event(wmclient, &revent); 142 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 143 144 ds_wmclient_destroy(wmclient); 145 ds_display_destroy(disp); 146 } 147 148 /** Test ds_wmclient_get_event(), ds_wmclient_post_wnd_changed_event(). */ 149 PCUT_TEST(client_get_post_wnd_changed_event) 150 { 151 ds_display_t *disp; 152 ds_wmclient_t *wmclient; 153 wndmgt_ev_t revent; 154 bool called_cb = NULL; 155 sysarg_t wnd_id; 156 errno_t rc; 157 158 rc = ds_display_create(NULL, df_none, &disp); 159 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 160 161 rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, &called_cb, 162 &wmclient); 163 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 164 165 called_cb = false; 166 wnd_id = 42; 167 168 rc = ds_wmclient_get_event(wmclient, &revent); 169 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 170 171 rc = ds_wmclient_post_wnd_changed_event(wmclient, wnd_id); 172 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 173 PCUT_ASSERT_TRUE(called_cb); 174 175 rc = ds_wmclient_get_event(wmclient, &revent); 176 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 177 PCUT_ASSERT_EQUALS(wnd_id, revent.wnd_id); 178 PCUT_ASSERT_EQUALS(wmev_window_changed, revent.etype); 179 180 rc = ds_wmclient_get_event(wmclient, &revent); 181 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 182 183 ds_wmclient_destroy(wmclient); 184 ds_display_destroy(disp); 185 } 186 109 187 /** Test ds_wmclient_purge_events() */ 110 188 PCUT_TEST(purge_events) -
uspace/srv/hid/display/window.c
rfc00f0d rf1f433d 45 45 #include <stdlib.h> 46 46 #include <str.h> 47 #include <wndmgt.h> 47 48 #include "client.h" 48 49 #include "display.h" 49 50 #include "seat.h" 50 51 #include "window.h" 52 #include "wmclient.h" 51 53 52 54 static void ds_window_invalidate_cb(void *, gfx_rect_t *); … … 933 935 { 934 936 char *dcaption; 937 ds_wmclient_t *wmclient; 935 938 936 939 dcaption = str_dup(caption); … … 940 943 free(wnd->caption); 941 944 wnd->caption = dcaption; 945 946 /* Notify window managers about window information change */ 947 wmclient = ds_display_first_wmclient(wnd->display); 948 while (wmclient != NULL) { 949 ds_wmclient_post_wnd_changed_event(wmclient, wnd->id); 950 wmclient = ds_display_next_wmclient(wmclient); 951 } 942 952 943 953 return EOK; -
uspace/srv/hid/display/wmclient.c
rfc00f0d rf1f433d 184 184 } 185 185 186 /** Post window changed event to the WM client's message queue. 187 * 188 * @param wmclient WM client 189 * @param wnd_id Window ID of the added window 190 * 191 * @return EOK on success or an error code 192 */ 193 errno_t ds_wmclient_post_wnd_changed_event(ds_wmclient_t *wmclient, 194 sysarg_t wnd_id) 195 { 196 ds_wmclient_ev_t *wevent; 197 198 wevent = calloc(1, sizeof(ds_wmclient_ev_t)); 199 if (wevent == NULL) 200 return ENOMEM; 201 202 wevent->wmclient = wmclient; 203 wevent->event.etype = wmev_window_changed; 204 wevent->event.wnd_id = wnd_id; 205 list_append(&wevent->levents, &wmclient->events); 206 207 /* Notify the client */ 208 // TODO Do not send more than once until client drains the queue 209 if (wmclient->cb != NULL && wmclient->cb->ev_pending != NULL) 210 wmclient->cb->ev_pending(wmclient->cb_arg); 211 212 return EOK; 213 } 214 186 215 /** @} 187 216 */ -
uspace/srv/hid/display/wmclient.h
rfc00f0d rf1f433d 48 48 extern errno_t ds_wmclient_post_wnd_added_event(ds_wmclient_t *, sysarg_t); 49 49 extern errno_t ds_wmclient_post_wnd_removed_event(ds_wmclient_t *, sysarg_t); 50 extern errno_t ds_wmclient_post_wnd_changed_event(ds_wmclient_t *, sysarg_t); 50 51 extern void ds_wmclient_purge_events(ds_wmclient_t *); 51 52
Note:
See TracChangeset
for help on using the changeset viewer.