Changes in uspace/srv/hid/display/window.c [ededdc4:5877de74] in mainline
- File:
-
- 1 edited
-
uspace/srv/hid/display/window.c (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/window.c
rededdc4 r5877de74 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 44 44 #include <memgfx/memgc.h> 45 45 #include <stdlib.h> 46 #include <str.h>47 #include <wndmgt.h>48 46 #include "client.h" 49 47 #include "display.h" 50 48 #include "seat.h" 51 49 #include "window.h" 52 #include "wmclient.h"53 50 54 51 static void ds_window_invalidate_cb(void *, gfx_rect_t *); … … 67 64 * @param client Client owning the window 68 65 * @param params Window parameters 69 * @param r wnd Place to store pointer to new window.66 * @param rgc Place to store pointer to new GC. 70 67 * 71 68 * @return EOK on success or an error code 72 69 */ 73 70 errno_t ds_window_create(ds_client_t *client, display_wnd_params_t *params, 74 ds_window_t **r wnd)71 ds_window_t **rgc) 75 72 { 76 73 ds_window_t *wnd = NULL; … … 84 81 wnd = calloc(1, sizeof(ds_window_t)); 85 82 if (wnd == NULL) { 86 rc = ENOMEM;87 goto error;88 }89 90 wnd->caption = str_dup(params->caption);91 if (wnd->caption == NULL) {92 83 rc = ENOMEM; 93 84 goto error; … … 142 133 } 143 134 144 // TODO Multi-seat: which seat should own the new window?145 135 seat = ds_display_first_seat(client->display); 146 136 … … 150 140 ds_seat_set_focus(seat, wnd); 151 141 152 if ((params->flags & wndf_avoid) != 0)153 ds_display_update_max_rect(wnd->display);154 155 142 (void) ds_display_paint(wnd->display, NULL); 156 143 157 *r wnd= wnd;144 *rgc = wnd; 158 145 return EOK; 159 146 error: … … 165 152 if (wnd->bitmap != NULL) 166 153 gfx_bitmap_destroy(wnd->bitmap); 167 if (wnd->caption != NULL)168 free(wnd->caption);169 154 free(wnd); 170 155 } … … 182 167 183 168 disp = wnd->display; 184 185 ds_window_unfocus(wnd);186 169 187 170 ds_client_remove_window(wnd); 188 171 ds_display_remove_window(wnd); 189 172 190 if ((wnd->flags & wndf_avoid) != 0)191 ds_display_update_max_rect(disp);192 193 173 mem_gc_delete(wnd->mgc); 194 174 … … 196 176 gfx_bitmap_destroy(wnd->bitmap); 197 177 198 free(wnd->caption);199 178 free(wnd); 200 179 … … 208 187 void ds_window_bring_to_top(ds_window_t *wnd) 209 188 { 210 ds_display_window_to_top(wnd); 189 ds_display_t *disp = wnd->display; 190 191 ds_display_remove_window(wnd); 192 ds_display_add_window(disp, wnd); 211 193 (void) ds_display_paint(wnd->display, NULL); 212 194 } … … 220 202 { 221 203 return wnd->gc; 222 }223 224 /** Determine if window is visible.225 *226 * @param wnd Window227 * @return @c true iff window is visible228 */229 bool ds_window_is_visible(ds_window_t *wnd)230 {231 return (wnd->flags & wndf_minimized) == 0;232 204 } 233 205 … … 244 216 gfx_rect_t crect; 245 217 246 log_msg(LOG_DEFAULT, LVL_DEBUG2, "ds_window_paint"); 247 248 /* Skip painting the window if not visible */ 249 if (!ds_window_is_visible(wnd)) 250 return EOK; 218 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_paint"); 251 219 252 220 if (rect != NULL) { … … 393 361 bool newr; 394 362 395 log_msg(LOG_DEFAULT, LVL_DEBUG 2, "ds_window_repaint_preview");363 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_repaint_preview"); 396 364 397 365 /* … … 491 459 gfx_rect_t old_rect; 492 460 493 log_msg(LOG_DEFAULT, LVL_DEBUG 2, "ds_window_update_move (%d, %d)",461 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_move (%d, %d)", 494 462 (int) pos->x, (int) pos->y); 495 463 … … 528 496 wnd->preview_rect = wnd->rect; 529 497 530 // TODO Multi-seat: need client to tell us which seat started the resize!498 // XXX Need client to tell us which seat started the resize! 531 499 seat = ds_display_first_seat(wnd->display); 532 500 ctype = display_cursor_from_wrsz(rsztype); … … 559 527 ds_client_post_resize_event(wnd->client, wnd, &nrect); 560 528 561 // TODO Multi-seat:Need to know which seat started the resize!529 // XXX Need to know which seat started the resize! 562 530 seat = ds_display_first_seat(wnd->display); 563 531 ds_seat_set_wm_cursor(seat, NULL); … … 577 545 gfx_rect_t old_rect; 578 546 579 log_msg(LOG_DEFAULT, LVL_DEBUG 2, "ds_window_update_resize (%d, %d)",547 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_resize (%d, %d)", 580 548 (int) pos->x, (int) pos->y); 581 549 … … 626 594 bool inside; 627 595 628 log_msg(LOG_DEFAULT, LVL_DEBUG 2,596 log_msg(LOG_DEFAULT, LVL_DEBUG, 629 597 "ds_window_post_pos_event type=%d pos=%d,%d", event->type, 630 598 (int) event->hpos, (int) event->vpos); … … 680 648 errno_t ds_window_post_focus_event(ds_window_t *wnd) 681 649 { 682 errno_t rc;683 ds_wmclient_t *wmclient;684 685 650 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_post_focus_event"); 686 651 687 rc = ds_client_post_focus_event(wnd->client, wnd); 688 if (rc != EOK) 689 return rc; 690 691 /* Increase focus counter */ 692 ++wnd->nfocus; 693 694 /* Notify window managers about window information change */ 695 wmclient = ds_display_first_wmclient(wnd->display); 696 while (wmclient != NULL) { 697 ds_wmclient_post_wnd_changed_event(wmclient, wnd->id); 698 wmclient = ds_display_next_wmclient(wmclient); 699 } 700 701 return EOK; 652 return ds_client_post_focus_event(wnd->client, wnd); 702 653 } 703 654 … … 709 660 errno_t ds_window_post_unfocus_event(ds_window_t *wnd) 710 661 { 711 errno_t rc;712 ds_wmclient_t *wmclient;713 714 662 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_post_unfocus_event"); 715 663 716 rc = ds_client_post_unfocus_event(wnd->client, wnd); 717 if (rc != EOK) 718 return rc; 719 720 /* Decrease focus counter */ 721 --wnd->nfocus; 722 723 /* Notify window managers about window information change */ 724 wmclient = ds_display_first_wmclient(wnd->display); 725 while (wmclient != NULL) { 726 ds_wmclient_post_wnd_changed_event(wmclient, wnd->id); 727 wmclient = ds_display_next_wmclient(wmclient); 728 } 729 730 return EOK; 664 return ds_client_post_unfocus_event(wnd->client, wnd); 731 665 } 732 666 … … 774 708 void ds_window_get_max_rect(ds_window_t *wnd, gfx_rect_t *rect) 775 709 { 776 *rect = wnd->display-> max_rect;710 *rect = wnd->display->rect; 777 711 } 778 712 … … 851 785 wnd->rect = *nrect; 852 786 853 if ((wnd->flags & wndf_avoid) != 0)854 ds_display_update_max_rect(wnd->display);855 856 (void) ds_display_paint(wnd->display, NULL);857 return EOK;858 }859 860 /** Minimize window.861 *862 * @param wnd Window863 * @return EOK on success or an error code864 */865 errno_t ds_window_minimize(ds_window_t *wnd)866 {867 /* If already minimized, do nothing and return success. */868 if ((wnd->flags & wndf_minimized) != 0)869 return EOK;870 871 ds_window_unfocus(wnd);872 873 wnd->flags |= wndf_minimized;874 (void) ds_display_paint(wnd->display, NULL);875 return EOK;876 }877 878 /** Unminimize window.879 *880 * @param wnd Window881 * @return EOK on success or an error code882 */883 errno_t ds_window_unminimize(ds_window_t *wnd)884 {885 /* If not minimized, do nothing and return success. */886 if ((wnd->flags & wndf_minimized) == 0)887 return EOK;888 889 wnd->flags &= ~wndf_minimized;890 787 (void) ds_display_paint(wnd->display, NULL); 891 788 return EOK; … … 1005 902 * 1006 903 * @param wnd Window 1007 * @param cursor New cursor1008 904 * @return EOK on success, EINVAL if @a cursor is invalid 1009 905 */ … … 1019 915 } 1020 916 1021 /** Set window caption.1022 *1023 * @param wnd Window1024 * @param caption New caption1025 *1026 * @return EOK on success, EINVAL if @a cursor is invalid1027 */1028 errno_t ds_window_set_caption(ds_window_t *wnd, const char *caption)1029 {1030 char *dcaption;1031 ds_wmclient_t *wmclient;1032 1033 dcaption = str_dup(caption);1034 if (dcaption == NULL)1035 return ENOMEM;1036 1037 free(wnd->caption);1038 wnd->caption = dcaption;1039 1040 /* Notify window managers about window information change */1041 wmclient = ds_display_first_wmclient(wnd->display);1042 while (wmclient != NULL) {1043 ds_wmclient_post_wnd_changed_event(wmclient, wnd->id);1044 wmclient = ds_display_next_wmclient(wmclient);1045 }1046 1047 return EOK;1048 }1049 1050 /** Find alternate window with the allowed flags.1051 *1052 * An alternate window is a *different* window that is preferably previous1053 * in the display order and only has the @a allowed flags.1054 *1055 * @param wnd Window1056 * @param allowed_flags Bitmask of flags that the window is allowed to have1057 *1058 * @return Alternate window matching the criteria or @c NULL if there is none1059 */1060 ds_window_t *ds_window_find_alt(ds_window_t *wnd,1061 display_wnd_flags_t allowed_flags)1062 {1063 ds_window_t *nwnd;1064 1065 /* Try preceding windows in display order */1066 nwnd = ds_display_prev_window(wnd);1067 while (nwnd != NULL && (nwnd->flags & ~allowed_flags) != 0) {1068 nwnd = ds_display_prev_window(nwnd);1069 }1070 1071 /* Do we already have a matching window? */1072 if (nwnd != NULL && (nwnd->flags & ~allowed_flags) == 0) {1073 return nwnd;1074 }1075 1076 /* Try succeeding windows in display order */1077 nwnd = ds_display_last_window(wnd->display);1078 while (nwnd != NULL && nwnd != wnd &&1079 (nwnd->flags & ~allowed_flags) != 0) {1080 nwnd = ds_display_prev_window(nwnd);1081 }1082 1083 if (nwnd == wnd)1084 return NULL;1085 1086 return nwnd;1087 }1088 1089 /** Remove focus from window.1090 *1091 * Used to switch focus to another window when closing or minimizing window.1092 *1093 * @param wnd Window1094 */1095 void ds_window_unfocus(ds_window_t *wnd)1096 {1097 ds_seat_t *seat;1098 1099 /* Make sure window is no longer focused in any seat */1100 seat = ds_display_first_seat(wnd->display);1101 while (seat != NULL) {1102 ds_seat_unfocus_wnd(seat, wnd);1103 seat = ds_display_next_seat(seat);1104 }1105 }1106 1107 917 /** Window memory GC invalidate callback. 1108 918 *
Note:
See TracChangeset
for help on using the changeset viewer.
