Changeset 35cffea in mainline for uspace/srv/hid/display
- Timestamp:
- 2022-05-19T08:02:31Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ad698f4
- Parents:
- fd05ea6
- git-author:
- Jiri Svoboda <jiri@…> (2022-05-18 17:02:12)
- git-committer:
- Jiri Svoboda <jiri@…> (2022-05-19 08:02:31)
- Location:
- uspace/srv/hid/display
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/dsops.c
rfd05ea6 r35cffea 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 49 49 static errno_t disp_window_move(void *, sysarg_t, gfx_coord2_t *); 50 50 static errno_t disp_window_get_pos(void *, sysarg_t, gfx_coord2_t *); 51 static errno_t disp_window_get_max_rect(void *, sysarg_t, gfx_rect_t *); 51 52 static errno_t disp_window_resize_req(void *, sysarg_t, 52 53 display_wnd_rsztype_t, gfx_coord2_t *); 53 54 static errno_t disp_window_resize(void *, sysarg_t, gfx_coord2_t *, 54 55 gfx_rect_t *); 56 static errno_t disp_window_maximize(void *, sysarg_t); 57 static errno_t disp_window_unmaximize(void *, sysarg_t); 55 58 static errno_t disp_window_set_cursor(void *, sysarg_t, display_stock_cursor_t); 56 59 static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *); … … 63 66 .window_move = disp_window_move, 64 67 .window_get_pos = disp_window_get_pos, 68 .window_get_max_rect = disp_window_get_max_rect, 65 69 .window_resize_req = disp_window_resize_req, 66 70 .window_resize = disp_window_resize, 71 .window_maximize = disp_window_maximize, 72 .window_unmaximize = disp_window_unmaximize, 67 73 .window_set_cursor = disp_window_set_cursor, 68 74 .get_event = disp_get_event, … … 175 181 } 176 182 183 static errno_t disp_window_get_max_rect(void *arg, sysarg_t wnd_id, 184 gfx_rect_t *rect) 185 { 186 ds_client_t *client = (ds_client_t *) arg; 187 ds_window_t *wnd; 188 189 ds_display_lock(client->display); 190 191 wnd = ds_client_find_window(client, wnd_id); 192 if (wnd == NULL) { 193 ds_display_unlock(client->display); 194 return ENOENT; 195 } 196 197 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_max_rect()"); 198 ds_window_get_max_rect(wnd, rect); 199 ds_display_unlock(client->display); 200 return EOK; 201 } 202 177 203 static errno_t disp_window_resize_req(void *arg, sysarg_t wnd_id, 178 204 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos) … … 219 245 } 220 246 247 static errno_t disp_window_maximize(void *arg, sysarg_t wnd_id) 248 { 249 ds_client_t *client = (ds_client_t *) arg; 250 ds_window_t *wnd; 251 errno_t rc; 252 253 ds_display_lock(client->display); 254 255 wnd = ds_client_find_window(client, wnd_id); 256 if (wnd == NULL) { 257 ds_display_unlock(client->display); 258 return ENOENT; 259 } 260 261 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_maximize()"); 262 rc = ds_window_maximize(wnd); 263 ds_display_unlock(client->display); 264 return rc; 265 } 266 267 static errno_t disp_window_unmaximize(void *arg, sysarg_t wnd_id) 268 { 269 ds_client_t *client = (ds_client_t *) arg; 270 ds_window_t *wnd; 271 errno_t rc; 272 273 ds_display_lock(client->display); 274 275 wnd = ds_client_find_window(client, wnd_id); 276 if (wnd == NULL) { 277 ds_display_unlock(client->display); 278 return ENOENT; 279 } 280 281 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_unmaximize()"); 282 rc = ds_window_unmaximize(wnd); 283 ds_display_unlock(client->display); 284 return rc; 285 } 286 221 287 static errno_t disp_window_set_cursor(void *arg, sysarg_t wnd_id, 222 288 display_stock_cursor_t cursor) -
uspace/srv/hid/display/test/window.c
rfd05ea6 r35cffea 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 99 99 } 100 100 101 /** Test ds_window_get_pos(). */ 102 PCUT_TEST(get_pos) 103 { 104 ds_display_t *disp; 105 ds_client_t *client; 106 ds_seat_t *seat; 107 ds_window_t *wnd; 108 display_wnd_params_t params; 109 gfx_coord2_t pos; 110 errno_t rc; 111 112 rc = ds_display_create(NULL, df_none, &disp); 113 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 114 115 rc = ds_client_create(disp, NULL, NULL, &client); 116 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 117 118 rc = ds_seat_create(disp, &seat); 119 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 120 121 display_wnd_params_init(¶ms); 122 params.rect.p0.x = params.rect.p0.y = 0; 123 params.rect.p1.x = params.rect.p1.y = 10; 124 125 rc = ds_window_create(client, ¶ms, &wnd); 126 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 127 128 wnd->dpos.x = 100; 129 wnd->dpos.y = 100; 130 131 ds_window_get_pos(wnd, &pos); 132 133 PCUT_ASSERT_INT_EQUALS(100, pos.x); 134 PCUT_ASSERT_INT_EQUALS(100, pos.y); 135 136 ds_window_destroy(wnd); 137 ds_seat_destroy(seat); 138 ds_client_destroy(client); 139 ds_display_destroy(disp); 140 } 141 142 /** Test ds_window_get_max_rect(). */ 143 PCUT_TEST(get_max_rect) 144 { 145 ds_display_t *disp; 146 ds_client_t *client; 147 ds_seat_t *seat; 148 ds_window_t *wnd; 149 display_wnd_params_t params; 150 gfx_rect_t rect; 151 errno_t rc; 152 153 rc = ds_display_create(NULL, df_none, &disp); 154 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 155 156 rc = ds_client_create(disp, NULL, NULL, &client); 157 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 158 159 rc = ds_seat_create(disp, &seat); 160 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 161 162 display_wnd_params_init(¶ms); 163 params.rect.p0.x = params.rect.p0.y = 0; 164 params.rect.p1.x = params.rect.p1.y = 10; 165 166 rc = ds_window_create(client, ¶ms, &wnd); 167 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 168 169 wnd->dpos.x = 100; 170 wnd->dpos.y = 100; 171 172 ds_window_get_max_rect(wnd, &rect); 173 174 PCUT_ASSERT_INT_EQUALS(disp->rect.p0.x, rect.p0.x); 175 PCUT_ASSERT_INT_EQUALS(disp->rect.p0.y, rect.p0.y); 176 PCUT_ASSERT_INT_EQUALS(disp->rect.p1.x, rect.p1.x); 177 PCUT_ASSERT_INT_EQUALS(disp->rect.p1.y, rect.p1.y); 178 179 ds_window_destroy(wnd); 180 ds_seat_destroy(seat); 181 ds_client_destroy(client); 182 ds_display_destroy(disp); 183 } 184 185 /** Test ds_window_maximize(). */ 186 PCUT_TEST(window_maximize) 187 { 188 ds_display_t *disp; 189 ds_client_t *client; 190 ds_seat_t *seat; 191 ds_window_t *wnd; 192 display_wnd_params_t params; 193 errno_t rc; 194 195 rc = ds_display_create(NULL, df_none, &disp); 196 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 197 198 rc = ds_client_create(disp, NULL, NULL, &client); 199 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 200 201 rc = ds_seat_create(disp, &seat); 202 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 203 204 display_wnd_params_init(¶ms); 205 params.rect.p0.x = params.rect.p0.y = 0; 206 params.rect.p1.x = params.rect.p1.y = 10; 207 208 rc = ds_window_create(client, ¶ms, &wnd); 209 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 210 211 wnd->dpos.x = 100; 212 wnd->dpos.y = 100; 213 214 rc = ds_window_maximize(wnd); 215 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 216 217 PCUT_ASSERT_INT_EQUALS(wndf_maximized, wnd->flags & wndf_maximized); 218 219 ds_window_destroy(wnd); 220 ds_seat_destroy(seat); 221 ds_client_destroy(client); 222 ds_display_destroy(disp); 223 } 224 225 /** Test ds_window_unmaximize(). */ 226 PCUT_TEST(window_unmaximize) 227 { 228 ds_display_t *disp; 229 ds_client_t *client; 230 ds_seat_t *seat; 231 ds_window_t *wnd; 232 display_wnd_params_t params; 233 errno_t rc; 234 235 rc = ds_display_create(NULL, df_none, &disp); 236 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 237 238 rc = ds_client_create(disp, NULL, NULL, &client); 239 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 240 241 rc = ds_seat_create(disp, &seat); 242 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 243 244 display_wnd_params_init(¶ms); 245 params.rect.p0.x = params.rect.p0.y = 0; 246 params.rect.p1.x = params.rect.p1.y = 10; 247 248 rc = ds_window_create(client, ¶ms, &wnd); 249 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 250 251 wnd->dpos.x = 100; 252 wnd->dpos.y = 100; 253 254 rc = ds_window_maximize(wnd); 255 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 256 257 rc = ds_window_unmaximize(wnd); 258 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 259 260 PCUT_ASSERT_INT_EQUALS(0, wnd->flags & wndf_maximized); 261 262 ds_window_destroy(wnd); 263 ds_seat_destroy(seat); 264 ds_client_destroy(client); 265 ds_display_destroy(disp); 266 } 267 101 268 /** Test ds_window_get_ctx(). */ 102 269 PCUT_TEST(window_get_ctx) -
uspace/srv/hid/display/types/display/window.h
rfd05ea6 r35cffea 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 79 79 /** Minimum size */ 80 80 gfx_coord2_t min_size; 81 /** Normal rectangle (when not maximized or minimized) */ 82 gfx_rect_t normal_rect; 83 /** Normal display position (when not maximized or minimized) */ 84 gfx_coord2_t normal_dpos; 81 85 /** Window ID */ 82 86 ds_wnd_id_t id; -
uspace/srv/hid/display/window.c
rfd05ea6 r35cffea 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 580 580 * @param wnd Window 581 581 * @param event Position event 582 * 583 * @return EOK on success or an error code 582 584 */ 583 585 errno_t ds_window_post_pos_event(ds_window_t *wnd, pos_event_t *event) … … 597 599 inside = gfx_pix_inside_rect(&pos, &drect); 598 600 599 if (event->type == POS_PRESS && event->btn_num == 2 && inside) { 601 if (event->type == POS_PRESS && event->btn_num == 2 && inside && 602 (wnd->flags & wndf_maximized) == 0) { 600 603 ds_window_start_move(wnd, &pos); 601 604 return EOK; … … 637 640 * 638 641 * @param wnd Window 642 * @return EOK on success or an error code 639 643 */ 640 644 errno_t ds_window_post_focus_event(ds_window_t *wnd) … … 648 652 * 649 653 * @param wnd Window 654 * @return EOK on success or an error code 650 655 */ 651 656 errno_t ds_window_post_unfocus_event(ds_window_t *wnd) … … 691 696 { 692 697 *dpos = wnd->dpos; 698 } 699 700 /** Get maximized window rectangle. 701 * 702 * @param wnd Window 703 */ 704 void ds_window_get_max_rect(ds_window_t *wnd, gfx_rect_t *rect) 705 { 706 *rect = wnd->display->rect; 693 707 } 694 708 … … 716 730 * 717 731 * @param wnd Window 732 * @return EOK on success or an error code 718 733 */ 719 734 errno_t ds_window_resize(ds_window_t *wnd, gfx_coord2_t *offs, … … 770 785 } 771 786 787 /** Maximize window. 788 * 789 * @param wnd Window 790 * @return EOK on success or an error code 791 */ 792 errno_t ds_window_maximize(ds_window_t *wnd) 793 { 794 gfx_coord2_t old_dpos; 795 gfx_rect_t old_rect; 796 gfx_coord2_t offs; 797 gfx_rect_t max_rect; 798 gfx_rect_t nrect; 799 errno_t rc; 800 801 /* If already maximized, do nothing and return success. */ 802 if ((wnd->flags & wndf_maximized) != 0) 803 return EOK; 804 805 /* Remember the old window rectangle and display position */ 806 old_rect = wnd->rect; 807 old_dpos = wnd->dpos; 808 809 ds_window_get_max_rect(wnd, &max_rect); 810 811 /* Keep window contents on the same position on the screen */ 812 offs.x = max_rect.p0.x - wnd->dpos.x; 813 offs.y = max_rect.p0.y - wnd->dpos.y; 814 815 /* Maximized window's coordinates will start at 0,0 */ 816 gfx_rect_rtranslate(&max_rect.p0, &max_rect, &nrect); 817 818 rc = ds_window_resize(wnd, &offs, &nrect); 819 if (rc != EOK) 820 return rc; 821 822 /* Set window flags, remember normal rectangle */ 823 wnd->flags |= wndf_maximized; 824 wnd->normal_rect = old_rect; 825 wnd->normal_dpos = old_dpos; 826 827 return EOK; 828 } 829 830 /** Unmaximize window. 831 * 832 * @param wnd Window 833 * @return EOK on success or an error code 834 */ 835 errno_t ds_window_unmaximize(ds_window_t *wnd) 836 { 837 gfx_coord2_t offs; 838 errno_t rc; 839 840 /* If not maximized, do nothing and return success. */ 841 if ((wnd->flags & wndf_maximized) == 0) 842 return EOK; 843 844 /* Keep window contents on the same position on the screen */ 845 offs.x = wnd->normal_dpos.x - wnd->dpos.x; 846 offs.y = wnd->normal_dpos.y - wnd->dpos.y; 847 848 rc = ds_window_resize(wnd, &offs, &wnd->normal_rect); 849 if (rc != EOK) 850 return rc; 851 852 /* Set window flags, remember normal rectangle */ 853 wnd->flags &= ~wndf_maximized; 854 855 return EOK; 856 } 857 772 858 /** Compute new window rectangle after resize operation. 773 859 * -
uspace/srv/hid/display/window.h
rfd05ea6 r35cffea 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 64 64 extern void ds_window_move(ds_window_t *, gfx_coord2_t *); 65 65 extern void ds_window_get_pos(ds_window_t *, gfx_coord2_t *); 66 extern void ds_window_get_max_rect(ds_window_t *, gfx_rect_t *); 66 67 extern void ds_window_resize_req(ds_window_t *, display_wnd_rsztype_t, 67 68 gfx_coord2_t *); 68 69 extern errno_t ds_window_resize(ds_window_t *, gfx_coord2_t *, gfx_rect_t *); 70 extern errno_t ds_window_maximize(ds_window_t *); 71 extern errno_t ds_window_unmaximize(ds_window_t *); 69 72 extern void ds_window_calc_resize(ds_window_t *, gfx_coord2_t *, 70 73 gfx_rect_t *);
Note:
See TracChangeset
for help on using the changeset viewer.