Changes in uspace/lib/gui/window.c [61b5b73d:21eeb653] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gui/window.c
r61b5b73d r21eeb653 56 56 #include <surface.h> 57 57 58 #include "common.h"59 58 #include "connection.h" 60 59 #include "widget.h" 61 60 #include "window.h" 62 61 63 static sysarg_t border_thickness = 4; 64 static sysarg_t bevel_thickness = 1; 62 static sysarg_t border_thickness = 5; 65 63 static sysarg_t header_height = 20; 66 64 static sysarg_t header_min_width = 40; 67 static sysarg_t close_thickness = 20; 68 69 static pixel_t color_highlight = PIXEL(255, 255, 255, 255); 70 static pixel_t color_shadow = PIXEL(255, 85, 85, 85); 71 static pixel_t color_surface = PIXEL(255, 186, 186, 186); 72 73 static pixel_t color_header_focus_highlight = PIXEL(255, 120, 145, 255); 74 static pixel_t color_header_focus_shadow = PIXEL(255, 40, 48, 89); 75 static pixel_t color_header_focus_surface = PIXEL(255, 88, 106, 196); 76 77 static pixel_t color_header_unfocus_highlight = PIXEL(255, 16, 78, 126); 78 static pixel_t color_header_unfocus_shadow = PIXEL(255, 5, 26, 42); 79 static pixel_t color_header_unfocus_surface = PIXEL(255, 12, 57, 92); 80 81 static pixel_t color_caption_focus = PIXEL(255, 255, 255, 255); 82 static pixel_t color_caption_unfocus = PIXEL(255, 207, 207, 207); 83 84 static void paint_internal(widget_t *widget) 85 { 86 surface_t *surface = window_claim(widget->window); 87 if (!surface) 88 window_yield(widget->window); 89 65 static sysarg_t close_width = 20; 66 67 static pixel_t border_color = PIXEL(255, 0, 0, 0); 68 static pixel_t header_bg_focus_color = PIXEL(255, 25, 25, 112); 69 static pixel_t header_fg_focus_color = PIXEL(255, 255, 255, 255); 70 static pixel_t header_bg_unfocus_color = PIXEL(255, 70, 130, 180); 71 static pixel_t header_fg_unfocus_color = PIXEL(255, 255, 255, 255); 72 73 static void paint_internal(widget_t *w) 74 { 75 surface_t *surface = window_claim(w->window); 76 if (!surface) { 77 window_yield(w->window); 78 } 79 90 80 source_t source; 81 font_t font; 82 drawctx_t drawctx; 83 91 84 source_init(&source); 92 93 drawctx_t drawctx; 85 font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16); 94 86 drawctx_init(&drawctx, surface); 95 87 drawctx_set_source(&drawctx, &source); 96 97 /* Window border outer bevel */98 99 draw_bevel(&drawctx, &source, widget->vpos, widget->hpos,100 widget->width, widget->height, color_highlight, color_shadow);101 102 /* Window border surface */103 104 source_set_color(&source, color_surface);105 drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,106 widget->width - 2, 2);107 drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,108 2, widget->height - 2);109 drawctx_transfer(&drawctx, widget->hpos + 1,110 widget->vpos + widget->height - 3, widget->width - 2, 2);111 drawctx_transfer(&drawctx, widget->hpos + widget->width - 3,112 widget->vpos + 1, 2, widget->height - 4);113 114 /* Window border inner bevel */115 116 draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3,117 widget->width - 6, widget->height - 6, color_shadow,118 color_highlight);119 120 /* Header bevel */121 122 sysarg_t header_hpos = widget->hpos + border_thickness;123 sysarg_t header_vpos = widget->vpos + border_thickness;124 sysarg_t header_width = widget->width - 2 * border_thickness -125 close_thickness;126 127 draw_bevel(&drawctx, &source, header_hpos, header_vpos,128 header_width, header_height, widget->window->is_focused ?129 color_header_focus_highlight : color_header_unfocus_highlight,130 widget->window->is_focused ?131 color_header_focus_shadow : color_header_unfocus_shadow);132 133 /* Header surface */134 135 source_set_color(&source, widget->window->is_focused ?136 color_header_focus_surface : color_header_unfocus_surface);137 drawctx_transfer(&drawctx, header_hpos + 1, header_vpos + 1,138 header_width - 2, header_height - 2);139 140 /* Close button bevel */141 142 sysarg_t close_hpos = widget->hpos + widget->width -143 border_thickness - close_thickness;144 sysarg_t close_vpos = widget->vpos + border_thickness;145 146 draw_bevel(&drawctx, &source, close_hpos, close_vpos,147 close_thickness, close_thickness, color_highlight, color_shadow);148 149 /* Close button surface */150 151 source_set_color(&source, color_surface);152 drawctx_transfer(&drawctx, close_hpos + 1, close_vpos + 1,153 close_thickness - 2, close_thickness - 2);154 155 /* Close button icon */156 157 draw_icon_cross(surface, close_hpos + 3, close_vpos + 3,158 color_highlight, color_shadow);159 160 /* Window caption */161 162 font_t font;163 font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);164 165 88 drawctx_set_font(&drawctx, &font); 166 source_set_color(&source, widget->window->is_focused ? 167 color_caption_focus : color_caption_unfocus); 168 89 90 source_set_color(&source, border_color); 91 drawctx_transfer(&drawctx, w->hpos, w->vpos, border_thickness, w->height); 92 drawctx_transfer(&drawctx, w->hpos + w->width - border_thickness, 93 w->vpos, border_thickness, w->height); 94 drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, border_thickness); 95 drawctx_transfer(&drawctx, w->hpos, 96 w->vpos + w->height - border_thickness, w->width, border_thickness); 97 98 source_set_color(&source, 99 w->window->is_focused ? header_bg_focus_color : header_bg_unfocus_color); 100 drawctx_transfer(&drawctx, 101 w->hpos + border_thickness, w->vpos + border_thickness, 102 w->width - 2 * border_thickness, header_height); 103 169 104 sysarg_t cpt_width; 170 105 sysarg_t cpt_height; 171 font_get_box(&font, widget->window->caption, &cpt_width, &cpt_height); 172 173 bool draw_title = 174 (widget->width >= 2 * border_thickness + 2 * bevel_thickness + 175 close_thickness + cpt_width); 106 font_get_box(&font, w->window->caption, &cpt_width, &cpt_height); 107 sysarg_t cls_width; 108 sysarg_t cls_height; 109 char cls_pict[] = "x"; 110 font_get_box(&font, cls_pict, &cls_width, &cls_height); 111 source_set_color(&source, 112 w->window->is_focused ? header_fg_focus_color : header_fg_unfocus_color); 113 sysarg_t cls_x = ((close_width - cls_width) / 2) + w->hpos + w->width - 114 border_thickness - close_width; 115 sysarg_t cls_y = ((header_height - cls_height) / 2) + w->vpos + border_thickness; 116 drawctx_print(&drawctx, cls_pict, cls_x, cls_y); 117 118 bool draw_title = (w->width >= 2 * border_thickness + close_width + cpt_width); 176 119 if (draw_title) { 177 sysarg_t cpt_x = ((widget->width - cpt_width) / 2) + widget->hpos; 178 sysarg_t cpt_y = ((header_height - cpt_height) / 2) + 179 widget->vpos + border_thickness; 180 181 if (widget->window->caption) 182 drawctx_print(&drawctx, widget->window->caption, cpt_x, cpt_y); 183 } 184 120 sysarg_t cpt_x = ((w->width - cpt_width) / 2) + w->hpos; 121 sysarg_t cpt_y = ((header_height - cpt_height) / 2) + w->vpos + border_thickness; 122 if (w->window->caption) { 123 drawctx_print(&drawctx, w->window->caption, cpt_x, cpt_y); 124 } 125 } 126 185 127 font_release(&font); 186 window_yield(w idget->window);128 window_yield(w->window); 187 129 } 188 130 … … 195 137 { 196 138 if (widget->window->is_decorated) { 197 list_foreach(widget->children, link, widget_t, child) { 198 child->rearrange(child, 139 list_foreach(widget->children, link) { 140 widget_t *child = list_get_instance(link, widget_t, link); 141 child->rearrange(child, 199 142 widget->hpos + border_thickness, 200 143 widget->vpos + border_thickness + header_height, … … 203 146 } 204 147 } else { 205 list_foreach(widget->children, link, widget_t, child) { 148 list_foreach(widget->children, link) { 149 widget_t *child = list_get_instance(link, widget_t, link); 206 150 child->rearrange(child, widget->hpos, widget->vpos, 207 151 widget->width, widget->height); … … 216 160 if (widget->window->is_decorated) { 217 161 paint_internal(widget); 218 list_foreach(widget->children, link, widget_t, child) { 162 list_foreach(widget->children, link) { 163 widget_t *child = list_get_instance(link, widget_t, link); 219 164 child->rearrange(child, 220 165 hpos + border_thickness, … … 224 169 } 225 170 } else { 226 list_foreach(widget->children, link, widget_t, child) { 171 list_foreach(widget->children, link) { 172 widget_t *child = list_get_instance(link, widget_t, link); 227 173 child->rearrange(child, hpos, vpos, width, height); 228 174 } … … 235 181 paint_internal(widget); 236 182 } 237 list_foreach(widget->children, link, widget_t, child) { 183 list_foreach(widget->children, link) { 184 widget_t *child = list_get_instance(link, widget_t, link); 238 185 child->repaint(child); 239 186 } … … 269 216 (event.vpos >= border_thickness) && 270 217 (event.vpos < border_thickness + header_height); 271 bool close = (header) && 272 (event.hpos >= width - border_thickness - close_thickness); 218 bool close = header && (event.hpos >= width - border_thickness - close_width); 273 219 274 220 if (top && left && allowed_button) { … … 322 268 win_grab(widget->window->osess, event.pos_id, flags); 323 269 } else { 324 list_foreach(widget->children, link, widget_t, child) { 270 list_foreach(widget->children, link) { 271 widget_t *child = list_get_instance(link, widget_t, link); 325 272 child->handle_position_event(child, event); 326 273 } 327 274 } 328 275 } else { 329 list_foreach(widget->children, link, widget_t, child) { 276 list_foreach(widget->children, link) { 277 widget_t *child = list_get_instance(link, widget_t, link); 330 278 child->handle_position_event(child, event); 331 279 } … … 351 299 } 352 300 353 static void handle_signal_event(window_t *win, sig nal_event_t event)301 static void handle_signal_event(window_t *win, sig_event_t event) 354 302 { 355 303 widget_t *widget = (widget_t *) event.object; … … 362 310 } 363 311 364 static void handle_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y, 365 sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags) 366 { 312 static void handle_resize(window_t *win, sysarg_t width, sysarg_t height) 313 { 314 int rc; 315 surface_t *old_surface; 316 surface_t *new_surface; 317 367 318 if (width < 2 * border_thickness + header_min_width) { 368 319 win_damage(win->osess, 0, 0, 0, 0); 369 320 return; 370 321 } 371 322 372 323 if (height < 2 * border_thickness + header_height) { 373 324 win_damage(win->osess, 0, 0, 0, 0); 374 325 return; 375 326 } 376 327 377 328 /* Allocate resources for new surface. */ 378 surface_t *new_surface = surface_create(width, height, NULL, 379 SURFACE_FLAG_SHARED); 380 if (!new_surface) 329 new_surface = surface_create(width, height, NULL, SURFACE_FLAG_SHARED); 330 if (!new_surface) { 381 331 return; 382 332 } 333 383 334 /* Switch new and old surface. */ 384 335 fibril_mutex_lock(&win->guard); 385 surface_t *old_surface = win->surface;336 old_surface = win->surface; 386 337 win->surface = new_surface; 387 338 fibril_mutex_unlock(&win->guard); 388 389 /* 390 * Let all widgets in the tree alter their position and size. 391 * Widgets might also paint themselves onto the new surface. 392 */ 339 340 /* Let all widgets in the tree alter their position and size. Widgets might 341 * also paint themselves onto the new surface. */ 393 342 win->root.rearrange(&win->root, 0, 0, width, height); 394 343 395 344 fibril_mutex_lock(&win->guard); 396 345 surface_reset_damaged_region(win->surface); 397 346 fibril_mutex_unlock(&win->guard); 398 347 399 348 /* Inform compositor about new surface. */ 400 int rc = win_resize(win->osess, offset_x, offset_y, width, height,401 placement_flags, surface_direct_access(new_surface));402 349 rc = win_resize(win->osess, 350 width, height, surface_direct_access(new_surface)); 351 403 352 if (rc != EOK) { 404 353 /* Rollback to old surface. Reverse all changes. */ 405 354 406 355 sysarg_t old_width = 0; 407 356 sysarg_t old_height = 0; 408 if (old_surface) 357 if (old_surface) { 409 358 surface_get_resolution(old_surface, &old_width, &old_height); 410 359 } 360 411 361 fibril_mutex_lock(&win->guard); 412 362 new_surface = win->surface; 413 363 win->surface = old_surface; 414 364 fibril_mutex_unlock(&win->guard); 415 365 416 366 win->root.rearrange(&win->root, 0, 0, old_width, old_height); 417 367 … … 421 371 fibril_mutex_unlock(&win->guard); 422 372 } 423 373 424 374 surface_destroy(new_surface); 425 } else { 426 /* Deallocate old surface. */ 427 if (old_surface) 428 surface_destroy(old_surface); 375 return; 376 } 377 378 /* Finally deallocate old surface. */ 379 if (old_surface) { 380 surface_destroy(old_surface); 429 381 } 430 382 } … … 508 460 break; 509 461 case ET_SIGNAL_EVENT: 510 handle_signal_event(win, event->data.sig nal);462 handle_signal_event(win, event->data.sig); 511 463 break; 512 464 case ET_WINDOW_RESIZE: 513 handle_resize(win, event->data.resize.offset_x, 514 event->data.resize.offset_y, event->data.resize.width, 515 event->data.resize.height, event->data.resize.placement_flags); 465 handle_resize(win, event->data.rsz.width, event->data.rsz.height); 516 466 break; 517 467 case ET_WINDOW_FOCUS: … … 586 536 } 587 537 588 window_t *window_open(const char *winreg, bool is_main, bool is_decorated, 589 const char *caption) 590 { 538 window_t *window_open(char *winreg, bool is_main, bool is_decorated, 539 const char *caption, sysarg_t x_offset, sysarg_t y_offset) 540 { 541 int rc; 542 591 543 window_t *win = (window_t *) malloc(sizeof(window_t)); 592 if (!win) 544 if (!win) { 593 545 return NULL; 594 546 } 547 595 548 win->is_main = is_main; 596 549 win->is_decorated = is_decorated; … … 598 551 prodcons_initialize(&win->events); 599 552 fibril_mutex_initialize(&win->guard); 600 601 553 widget_init(&win->root, NULL); 602 554 win->root.window = win; … … 610 562 win->focus = NULL; 611 563 win->surface = NULL; 612 564 613 565 service_id_t reg_dsid; 614 int rc = loc_service_get_id(winreg, ®_dsid, 0); 566 async_sess_t *reg_sess; 567 568 rc = loc_service_get_id(winreg, ®_dsid, 0); 615 569 if (rc != EOK) { 616 570 free(win); 617 571 return NULL; 618 572 } 619 620 async_sess_t *reg_sess = loc_service_connect(EXCHANGE_SERIALIZE, 621 reg_dsid, 0); 573 574 reg_sess = loc_service_connect(EXCHANGE_SERIALIZE, reg_dsid, 0); 622 575 if (reg_sess == NULL) { 623 576 free(win); 624 577 return NULL; 625 578 } 626 579 627 580 service_id_t in_dsid; 628 581 service_id_t out_dsid; 629 rc = win_register(reg_sess, &in_dsid, &out_dsid); 582 583 rc = win_register(reg_sess, &in_dsid, &out_dsid, x_offset, y_offset); 630 584 async_hangup(reg_sess); 631 585 if (rc != EOK) { … … 633 587 return NULL; 634 588 } 635 589 636 590 win->osess = loc_service_connect(EXCHANGE_SERIALIZE, out_dsid, 0); 637 591 if (win->osess == NULL) { … … 639 593 return NULL; 640 594 } 641 595 642 596 win->isess = loc_service_connect(EXCHANGE_SERIALIZE, in_dsid, 0); 643 597 if (win->isess == NULL) { … … 646 600 return NULL; 647 601 } 648 649 if (caption == NULL) 602 603 if (caption == NULL) { 650 604 win->caption = NULL; 651 else605 } else { 652 606 win->caption = str_dup(caption); 653 607 } 608 654 609 return win; 655 610 } 656 611 657 void window_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y, 658 sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags) 612 void window_resize(window_t *win, sysarg_t width, sysarg_t height) 659 613 { 660 614 window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t)); … … 662 616 link_initialize(&event->link); 663 617 event->type = ET_WINDOW_RESIZE; 664 event->data.resize.offset_x = offset_x; 665 event->data.resize.offset_y = offset_y; 666 event->data.resize.width = width; 667 event->data.resize.height = height; 668 event->data.resize.placement_flags = placement_flags; 618 event->data.rsz.width = width; 619 event->data.rsz.height = height; 669 620 prodcons_produce(&win->events, &event->link); 670 621 }
Note:
See TracChangeset
for help on using the changeset viewer.