Changeset a35b458 in mainline for uspace/lib/gui/window.c
- Timestamp:
- 2018-03-02T20:10:49Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gui/window.c
r3061bc1 ra35b458 89 89 if (!surface) 90 90 window_yield(widget->window); 91 91 92 92 source_t source; 93 93 source_init(&source); 94 94 95 95 drawctx_t drawctx; 96 96 drawctx_init(&drawctx, surface); 97 97 drawctx_set_source(&drawctx, &source); 98 98 99 99 /* Window border outer bevel */ 100 100 101 101 draw_bevel(&drawctx, &source, widget->vpos, widget->hpos, 102 102 widget->width, widget->height, color_highlight, color_shadow); 103 103 104 104 /* Window border surface */ 105 105 106 106 source_set_color(&source, color_surface); 107 107 drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1, … … 113 113 drawctx_transfer(&drawctx, widget->hpos + widget->width - 3, 114 114 widget->vpos + 1, 2, widget->height - 4); 115 115 116 116 /* Window border inner bevel */ 117 117 118 118 draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3, 119 119 widget->width - 6, widget->height - 6, color_shadow, 120 120 color_highlight); 121 121 122 122 /* Header bevel */ 123 123 124 124 sysarg_t header_hpos = widget->hpos + border_thickness; 125 125 sysarg_t header_vpos = widget->vpos + border_thickness; 126 126 sysarg_t header_width = widget->width - 2 * border_thickness - 127 127 close_thickness; 128 128 129 129 draw_bevel(&drawctx, &source, header_hpos, header_vpos, 130 130 header_width, header_height, widget->window->is_focused ? … … 132 132 widget->window->is_focused ? 133 133 color_header_focus_shadow : color_header_unfocus_shadow); 134 134 135 135 /* Header surface */ 136 136 137 137 source_set_color(&source, widget->window->is_focused ? 138 138 color_header_focus_surface : color_header_unfocus_surface); 139 139 drawctx_transfer(&drawctx, header_hpos + 1, header_vpos + 1, 140 140 header_width - 2, header_height - 2); 141 141 142 142 /* Close button bevel */ 143 143 144 144 sysarg_t close_hpos = widget->hpos + widget->width - 145 145 border_thickness - close_thickness; 146 146 sysarg_t close_vpos = widget->vpos + border_thickness; 147 147 148 148 draw_bevel(&drawctx, &source, close_hpos, close_vpos, 149 149 close_thickness, close_thickness, color_highlight, color_shadow); 150 150 151 151 /* Close button surface */ 152 152 153 153 source_set_color(&source, color_surface); 154 154 drawctx_transfer(&drawctx, close_hpos + 1, close_vpos + 1, 155 155 close_thickness - 2, close_thickness - 2); 156 156 157 157 /* Close button icon */ 158 158 159 159 draw_icon_cross(surface, close_hpos + 3, close_vpos + 3, 160 160 color_highlight, color_shadow); 161 161 162 162 /* Window caption */ 163 163 164 164 font_t *font; 165 165 errno_t rc = embedded_font_create(&font, 16); … … 168 168 return; 169 169 } 170 170 171 171 drawctx_set_font(&drawctx, font); 172 172 source_set_color(&source, widget->window->is_focused ? 173 173 color_caption_focus : color_caption_unfocus); 174 174 175 175 sysarg_t cpt_width; 176 176 sysarg_t cpt_height; 177 177 font_get_box(font, widget->window->caption, &cpt_width, &cpt_height); 178 178 179 179 bool draw_title = 180 180 (widget->width >= 2 * border_thickness + 2 * bevel_thickness + … … 184 184 sysarg_t cpt_y = ((header_height - cpt_height) / 2) + 185 185 widget->vpos + border_thickness; 186 186 187 187 if (widget->window->caption) 188 188 drawctx_print(&drawctx, widget->window->caption, cpt_x, cpt_y); 189 189 } 190 190 191 191 font_release(font); 192 192 window_yield(widget->window); … … 375 375 return; 376 376 } 377 377 378 378 if (height < 2 * border_thickness + header_height) { 379 379 win_damage(win->osess, 0, 0, 0, 0); 380 380 return; 381 381 } 382 382 383 383 /* Allocate resources for new surface. */ 384 384 surface_t *new_surface = surface_create(width, height, NULL, … … 386 386 if (!new_surface) 387 387 return; 388 388 389 389 /* Switch new and old surface. */ 390 390 fibril_mutex_lock(&win->guard); … … 392 392 win->surface = new_surface; 393 393 fibril_mutex_unlock(&win->guard); 394 394 395 395 /* 396 396 * Let all widgets in the tree alter their position and size. … … 398 398 */ 399 399 win->root.rearrange(&win->root, 0, 0, width, height); 400 400 401 401 fibril_mutex_lock(&win->guard); 402 402 surface_reset_damaged_region(win->surface); 403 403 fibril_mutex_unlock(&win->guard); 404 404 405 405 /* Inform compositor about new surface. */ 406 406 errno_t rc = win_resize(win->osess, offset_x, offset_y, width, height, 407 407 placement_flags, surface_direct_access(new_surface)); 408 408 409 409 if (rc != EOK) { 410 410 /* Rollback to old surface. Reverse all changes. */ 411 411 412 412 sysarg_t old_width = 0; 413 413 sysarg_t old_height = 0; 414 414 if (old_surface) 415 415 surface_get_resolution(old_surface, &old_width, &old_height); 416 416 417 417 fibril_mutex_lock(&win->guard); 418 418 new_surface = win->surface; 419 419 win->surface = old_surface; 420 420 fibril_mutex_unlock(&win->guard); 421 421 422 422 win->root.rearrange(&win->root, 0, 0, old_width, old_height); 423 423 424 424 if (win->surface) { 425 425 fibril_mutex_lock(&win->guard); … … 427 427 fibril_mutex_unlock(&win->guard); 428 428 } 429 429 430 430 surface_destroy(new_surface); 431 431 } else { … … 569 569 while (true) { 570 570 window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t)); 571 571 572 572 if (event) { 573 573 rc = win_get_event(win->isess, event); … … 598 598 if (!win) 599 599 return NULL; 600 600 601 601 win->is_main = flags & WINDOW_MAIN; 602 602 win->is_decorated = flags & WINDOW_DECORATED; … … 604 604 prodcons_initialize(&win->events); 605 605 fibril_mutex_initialize(&win->guard); 606 606 607 607 widget_init(&win->root, NULL, data); 608 608 win->root.window = win; … … 616 616 win->focus = NULL; 617 617 win->surface = NULL; 618 618 619 619 service_id_t reg_dsid; 620 620 errno_t rc = loc_service_get_id(winreg, ®_dsid, 0); … … 623 623 return NULL; 624 624 } 625 625 626 626 async_sess_t *reg_sess = 627 627 loc_service_connect(reg_dsid, INTERFACE_COMPOSITOR, 0); … … 630 630 return NULL; 631 631 } 632 632 633 633 service_id_t in_dsid; 634 634 service_id_t out_dsid; … … 639 639 return NULL; 640 640 } 641 641 642 642 win->osess = loc_service_connect(out_dsid, INTERFACE_COMPOSITOR, 0); 643 643 if (win->osess == NULL) { … … 645 645 return NULL; 646 646 } 647 647 648 648 win->isess = loc_service_connect(in_dsid, INTERFACE_COMPOSITOR, 0); 649 649 if (win->isess == NULL) { … … 652 652 return NULL; 653 653 } 654 654 655 655 if (caption == NULL) 656 656 win->caption = NULL; 657 657 else 658 658 win->caption = str_dup(caption); 659 659 660 660 return win; 661 661 } … … 680 680 { 681 681 char *cap; 682 682 683 683 if (caption == NULL) { 684 684 win->caption = NULL; … … 690 690 win->caption = cap; 691 691 } 692 692 693 693 win->is_focused = false; 694 694 handle_refresh(win); 695 695 696 696 return EOK; 697 697 }
Note:
See TracChangeset
for help on using the changeset viewer.