Changeset 66be0288 in mainline for uspace/lib/gui
- Timestamp:
- 2014-01-17T17:02:59Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 476f62c, facc34d
- Parents:
- 2e80321 (diff), 61b5b73d (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. - Location:
- uspace/lib/gui
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gui/Makefile
r2e80321 r66be0288 34 34 35 35 SOURCES = \ 36 common.c \ 36 37 button.c \ 37 38 canvas.c \ -
uspace/lib/gui/button.c
r2e80321 r66be0288 36 36 #include <str.h> 37 37 #include <malloc.h> 38 39 38 #include <drawctx.h> 40 39 #include <surface.h> 41 40 #include "common.h" 42 41 #include "window.h" 43 42 #include "button.h" 44 43 45 static void paint_internal(widget_t *w) 46 { 47 button_t *btn = (button_t *) w; 48 44 static pixel_t color_highlight = PIXEL(255, 255, 255, 255); 45 static pixel_t color_shadow = PIXEL(255, 85, 85, 85); 46 47 static void paint_internal(widget_t *widget) 48 { 49 button_t *btn = (button_t *) widget; 50 49 51 surface_t *surface = window_claim(btn->widget.window); 50 if (!surface) {52 if (!surface) 51 53 window_yield(btn->widget.window); 54 55 source_t source; 56 source_init(&source); 57 58 drawctx_t drawctx; 59 drawctx_init(&drawctx, surface); 60 61 drawctx_set_source(&drawctx, &btn->background); 62 drawctx_transfer(&drawctx, widget->hpos, widget->vpos, 63 widget->width, widget->height); 64 65 if ((widget->width >= 8) && (widget->height >= 8)) { 66 drawctx_set_source(&drawctx, &source); 67 draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3, 68 widget->width - 6, widget->height - 6, color_highlight, 69 color_shadow); 70 71 drawctx_set_source(&drawctx, &btn->foreground); 72 drawctx_transfer(&drawctx, widget->hpos + 4, widget->vpos + 4, 73 widget->width - 8, widget->height - 8); 52 74 } 53 54 drawctx_t drawctx; 55 56 drawctx_init(&drawctx, surface); 57 drawctx_set_source(&drawctx, &btn->foreground); 58 drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, w->height); 59 60 if (w->width >= 6 && w->height >= 6) { 61 drawctx_set_source(&drawctx, &btn->background); 62 drawctx_transfer(&drawctx, 63 w->hpos + 3, w->vpos + 3, w->width - 6, w->height - 6); 64 } 65 75 66 76 sysarg_t cpt_width; 67 77 sysarg_t cpt_height; 68 78 font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height); 69 if (w->width >= cpt_width && w->height >= cpt_height) { 70 drawctx_set_source(&drawctx, &btn->foreground); 79 80 if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) { 81 sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos; 82 sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos; 83 84 drawctx_set_source(&drawctx, &btn->text); 71 85 drawctx_set_font(&drawctx, &btn->font); 72 sysarg_t x = ((w->width - cpt_width) / 2) + w->hpos; 73 sysarg_t y = ((w->height - cpt_height) / 2) + w->vpos; 74 if (btn->caption) { 86 87 if (btn->caption) 75 88 drawctx_print(&drawctx, btn->caption, x, y); 76 }77 89 } 78 90 79 91 window_yield(btn->widget.window); 80 92 } … … 90 102 { 91 103 button_t *btn = (button_t *) widget; 92 104 93 105 deinit_button(btn); 94 95 106 free(btn); 96 107 } … … 117 128 { 118 129 button_t *btn = (button_t *) widget; 119 if (event.key == KC_ENTER && event.type == KEY_PRESS) { 130 131 if (event.key == KC_ENTER && event.type == KEY_PRESS) 120 132 sig_send(&btn->clicked, NULL); 121 }122 133 } 123 134 … … 126 137 button_t *btn = (button_t *) widget; 127 138 widget->window->focus = widget; 128 139 129 140 // TODO make the click logic more robust (mouse grabbing, mouse moves) 130 141 if (event.btn_num == 1) { 131 if (event.type == POS_RELEASE) {142 if (event.type == POS_RELEASE) 132 143 sig_send(&btn->clicked, NULL); 133 }134 144 } 135 145 } 136 146 137 bool init_button(button_t *btn, widget_t *parent, 138 const char *caption, uint16_t points, pixel_t background, pixel_t foreground)147 bool init_button(button_t *btn, widget_t *parent, const char *caption, 148 uint16_t points, pixel_t background, pixel_t foreground, pixel_t text) 139 149 { 140 150 widget_init(&btn->widget, parent); 141 151 142 152 btn->widget.destroy = button_destroy; 143 153 btn->widget.reconfigure = button_reconfigure; … … 146 156 btn->widget.handle_keyboard_event = button_handle_keyboard_event; 147 157 btn->widget.handle_position_event = button_handle_position_event; 148 158 149 159 source_init(&btn->background); 150 160 source_set_color(&btn->background, background); 161 151 162 source_init(&btn->foreground); 152 163 source_set_color(&btn->foreground, foreground); 153 154 if (caption == NULL) { 164 165 source_init(&btn->text); 166 source_set_color(&btn->text, text); 167 168 if (caption == NULL) 155 169 btn->caption = NULL; 156 } else {170 else 157 171 btn->caption = str_dup(caption); 158 }172 159 173 font_init(&btn->font, FONT_DECODER_EMBEDDED, NULL, points); 160 174 161 175 sysarg_t cpt_width; 162 176 sysarg_t cpt_height; 163 177 font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height); 164 btn->widget.width_min = cpt_width + 8;165 btn->widget.height_min = cpt_height + 8;166 btn->widget.width_ideal = cpt_width + 28;167 btn->widget.height_ideal = cpt_height + 8;168 178 btn->widget.width_min = cpt_width + 10; 179 btn->widget.height_min = cpt_height + 10; 180 btn->widget.width_ideal = cpt_width + 30; 181 btn->widget.height_ideal = cpt_height + 10; 182 169 183 return true; 170 184 } 171 185 172 button_t *create_button(widget_t *parent, 173 const char *caption, uint16_t points, pixel_t background, pixel_t foreground)186 button_t *create_button(widget_t *parent, const char *caption, uint16_t points, 187 pixel_t background, pixel_t foreground, pixel_t text) 174 188 { 175 189 button_t *btn = (button_t *) malloc(sizeof(button_t)); 176 if (!btn) {190 if (!btn) 177 191 return NULL; 178 }179 180 if (init_button(btn, parent, caption, points, background, foreground)) {192 193 if (init_button(btn, parent, caption, points, background, foreground, 194 text)) 181 195 return btn; 182 } else { 183 free(btn); 184 return NULL; 185 } 196 197 free(btn); 198 return NULL; 186 199 } 187 200 -
uspace/lib/gui/button.h
r2e80321 r66be0288 50 50 source_t background; 51 51 source_t foreground; 52 source_t text; 52 53 char *caption; 53 54 font_t font; … … 55 56 } button_t; 56 57 57 extern bool init_button(button_t *, widget_t *, const char *, uint16_t, pixel_t, pixel_t); 58 extern button_t *create_button(widget_t *, const char *, uint16_t, pixel_t, pixel_t); 58 extern bool init_button(button_t *, widget_t *, const char *, uint16_t, pixel_t, 59 pixel_t, pixel_t); 60 extern button_t *create_button(widget_t *, const char *, uint16_t, pixel_t, 61 pixel_t, pixel_t); 59 62 extern void deinit_button(button_t *); 60 63 -
uspace/lib/gui/connection.c
r2e80321 r66be0288 210 210 link_initialize(&event->link); 211 211 event->type = ET_SIGNAL_EVENT; 212 event->data.sig .object = (sysarg_t) cur->widget;213 event->data.sig .slot = (sysarg_t) cur->slot;214 event->data.sig .argument = (sysarg_t) data_copy;212 event->data.signal.object = (sysarg_t) cur->widget; 213 event->data.signal.slot = (sysarg_t) cur->slot; 214 event->data.signal.argument = (sysarg_t) data_copy; 215 215 prodcons_produce(&cur->widget->window->events, &event->link); 216 216 } else { -
uspace/lib/gui/label.c
r2e80321 r66be0288 36 36 #include <str.h> 37 37 #include <malloc.h> 38 39 38 #include <drawctx.h> 40 39 #include <surface.h> 41 42 40 #include "window.h" 43 41 #include "label.h" 44 42 45 static void paint_internal(widget_t *w )43 static void paint_internal(widget_t *widget) 46 44 { 47 label_t *lbl = (label_t *) w ;45 label_t *lbl = (label_t *) widget; 48 46 49 47 surface_t *surface = window_claim(lbl->widget.window); 50 if (!surface) {48 if (!surface) 51 49 window_yield(lbl->widget.window); 52 } 53 50 54 51 drawctx_t drawctx; 55 56 52 drawctx_init(&drawctx, surface); 53 57 54 drawctx_set_source(&drawctx, &lbl->background); 58 drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, w->height); 59 55 drawctx_transfer(&drawctx, widget->hpos, widget->vpos, widget->width, 56 widget->height); 57 60 58 sysarg_t cpt_width; 61 59 sysarg_t cpt_height; 62 60 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 63 if (w->width >= cpt_width && w->height >= cpt_height) { 64 drawctx_set_source(&drawctx, &lbl->foreground); 61 62 if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) { 63 sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos; 64 sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos; 65 66 drawctx_set_source(&drawctx, &lbl->text); 65 67 drawctx_set_font(&drawctx, &lbl->font); 66 sysarg_t x = ((w->width - cpt_width) / 2) + w->hpos; 67 sysarg_t y = ((w->height - cpt_height) / 2) + w->vpos; 68 if (lbl->caption) { 68 69 if (lbl->caption) 69 70 drawctx_print(&drawctx, lbl->caption, x, y); 70 }71 71 } 72 72 73 73 window_yield(lbl->widget.window); 74 74 } … … 78 78 if (data != NULL) { 79 79 label_t *lbl = (label_t *) widget; 80 80 81 const char *new_caption = (const char *) data; 81 82 lbl->caption = str_dup(new_caption); 82 83 83 84 sysarg_t cpt_width; 84 85 sysarg_t cpt_height; 85 86 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 87 86 88 lbl->widget.width_min = cpt_width + 4; 87 89 lbl->widget.height_min = cpt_height + 4; 88 90 lbl->widget.width_ideal = lbl->widget.width_min; 89 91 lbl->widget.height_ideal = lbl->widget.height_min; 90 92 91 93 window_refresh(lbl->widget.window); 92 94 } … … 103 105 { 104 106 label_t *lbl = (label_t *) widget; 105 107 106 108 deinit_label(lbl); 107 108 109 free(lbl); 109 110 } … … 137 138 } 138 139 139 bool init_label(label_t *lbl, widget_t *parent, 140 const char *caption, uint16_t points, pixel_t background, pixel_t foreground)140 bool init_label(label_t *lbl, widget_t *parent, const char *caption, 141 uint16_t points, pixel_t background, pixel_t text) 141 142 { 142 143 widget_init(&lbl->widget, parent); 143 144 144 145 lbl->widget.destroy = label_destroy; 145 146 lbl->widget.reconfigure = label_reconfigure; … … 148 149 lbl->widget.handle_keyboard_event = label_handle_keyboard_event; 149 150 lbl->widget.handle_position_event = label_handle_position_event; 150 151 151 152 source_init(&lbl->background); 152 153 source_set_color(&lbl->background, background); 153 source_init(&lbl->foreground); 154 source_set_color(&lbl->foreground, foreground); 155 156 if (caption == NULL) { 154 155 source_init(&lbl->text); 156 source_set_color(&lbl->text, text); 157 158 if (caption == NULL) 157 159 lbl->caption = NULL; 158 } else {160 else 159 161 lbl->caption = str_dup(caption); 160 }162 161 163 font_init(&lbl->font, FONT_DECODER_EMBEDDED, NULL, points); 162 164 163 165 sysarg_t cpt_width; 164 166 sysarg_t cpt_height; 165 167 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 168 166 169 lbl->widget.width_min = cpt_width + 4; 167 170 lbl->widget.height_min = cpt_height + 4; 168 171 lbl->widget.width_ideal = lbl->widget.width_min; 169 172 lbl->widget.height_ideal = lbl->widget.height_min; 170 173 171 174 lbl->rewrite = on_rewrite; 172 175 173 176 return true; 174 177 } 175 178 176 label_t *create_label(widget_t *parent, 177 const char *caption, uint16_t points, pixel_t background, pixel_t foreground)179 label_t *create_label(widget_t *parent, const char *caption, uint16_t points, 180 pixel_t background, pixel_t text) 178 181 { 179 182 label_t *lbl = (label_t *) malloc(sizeof(label_t)); 180 if (!lbl) {183 if (!lbl) 181 184 return NULL; 182 } 183 184 if (init_label(lbl, parent, caption, points, background, foreground)) { 185 186 if (init_label(lbl, parent, caption, points, background, text)) 185 187 return lbl; 186 } else { 187 free(lbl); 188 return NULL; 189 } 188 189 free(lbl); 190 return NULL; 190 191 } 191 192 192 193 /** @} 193 194 */ 194 -
uspace/lib/gui/label.h
r2e80321 r66be0288 49 49 widget_t widget; 50 50 source_t background; 51 source_t foreground;51 source_t text; 52 52 char *caption; 53 53 font_t font; … … 55 55 } label_t; 56 56 57 extern bool init_label(label_t *, widget_t *, const char *, uint16_t, pixel_t, pixel_t); 58 extern label_t *create_label(widget_t *, const char *, uint16_t, pixel_t, pixel_t); 57 extern bool init_label(label_t *, widget_t *, const char *, uint16_t, pixel_t, 58 pixel_t); 59 extern label_t *create_label(widget_t *, const char *, uint16_t, pixel_t, 60 pixel_t); 59 61 extern void deinit_label(label_t *); 60 62 -
uspace/lib/gui/window.c
r2e80321 r66be0288 56 56 #include <surface.h> 57 57 58 #include "common.h" 58 59 #include "connection.h" 59 60 #include "widget.h" 60 61 #include "window.h" 61 62 62 static sysarg_t border_thickness = 5; 63 static sysarg_t border_thickness = 4; 64 static sysarg_t bevel_thickness = 1; 63 65 static sysarg_t header_height = 20; 64 66 static sysarg_t header_min_width = 40; 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, 88, 106, 196); 69 static pixel_t header_fg_focus_color = PIXEL(255, 255, 255, 255); 70 static pixel_t header_bg_unfocus_color = PIXEL(255, 12, 57, 92); 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 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 80 90 source_t source; 81 font_t font; 91 source_init(&source); 92 82 93 drawctx_t drawctx; 83 84 source_init(&source);85 font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);86 94 drawctx_init(&drawctx, surface); 87 95 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 88 165 drawctx_set_font(&drawctx, &font); 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 166 source_set_color(&source, widget->window->is_focused ? 167 color_caption_focus : color_caption_unfocus); 168 104 169 sysarg_t cpt_width; 105 170 sysarg_t cpt_height; 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); 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); 119 176 if (draw_title) { 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 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 127 185 font_release(&font); 128 window_yield(w ->window);186 window_yield(widget->window); 129 187 } 130 188 … … 138 196 if (widget->window->is_decorated) { 139 197 list_foreach(widget->children, link, widget_t, child) { 140 child->rearrange(child, 198 child->rearrange(child, 141 199 widget->hpos + border_thickness, 142 200 widget->vpos + border_thickness + header_height, … … 211 269 (event.vpos >= border_thickness) && 212 270 (event.vpos < border_thickness + header_height); 213 bool close = header && (event.hpos >= width - border_thickness - close_width); 271 bool close = (header) && 272 (event.hpos >= width - border_thickness - close_thickness); 214 273 215 274 if (top && left && allowed_button) { … … 292 351 } 293 352 294 static void handle_signal_event(window_t *win, sig _event_t event)353 static void handle_signal_event(window_t *win, signal_event_t event) 295 354 { 296 355 widget_t *widget = (widget_t *) event.object; … … 303 362 } 304 363 305 static void handle_resize(window_t *win, sysarg_t width, sysarg_t height) 306 { 307 int rc; 308 surface_t *old_surface; 309 surface_t *new_surface; 310 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 { 311 367 if (width < 2 * border_thickness + header_min_width) { 312 368 win_damage(win->osess, 0, 0, 0, 0); 313 369 return; 314 370 } 315 371 316 372 if (height < 2 * border_thickness + header_height) { 317 373 win_damage(win->osess, 0, 0, 0, 0); 318 374 return; 319 375 } 320 376 321 377 /* Allocate resources for new surface. */ 322 new_surface = surface_create(width, height, NULL, SURFACE_FLAG_SHARED); 323 if (!new_surface) { 378 surface_t *new_surface = surface_create(width, height, NULL, 379 SURFACE_FLAG_SHARED); 380 if (!new_surface) 324 381 return; 325 } 326 382 327 383 /* Switch new and old surface. */ 328 384 fibril_mutex_lock(&win->guard); 329 old_surface = win->surface;385 surface_t *old_surface = win->surface; 330 386 win->surface = new_surface; 331 387 fibril_mutex_unlock(&win->guard); 332 333 /* Let all widgets in the tree alter their position and size. Widgets might 334 * also paint themselves onto the new surface. */ 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 */ 335 393 win->root.rearrange(&win->root, 0, 0, width, height); 336 394 337 395 fibril_mutex_lock(&win->guard); 338 396 surface_reset_damaged_region(win->surface); 339 397 fibril_mutex_unlock(&win->guard); 340 398 341 399 /* Inform compositor about new surface. */ 342 rc = win_resize(win->osess,343 width, height, surface_direct_access(new_surface));344 400 int rc = win_resize(win->osess, offset_x, offset_y, width, height, 401 placement_flags, surface_direct_access(new_surface)); 402 345 403 if (rc != EOK) { 346 404 /* Rollback to old surface. Reverse all changes. */ 347 405 348 406 sysarg_t old_width = 0; 349 407 sysarg_t old_height = 0; 350 if (old_surface) {408 if (old_surface) 351 409 surface_get_resolution(old_surface, &old_width, &old_height); 352 } 353 410 354 411 fibril_mutex_lock(&win->guard); 355 412 new_surface = win->surface; 356 413 win->surface = old_surface; 357 414 fibril_mutex_unlock(&win->guard); 358 415 359 416 win->root.rearrange(&win->root, 0, 0, old_width, old_height); 360 417 … … 364 421 fibril_mutex_unlock(&win->guard); 365 422 } 366 423 367 424 surface_destroy(new_surface); 368 return; 369 } 370 371 /* Finally deallocate old surface. */ 372 if (old_surface) { 373 surface_destroy(old_surface); 425 } else { 426 /* Deallocate old surface. */ 427 if (old_surface) 428 surface_destroy(old_surface); 374 429 } 375 430 } … … 453 508 break; 454 509 case ET_SIGNAL_EVENT: 455 handle_signal_event(win, event->data.sig );510 handle_signal_event(win, event->data.signal); 456 511 break; 457 512 case ET_WINDOW_RESIZE: 458 handle_resize(win, event->data.rsz.width, event->data.rsz.height); 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); 459 516 break; 460 517 case ET_WINDOW_FOCUS: … … 530 587 531 588 window_t *window_open(const char *winreg, bool is_main, bool is_decorated, 532 const char *caption, sysarg_t x_offset, sysarg_t y_offset) 533 { 534 int rc; 535 589 const char *caption) 590 { 536 591 window_t *win = (window_t *) malloc(sizeof(window_t)); 537 if (!win) {592 if (!win) 538 593 return NULL; 539 } 540 594 541 595 win->is_main = is_main; 542 596 win->is_decorated = is_decorated; … … 544 598 prodcons_initialize(&win->events); 545 599 fibril_mutex_initialize(&win->guard); 600 546 601 widget_init(&win->root, NULL); 547 602 win->root.window = win; … … 555 610 win->focus = NULL; 556 611 win->surface = NULL; 557 612 558 613 service_id_t reg_dsid; 559 async_sess_t *reg_sess; 560 561 rc = loc_service_get_id(winreg, ®_dsid, 0); 614 int rc = loc_service_get_id(winreg, ®_dsid, 0); 562 615 if (rc != EOK) { 563 616 free(win); 564 617 return NULL; 565 618 } 566 567 reg_sess = loc_service_connect(EXCHANGE_SERIALIZE, reg_dsid, 0); 619 620 async_sess_t *reg_sess = loc_service_connect(EXCHANGE_SERIALIZE, 621 reg_dsid, 0); 568 622 if (reg_sess == NULL) { 569 623 free(win); 570 624 return NULL; 571 625 } 572 626 573 627 service_id_t in_dsid; 574 628 service_id_t out_dsid; 575 576 rc = win_register(reg_sess, &in_dsid, &out_dsid, x_offset, y_offset); 629 rc = win_register(reg_sess, &in_dsid, &out_dsid); 577 630 async_hangup(reg_sess); 578 631 if (rc != EOK) { … … 580 633 return NULL; 581 634 } 582 635 583 636 win->osess = loc_service_connect(EXCHANGE_SERIALIZE, out_dsid, 0); 584 637 if (win->osess == NULL) { … … 586 639 return NULL; 587 640 } 588 641 589 642 win->isess = loc_service_connect(EXCHANGE_SERIALIZE, in_dsid, 0); 590 643 if (win->isess == NULL) { … … 593 646 return NULL; 594 647 } 595 596 if (caption == NULL) {648 649 if (caption == NULL) 597 650 win->caption = NULL; 598 } else {651 else 599 652 win->caption = str_dup(caption); 600 } 601 653 602 654 return win; 603 655 } 604 656 605 void window_resize(window_t *win, sysarg_t width, sysarg_t height) 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) 606 659 { 607 660 window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t)); … … 609 662 link_initialize(&event->link); 610 663 event->type = ET_WINDOW_RESIZE; 611 event->data.rsz.width = width; 612 event->data.rsz.height = height; 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; 613 669 prodcons_produce(&win->events, &event->link); 614 670 } -
uspace/lib/gui/window.h
r2e80321 r66be0288 66 66 * If the window is declared as main, its closure causes termination of the 67 67 * whole application. Note that opened window does not have any surface yet. */ 68 extern window_t *window_open(const char *, bool, bool, const char *, sysarg_t, 69 sysarg_t); 68 extern window_t *window_open(const char *, bool, bool, const char *); 70 69 71 70 /** … … 74 73 * and to paint themselves on the new surface (top-bottom order). Should be 75 74 * called also after opening new window to obtain surface. */ 76 extern void window_resize(window_t *, sysarg_t, sysarg_t); 75 extern void window_resize(window_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 76 window_placement_flags_t); 77 77 78 78 /**
Note:
See TracChangeset
for help on using the changeset viewer.