Changeset dc5c303 in mainline for uspace/lib/ui/src/wdecor.c
- Timestamp:
- 2023-12-28T13:59:23Z (14 months ago)
- Children:
- 6b66de6b
- Parents:
- 42c2e65 (diff), f87ff8e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- boba-buba <120932204+boba-buba@…> (2023-12-28 13:59:23)
- git-committer:
- GitHub <noreply@…> (2023-12-28 13:59:23)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/wdecor.c
r42c2e65 rdc5c303 104 104 /** Window caption horizontal margin in text mode */ 105 105 wdecor_cap_hmargin_text = 1, 106 /** System menu handle width */ 107 wdecor_sysmenu_hdl_w = 20, 108 /** System menu handle height */ 109 wdecor_sysmenu_hdl_h = 20, 110 /** System menu handle width in text mode */ 111 wdecor_sysmenu_hdl_w_text = 3, 112 /** System menu handle height in text mode */ 113 wdecor_sysmenu_hdl_h_text = 1, 106 114 /** Close button cross leg length */ 107 115 wdecor_close_cross_n = 5, … … 296 304 } 297 305 306 /** Paint system menu handle in graphics mode. 307 * 308 * @param wdecor Window decoration 309 * @param rect System menu handle rectangle 310 * @return EOK on success or an error code 311 */ 312 errno_t ui_wdecor_sysmenu_hdl_paint_gfx(ui_wdecor_t *wdecor, gfx_rect_t *rect) 313 { 314 errno_t rc; 315 gfx_rect_t mrect; 316 gfx_rect_t inside; 317 gfx_coord2_t center; 318 319 rc = gfx_set_color(wdecor->res->gc, wdecor->sysmenu_hdl_active ? 320 wdecor->res->btn_shadow_color : wdecor->res->btn_face_color); 321 if (rc != EOK) 322 return rc; 323 324 rc = gfx_fill_rect(wdecor->res->gc, rect); 325 if (rc != EOK) 326 return rc; 327 328 center.x = (rect->p0.x + rect->p1.x) / 2; 329 center.y = (rect->p0.y + rect->p1.y) / 2; 330 mrect.p0.x = center.x - 7; 331 mrect.p0.y = center.y - 1; 332 mrect.p1.x = center.x + 7; 333 mrect.p1.y = center.y + 1 + 1; 334 335 /* XXX Not really a bevel, just a frame */ 336 rc = ui_paint_bevel(wdecor->res->gc, &mrect, 337 wdecor->res->btn_text_color, wdecor->res->btn_text_color, 1, 338 &inside); 339 if (rc != EOK) 340 return rc; 341 342 rc = gfx_set_color(wdecor->res->gc, wdecor->res->btn_highlight_color); 343 if (rc != EOK) 344 return rc; 345 346 rc = gfx_fill_rect(wdecor->res->gc, &inside); 347 if (rc != EOK) 348 return rc; 349 350 return EOK; 351 } 352 353 /** Paint system menu handle in text mode. 354 * 355 * @param wdecor Window decoration 356 * @param rect System menu handle rectangle 357 * @return EOK on success or an error code 358 */ 359 errno_t ui_wdecor_sysmenu_hdl_paint_text(ui_wdecor_t *wdecor, gfx_rect_t *rect) 360 { 361 errno_t rc; 362 gfx_text_fmt_t fmt; 363 364 rc = gfx_set_color(wdecor->res->gc, wdecor->sysmenu_hdl_active ? 365 wdecor->res->btn_shadow_color : wdecor->res->btn_face_color); 366 367 gfx_text_fmt_init(&fmt); 368 fmt.font = wdecor->res->font; 369 fmt.color = wdecor->sysmenu_hdl_active ? 370 wdecor->res->wnd_sel_text_color : 371 wdecor->res->tbar_act_text_color; 372 fmt.halign = gfx_halign_left; 373 fmt.valign = gfx_valign_top; 374 375 rc = gfx_puttext(&rect->p0, &fmt, "[\u2261]"); 376 if (rc != EOK) 377 return rc; 378 379 return EOK; 380 } 381 382 /** Paint system menu handle. 383 * 384 * @param wdecor Window decoration 385 * @param rect System menu handle rectangle 386 * @return EOK on success or an error code 387 */ 388 errno_t ui_wdecor_sysmenu_hdl_paint(ui_wdecor_t *wdecor, gfx_rect_t *rect) 389 { 390 errno_t rc; 391 392 if (wdecor->res->textmode) 393 rc = ui_wdecor_sysmenu_hdl_paint_text(wdecor, rect); 394 else 395 rc = ui_wdecor_sysmenu_hdl_paint_gfx(wdecor, rect); 396 397 return rc; 398 } 399 400 /** Set system menu handle active flag. 401 * 402 * @param wdecor Window decoration 403 * @param active @c true iff handle should be active 404 */ 405 void ui_wdecor_sysmenu_hdl_set_active(ui_wdecor_t *wdecor, bool active) 406 { 407 ui_wdecor_geom_t geom; 408 409 wdecor->sysmenu_hdl_active = active; 410 411 ui_wdecor_get_geom(wdecor, &geom); 412 (void) ui_wdecor_sysmenu_hdl_paint(wdecor, &geom.sysmenu_hdl_rect); 413 (void) gfx_update(wdecor->res->gc); 414 } 415 298 416 /** Paint window decoration. 299 417 * … … 395 513 return rc; 396 514 515 if ((wdecor->style & ui_wds_sysmenu_hdl) != 0) { 516 rc = ui_wdecor_sysmenu_hdl_paint(wdecor, 517 &geom.sysmenu_hdl_rect); 518 if (rc != EOK) 519 return rc; 520 } 521 397 522 if (wdecor->btn_min != NULL) { 398 523 rc = ui_pbutton_paint(wdecor->btn_min); … … 421 546 } 422 547 548 /** Send decoration sysmenu open event. 549 * 550 * @param wdecor Window decoration 551 * @param idev_id Input device ID 552 */ 553 void ui_wdecor_sysmenu_open(ui_wdecor_t *wdecor, sysarg_t idev_id) 554 { 555 if (wdecor->cb != NULL && wdecor->cb->sysmenu_open != NULL) 556 wdecor->cb->sysmenu_open(wdecor, wdecor->arg, idev_id); 557 } 558 559 /** Send decoration sysmenu left event. 560 * 561 * @param wdecor Window decoration 562 * @param idev_id Input device ID 563 */ 564 void ui_wdecor_sysmenu_left(ui_wdecor_t *wdecor, sysarg_t idev_id) 565 { 566 if (wdecor->cb != NULL && wdecor->cb->sysmenu_left != NULL) 567 wdecor->cb->sysmenu_left(wdecor, wdecor->arg, idev_id); 568 } 569 570 /** Send decoration sysmenu right event. 571 * 572 * @param wdecor Window decoration 573 * @param idev_id Input device ID 574 */ 575 void ui_wdecor_sysmenu_right(ui_wdecor_t *wdecor, sysarg_t idev_id) 576 { 577 if (wdecor->cb != NULL && wdecor->cb->sysmenu_right != NULL) 578 wdecor->cb->sysmenu_right(wdecor, wdecor->arg, idev_id); 579 } 580 581 /** Send decoration sysmenu accelerator event. 582 * 583 * @param wdecor Window decoration 584 * @param c Accelerator character 585 * @param idev_id Input device ID 586 */ 587 void ui_wdecor_sysmenu_accel(ui_wdecor_t *wdecor, char32_t c, sysarg_t idev_id) 588 { 589 if (wdecor->cb != NULL && wdecor->cb->sysmenu_right != NULL) 590 wdecor->cb->sysmenu_accel(wdecor, wdecor->arg, c, idev_id); 591 } 592 423 593 /** Send decoration minimize event. 424 594 * … … 509 679 gfx_coord_t btn_y; 510 680 gfx_coord_t cap_hmargin; 681 gfx_coord_t cap_x; 682 gfx_coord_t hdl_x_off; 683 gfx_coord_t hdl_y_off; 684 gfx_coord_t hdl_w; 685 gfx_coord_t hdl_h; 511 686 512 687 /* Does window have a frame? */ … … 557 732 } 558 733 734 /* Does window have a sysmenu handle? */ 735 if ((wdecor->style & ui_wds_sysmenu_hdl) != 0) { 736 if (wdecor->res->textmode) { 737 hdl_x_off = 2; 738 hdl_y_off = 0; 739 hdl_w = wdecor_sysmenu_hdl_w_text; 740 hdl_h = wdecor_sysmenu_hdl_h_text; 741 } else { 742 hdl_x_off = 1; 743 hdl_y_off = 1; 744 hdl_w = wdecor_sysmenu_hdl_w; 745 hdl_h = wdecor_sysmenu_hdl_h; 746 } 747 748 geom->sysmenu_hdl_rect.p0.x = geom->title_bar_rect.p0.x + 749 hdl_x_off; 750 geom->sysmenu_hdl_rect.p0.y = geom->title_bar_rect.p0.y + 751 hdl_y_off; 752 geom->sysmenu_hdl_rect.p1.x = geom->sysmenu_hdl_rect.p0.x + 753 hdl_w; 754 geom->sysmenu_hdl_rect.p1.y = geom->sysmenu_hdl_rect.p0.y + 755 hdl_h; 756 cap_x = hdl_w; 757 } else { 758 geom->sysmenu_hdl_rect.p0.x = 0; 759 geom->sysmenu_hdl_rect.p0.y = 0; 760 geom->sysmenu_hdl_rect.p1.x = 0; 761 geom->sysmenu_hdl_rect.p1.y = 0; 762 cap_x = 0; 763 } 764 559 765 /* Does window have a close button? */ 560 766 if ((wdecor->style & ui_wds_close_btn) != 0) { … … 629 835 } 630 836 631 if (wdecor->res->textmode == false) 632 cap_hmargin = wdecor_cap_hmargin; 633 else 634 cap_hmargin = wdecor_cap_hmargin_text; 635 636 geom->caption_rect.p0.x = geom->title_bar_rect.p0.x + 637 cap_hmargin; 638 geom->caption_rect.p0.y = geom->title_bar_rect.p0.y; 639 geom->caption_rect.p1.x = btn_x - cap_hmargin; 640 geom->caption_rect.p1.y = geom->title_bar_rect.p1.y; 837 if ((wdecor->style & ui_wds_titlebar) != 0) { 838 if (wdecor->res->textmode == false) 839 cap_hmargin = wdecor_cap_hmargin; 840 else 841 cap_hmargin = wdecor_cap_hmargin_text; 842 843 geom->caption_rect.p0.x = geom->title_bar_rect.p0.x + 844 cap_hmargin + cap_x; 845 geom->caption_rect.p0.y = geom->title_bar_rect.p0.y; 846 geom->caption_rect.p1.x = btn_x - cap_hmargin; 847 geom->caption_rect.p1.y = geom->title_bar_rect.p1.y; 848 } else { 849 geom->caption_rect.p0.x = 0; 850 geom->caption_rect.p0.y = 0; 851 geom->caption_rect.p1.x = 0; 852 geom->caption_rect.p1.y = 0; 853 } 641 854 } 642 855 … … 805 1018 } 806 1019 1020 /** Handle window decoration keyboard event. 1021 * 1022 * @param wdecor Window decoration 1023 * @param kbd_event Keyboard event 1024 * @return @c ui_claimed iff event was claimed 1025 */ 1026 ui_evclaim_t ui_wdecor_kbd_event(ui_wdecor_t *wdecor, kbd_event_t *event) 1027 { 1028 if (event->type == KEY_PRESS && (event->mods & (KM_CTRL | KM_ALT | 1029 KM_SHIFT)) == 0) { 1030 if (event->key == KC_F10) { 1031 ui_wdecor_sysmenu_hdl_set_active(wdecor, true); 1032 ui_wdecor_sysmenu_open(wdecor, event->kbd_id); 1033 return ui_claimed; 1034 } 1035 } 1036 1037 /* System menu handle events (if active) */ 1038 if (event->type == KEY_PRESS && (event->mods & (KM_CTRL | KM_ALT | 1039 KM_SHIFT)) == 0 && wdecor->sysmenu_hdl_active) { 1040 switch (event->key) { 1041 case KC_ESCAPE: 1042 ui_wdecor_sysmenu_hdl_set_active(wdecor, false); 1043 return ui_claimed; 1044 case KC_LEFT: 1045 ui_wdecor_sysmenu_left(wdecor, event->kbd_id); 1046 return ui_claimed; 1047 case KC_RIGHT: 1048 ui_wdecor_sysmenu_right(wdecor, event->kbd_id); 1049 return ui_claimed; 1050 case KC_DOWN: 1051 ui_wdecor_sysmenu_open(wdecor, event->kbd_id); 1052 return ui_claimed; 1053 default: 1054 break; 1055 } 1056 1057 if (event->c != '\0') { 1058 /* Could be an accelerator key */ 1059 ui_wdecor_sysmenu_accel(wdecor, event->c, 1060 event->kbd_id); 1061 } 1062 } 1063 1064 return ui_unclaimed; 1065 } 1066 807 1067 /** Handle window frame position event. 808 1068 * … … 851 1111 852 1112 ui_wdecor_get_geom(wdecor, &geom); 1113 1114 if ((wdecor->style & ui_wds_titlebar) != 0 && 1115 (wdecor->style & ui_wds_sysmenu_hdl) != 0) { 1116 if (event->type == POS_PRESS && 1117 gfx_pix_inside_rect(&pos, &geom.sysmenu_hdl_rect)) { 1118 ui_wdecor_sysmenu_hdl_set_active(wdecor, true); 1119 ui_wdecor_sysmenu_open(wdecor, event->pos_id); 1120 return ui_claimed; 1121 } 1122 } 853 1123 854 1124 if (wdecor->btn_min != NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.