Changes in uspace/srv/hid/display/seat.c [0d00e53:d7f82635] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/seat.c
r0d00e53 rd7f82635 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 #include <gfx/color.h> 39 39 #include <gfx/render.h> 40 #include <sif.h>41 #include <stdio.h>42 40 #include <stdlib.h> 43 #include <str.h>44 41 #include "client.h" 45 42 #include "cursor.h" 46 43 #include "display.h" 47 #include "idevcfg.h"48 44 #include "seat.h" 49 45 #include "window.h" … … 55 51 * 56 52 * @param display Parent display 57 * @param name Seat name58 53 * @param rseat Place to store pointer to new seat. 59 54 * @return EOK on success, ENOMEM if out of memory 60 55 */ 61 errno_t ds_seat_create(ds_display_t *display, const char *name, 62 ds_seat_t **rseat) 56 errno_t ds_seat_create(ds_display_t *display, ds_seat_t **rseat) 63 57 { 64 58 ds_seat_t *seat; 65 ds_seat_t *s0;66 67 s0 = ds_display_first_seat(display);68 while (s0 != NULL) {69 if (str_cmp(s0->name, name) == 0)70 return EEXIST;71 s0 = ds_display_next_seat(s0);72 }73 59 74 60 seat = calloc(1, sizeof(ds_seat_t)); … … 76 62 return ENOMEM; 77 63 78 seat->name = str_dup(name);79 if (seat->name == NULL) {80 free(seat);81 return ENOMEM;82 }83 84 list_initialize(&seat->idevcfgs);85 86 64 ds_display_add_seat(display, seat); 87 65 seat->pntpos.x = 0; … … 90 68 seat->client_cursor = display->cursor[dcurs_arrow]; 91 69 seat->wm_cursor = NULL; 92 seat->focus = ds_display_first_window(display);93 70 94 71 *rseat = seat; … … 102 79 void ds_seat_destroy(ds_seat_t *seat) 103 80 { 104 ds_idevcfg_t *idevcfg;105 106 /* Remove all input device configuration entries pointing to this seat */107 idevcfg = ds_seat_first_idevcfg(seat);108 while (idevcfg != NULL) {109 ds_idevcfg_destroy(idevcfg);110 idevcfg = ds_seat_first_idevcfg(seat);111 }112 113 /* Remove this seat's focus */114 if (seat->focus != NULL)115 ds_window_post_unfocus_event(seat->focus);116 117 81 ds_display_remove_seat(seat); 118 119 free(seat->name);120 82 free(seat); 121 83 } 122 84 123 /** Load seat from SIF node.124 *125 * @param display Display126 * @param snode Seat node from which to load the seat127 * @param rseat Place to store pointer to the newly loaded seat128 *129 * @return EOK on success or an error code130 */131 errno_t ds_seat_load(ds_display_t *display, sif_node_t *snode,132 ds_seat_t **rseat)133 {134 const char *sid;135 const char *name;136 char *endptr;137 unsigned long id;138 errno_t rc;139 140 sid = sif_node_get_attr(snode, "id");141 if (sid == NULL)142 return EIO;143 144 name = sif_node_get_attr(snode, "name");145 if (name == NULL)146 return EIO;147 148 id = strtoul(sid, &endptr, 10);149 if (*endptr != '\0')150 return EIO;151 152 rc = ds_seat_create(display, name, rseat);153 if (rc != EOK)154 return EIO;155 156 (*rseat)->id = id;157 return EOK;158 }159 160 /** Save seat to SIF node.161 *162 * @param seat Seat163 * @param snode Seat node into which the seat should be saved164 *165 * @return EOK on success or an error code166 */167 errno_t ds_seat_save(ds_seat_t *seat, sif_node_t *snode)168 {169 char *sid;170 errno_t rc;171 int rv;172 173 rv = asprintf(&sid, "%lu", (unsigned long)seat->id);174 if (rv < 0) {175 rc = ENOMEM;176 return rc;177 }178 179 rc = sif_node_set_attr(snode, "id", sid);180 if (rc != EOK) {181 free(sid);182 return rc;183 }184 185 free(sid);186 187 rc = sif_node_set_attr(snode, "name", seat->name);188 if (rc != EOK)189 return rc;190 191 return EOK;192 }193 194 85 /** Set seat focus to a window. 195 86 * … … 199 90 void ds_seat_set_focus(ds_seat_t *seat, ds_window_t *wnd) 200 91 { 201 errno_t rc;202 203 92 if (wnd == seat->focus) { 204 93 /* Focus is not changing */ 205 94 return; 206 }207 208 if (wnd != NULL) {209 rc = ds_window_unminimize(wnd);210 if (rc != EOK)211 return;212 95 } 213 96 … … 247 130 /** Evacuate seat references to window. 248 131 * 249 * If seat's focus is @a wnd, it will be set to NULL.132 * If seat's focus is @a wnd, it will be set to a different window. 250 133 * If seat's popup window is @a wnd, it will be set to NULL. 251 134 * 252 135 * @param seat Seat 253 * @param wnd Window to evacuate references from136 * @param wnd Window to evacuate focus from 254 137 */ 255 138 void ds_seat_evac_wnd_refs(ds_seat_t *seat, ds_window_t *wnd) 256 139 { 257 if (seat->focus == wnd) 258 ds_seat_set_focus(seat, NULL); 140 ds_window_t *nwnd; 141 142 if (seat->focus == wnd) { 143 nwnd = ds_display_prev_window(wnd); 144 if (nwnd == NULL) 145 nwnd = ds_display_last_window(wnd->display); 146 if (nwnd == wnd) 147 nwnd = NULL; 148 149 ds_seat_set_focus(seat, nwnd); 150 } 259 151 260 152 if (seat->popup == wnd) … … 262 154 } 263 155 264 /** Unfocus window. 265 * 266 * If seat's focus is @a wnd, it will be set to a different window 267 * that is not minimized, preferably not a system window. 268 * 269 * @param seat Seat 270 * @param wnd Window to remove focus from 271 */ 272 void ds_seat_unfocus_wnd(ds_seat_t *seat, ds_window_t *wnd) 156 /** Switch focus to another window. 157 * 158 * @param seat Seat 159 * @param wnd Window to evacuate focus from 160 */ 161 void ds_seat_switch_focus(ds_seat_t *seat) 273 162 { 274 163 ds_window_t *nwnd; 275 164 276 if (seat->focus != wnd) 277 return; 278 279 /* Find alternate window that is neither system nor minimized */ 280 nwnd = ds_window_find_prev(wnd, ~(wndf_minimized | wndf_system)); 281 282 if (nwnd == NULL) { 283 /* Find alternate window that is not minimized */ 284 nwnd = ds_window_find_prev(wnd, ~wndf_minimized); 285 } 286 287 ds_seat_set_focus(seat, nwnd); 288 } 289 290 /** Switch focus to another window. 291 * 292 * @param seat Seat 293 * @param wnd Window to evacuate focus from 294 */ 295 void ds_seat_switch_focus(ds_seat_t *seat) 296 { 297 ds_window_t *nwnd; 298 299 if (seat->focus != NULL) { 300 /* Find alternate window that is not a system window */ 301 nwnd = ds_window_find_next(seat->focus, ~wndf_system); 302 } else { 303 /* Currently no focus. Focus topmost window. */ 304 nwnd = ds_display_first_window(seat->display); 305 } 306 307 /* Only switch focus if there is another window */ 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 308 173 if (nwnd != NULL) 309 174 ds_seat_set_focus(seat, nwnd); … … 492 357 /* Focus window on button press */ 493 358 if (event->type == PTD_PRESS && event->btn_num == 1) { 494 if (wnd != NULL && (wnd->flags & wndf_popup) == 0 && 495 (wnd->flags & wndf_nofocus) == 0) { 359 if (wnd != NULL && (wnd->flags & wndf_popup) == 0) { 496 360 ds_seat_set_focus(seat, wnd); 497 361 } 498 362 } 499 363 500 if (event->type == PTD_PRESS || event->type == PTD_RELEASE || 501 event->type == PTD_DCLICK) { 502 pevent.pos_id = event->pos_id; 503 switch (event->type) { 504 case PTD_PRESS: 505 pevent.type = POS_PRESS; 506 break; 507 case PTD_RELEASE: 508 pevent.type = POS_RELEASE; 509 break; 510 case PTD_DCLICK: 511 pevent.type = POS_DCLICK; 512 break; 513 default: 514 assert(false); 515 } 516 364 if (event->type == PTD_PRESS || event->type == PTD_RELEASE) { 365 pevent.pos_id = 0; 366 pevent.type = (event->type == PTD_PRESS) ? 367 POS_PRESS : POS_RELEASE; 517 368 pevent.btn_num = event->btn_num; 518 369 pevent.hpos = seat->pntpos.x; … … 531 382 seat->pntpos = npos; 532 383 533 pevent.pos_id = event->pos_id;384 pevent.pos_id = 0; 534 385 pevent.type = POS_UPDATE; 535 386 pevent.btn_num = 0; … … 559 410 seat->pntpos = npos; 560 411 561 pevent.pos_id = event->pos_id;412 pevent.pos_id = 0; 562 413 pevent.type = POS_UPDATE; 563 414 pevent.btn_num = 0; … … 584 435 errno_t ds_seat_post_pos_event(ds_seat_t *seat, pos_event_t *event) 585 436 { 586 ds_window_t *pwindow; 587 ds_window_t *cwindow; 437 ds_window_t *wnd; 588 438 errno_t rc; 589 439 590 /* Window under pointer */ 591 pwindow = ds_display_window_by_pos(seat->display, &seat->pntpos); 592 593 /* Current window: popup or focused */ 594 cwindow = seat->popup; 595 if (cwindow == NULL) 596 cwindow = seat->focus; 597 598 /* 599 * Deliver move and release event to current window if different 600 * from pwindow 601 */ 602 if (event->type != POS_PRESS && cwindow != NULL && 603 cwindow != pwindow) { 604 rc = ds_window_post_pos_event(cwindow, event); 605 if (rc != EOK) 606 return rc; 607 } 608 609 if (pwindow != NULL) { 440 wnd = ds_display_window_by_pos(seat->display, &seat->pntpos); 441 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) { 456 rc = ds_window_post_pos_event(seat->focus, event); 457 if (rc != EOK) 458 return rc; 459 460 /* Only deliver release events to the focused window */ 461 if (event->type == POS_RELEASE) 462 return EOK; 463 } 464 465 if (wnd != NULL) { 610 466 /* Moving over a window */ 611 ds_seat_set_client_cursor(seat, pwindow->cursor); 612 613 rc = ds_window_post_pos_event(pwindow, event); 614 if (rc != EOK) 615 return rc; 467 ds_seat_set_client_cursor(seat, wnd->cursor); 468 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 } 616 478 } else { 617 479 /* Not over a window */ 618 ds_seat_set_client_cursor(seat, 619 seat->display->cursor[dcurs_arrow]); 620 } 621 622 /* Click outside popup window */ 623 if (event->type == POS_PRESS && pwindow != seat->popup) { 624 /* Close popup window */ 625 ds_seat_set_popup(seat, NULL); 480 ds_seat_set_client_cursor(seat, seat->display->cursor[dcurs_arrow]); 626 481 } 627 482 … … 642 497 } 643 498 644 /** Add input device configuration entry to seat.645 *646 * @param seat Seat647 * @param idevcfg Input device configuration648 */649 void ds_seat_add_idevcfg(ds_seat_t *seat, ds_idevcfg_t *idevcfg)650 {651 assert(idevcfg->seat == NULL);652 assert(!link_used(&idevcfg->lseatidcfgs));653 654 idevcfg->seat = seat;655 list_append(&idevcfg->lseatidcfgs, &seat->idevcfgs);656 }657 658 /** Remove input device configuration entry from seat.659 *660 * @param idevcfg Input device configuration entry661 */662 void ds_seat_remove_idevcfg(ds_idevcfg_t *idevcfg)663 {664 list_remove(&idevcfg->lseatidcfgs);665 idevcfg->seat = NULL;666 }667 668 /** Get first input device configuration entry in seat.669 *670 * @param disp Display671 * @return First input device configuration entry or @c NULL if there is none672 */673 ds_idevcfg_t *ds_seat_first_idevcfg(ds_seat_t *seat)674 {675 link_t *link = list_first(&seat->idevcfgs);676 677 if (link == NULL)678 return NULL;679 680 return list_get_instance(link, ds_idevcfg_t, lseatidcfgs);681 }682 683 /** Get next input device configuration entry in seat.684 *685 * @param idevcfg Current input device configuration entry686 * @return Next input device configuration entry or @c NULL if there is none687 */688 ds_idevcfg_t *ds_seat_next_idevcfg(ds_idevcfg_t *idevcfg)689 {690 link_t *link = list_next(&idevcfg->lseatidcfgs, &idevcfg->seat->idevcfgs);691 692 if (link == NULL)693 return NULL;694 695 return list_get_instance(link, ds_idevcfg_t, lseatidcfgs);696 }697 698 499 /** @} 699 500 */
Note:
See TracChangeset
for help on using the changeset viewer.