[6d5e378] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Petr Koupy
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup gui
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[3e6a98c5] | 36 | #include <stdbool.h>
|
---|
[6d5e378] | 37 | #include <errno.h>
|
---|
| 38 | #include <stdio.h>
|
---|
[c23275a] | 39 | #include <stdlib.h>
|
---|
[6d5e378] | 40 |
|
---|
| 41 | #include <as.h>
|
---|
[38d150e] | 42 | #include <stdlib.h>
|
---|
[6d5e378] | 43 | #include <str.h>
|
---|
| 44 |
|
---|
| 45 | #include <fibril.h>
|
---|
| 46 | #include <task.h>
|
---|
| 47 | #include <adt/prodcons.h>
|
---|
| 48 | #include <adt/list.h>
|
---|
| 49 |
|
---|
| 50 | #include <loc.h>
|
---|
| 51 |
|
---|
| 52 | #include <io/pixel.h>
|
---|
[2bb6d04] | 53 | #include <draw/source.h>
|
---|
| 54 | #include <draw/font.h>
|
---|
| 55 | #include <draw/drawctx.h>
|
---|
| 56 | #include <draw/surface.h>
|
---|
[4645b2c] | 57 | #include <display.h>
|
---|
[6d5e378] | 58 |
|
---|
[296e124e] | 59 | #include "common.h"
|
---|
[6d5e378] | 60 | #include "connection.h"
|
---|
| 61 | #include "widget.h"
|
---|
| 62 | #include "window.h"
|
---|
| 63 |
|
---|
[296e124e] | 64 | static sysarg_t border_thickness = 4;
|
---|
| 65 | static sysarg_t bevel_thickness = 1;
|
---|
[61b5b73d] | 66 | static sysarg_t header_height = 20;
|
---|
[6d5e378] | 67 | static sysarg_t header_min_width = 40;
|
---|
[61b5b73d] | 68 | static sysarg_t close_thickness = 20;
|
---|
[ef20a91] | 69 | static sysarg_t corner_size = 24;
|
---|
[6d5e378] | 70 |
|
---|
[296e124e] | 71 | static pixel_t color_highlight = PIXEL(255, 255, 255, 255);
|
---|
| 72 | static pixel_t color_shadow = PIXEL(255, 85, 85, 85);
|
---|
| 73 | static pixel_t color_surface = PIXEL(255, 186, 186, 186);
|
---|
[6d5e378] | 74 |
|
---|
[296e124e] | 75 | static pixel_t color_header_focus_highlight = PIXEL(255, 120, 145, 255);
|
---|
| 76 | static pixel_t color_header_focus_shadow = PIXEL(255, 40, 48, 89);
|
---|
| 77 | static pixel_t color_header_focus_surface = PIXEL(255, 88, 106, 196);
|
---|
[6d5e378] | 78 |
|
---|
[296e124e] | 79 | static pixel_t color_header_unfocus_highlight = PIXEL(255, 16, 78, 126);
|
---|
| 80 | static pixel_t color_header_unfocus_shadow = PIXEL(255, 5, 26, 42);
|
---|
| 81 | static pixel_t color_header_unfocus_surface = PIXEL(255, 12, 57, 92);
|
---|
[6d5e378] | 82 |
|
---|
[296e124e] | 83 | static pixel_t color_caption_focus = PIXEL(255, 255, 255, 255);
|
---|
| 84 | static pixel_t color_caption_unfocus = PIXEL(255, 207, 207, 207);
|
---|
| 85 |
|
---|
[338d0935] | 86 | static void window_close_event(void *);
|
---|
[b0a94854] | 87 | static void window_focus_event(void *);
|
---|
[287688f2] | 88 | static void window_kbd_event(void *, kbd_event_t *);
|
---|
[f7fb2b21] | 89 | static void window_pos_event(void *, pos_event_t *);
|
---|
[e022819] | 90 | static void window_resize_event(void *, gfx_rect_t *);
|
---|
[b0a94854] | 91 | static void window_unfocus_event(void *);
|
---|
[287688f2] | 92 |
|
---|
| 93 | static display_wnd_cb_t window_cb = {
|
---|
[338d0935] | 94 | .close_event = window_close_event,
|
---|
[b0a94854] | 95 | .focus_event = window_focus_event,
|
---|
[f7fb2b21] | 96 | .kbd_event = window_kbd_event,
|
---|
[b0a94854] | 97 | .pos_event = window_pos_event,
|
---|
[e022819] | 98 | .resize_event = window_resize_event,
|
---|
[b0a94854] | 99 | .unfocus_event = window_unfocus_event
|
---|
[287688f2] | 100 | };
|
---|
| 101 |
|
---|
[9242ad9] | 102 | static void set_cursor(window_t *window, display_stock_cursor_t cursor)
|
---|
| 103 | {
|
---|
| 104 | if (cursor != window->cursor) {
|
---|
| 105 | (void) display_window_set_cursor(window->dwindow, cursor);
|
---|
| 106 | window->cursor = cursor;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[296e124e] | 110 | static void paint_internal(widget_t *widget)
|
---|
| 111 | {
|
---|
| 112 | surface_t *surface = window_claim(widget->window);
|
---|
| 113 | if (!surface)
|
---|
| 114 | window_yield(widget->window);
|
---|
[a35b458] | 115 |
|
---|
[296e124e] | 116 | source_t source;
|
---|
[6d5e378] | 117 | source_init(&source);
|
---|
[a35b458] | 118 |
|
---|
[296e124e] | 119 | drawctx_t drawctx;
|
---|
[6d5e378] | 120 | drawctx_init(&drawctx, surface);
|
---|
| 121 | drawctx_set_source(&drawctx, &source);
|
---|
[a35b458] | 122 |
|
---|
[296e124e] | 123 | /* Window border outer bevel */
|
---|
[a35b458] | 124 |
|
---|
[296e124e] | 125 | draw_bevel(&drawctx, &source, widget->vpos, widget->hpos,
|
---|
| 126 | widget->width, widget->height, color_highlight, color_shadow);
|
---|
[a35b458] | 127 |
|
---|
[296e124e] | 128 | /* Window border surface */
|
---|
[a35b458] | 129 |
|
---|
[296e124e] | 130 | source_set_color(&source, color_surface);
|
---|
| 131 | drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,
|
---|
| 132 | widget->width - 2, 2);
|
---|
| 133 | drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,
|
---|
| 134 | 2, widget->height - 2);
|
---|
| 135 | drawctx_transfer(&drawctx, widget->hpos + 1,
|
---|
| 136 | widget->vpos + widget->height - 3, widget->width - 2, 2);
|
---|
| 137 | drawctx_transfer(&drawctx, widget->hpos + widget->width - 3,
|
---|
| 138 | widget->vpos + 1, 2, widget->height - 4);
|
---|
[a35b458] | 139 |
|
---|
[296e124e] | 140 | /* Window border inner bevel */
|
---|
[a35b458] | 141 |
|
---|
[296e124e] | 142 | draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3,
|
---|
| 143 | widget->width - 6, widget->height - 6, color_shadow,
|
---|
| 144 | color_highlight);
|
---|
[a35b458] | 145 |
|
---|
[296e124e] | 146 | /* Header bevel */
|
---|
[a35b458] | 147 |
|
---|
[296e124e] | 148 | sysarg_t header_hpos = widget->hpos + border_thickness;
|
---|
| 149 | sysarg_t header_vpos = widget->vpos + border_thickness;
|
---|
| 150 | sysarg_t header_width = widget->width - 2 * border_thickness -
|
---|
| 151 | close_thickness;
|
---|
[a35b458] | 152 |
|
---|
[296e124e] | 153 | draw_bevel(&drawctx, &source, header_hpos, header_vpos,
|
---|
| 154 | header_width, header_height, widget->window->is_focused ?
|
---|
| 155 | color_header_focus_highlight : color_header_unfocus_highlight,
|
---|
| 156 | widget->window->is_focused ?
|
---|
| 157 | color_header_focus_shadow : color_header_unfocus_shadow);
|
---|
[a35b458] | 158 |
|
---|
[296e124e] | 159 | /* Header surface */
|
---|
[a35b458] | 160 |
|
---|
[296e124e] | 161 | source_set_color(&source, widget->window->is_focused ?
|
---|
| 162 | color_header_focus_surface : color_header_unfocus_surface);
|
---|
| 163 | drawctx_transfer(&drawctx, header_hpos + 1, header_vpos + 1,
|
---|
| 164 | header_width - 2, header_height - 2);
|
---|
[a35b458] | 165 |
|
---|
[296e124e] | 166 | /* Close button bevel */
|
---|
[a35b458] | 167 |
|
---|
[296e124e] | 168 | sysarg_t close_hpos = widget->hpos + widget->width -
|
---|
| 169 | border_thickness - close_thickness;
|
---|
| 170 | sysarg_t close_vpos = widget->vpos + border_thickness;
|
---|
[a35b458] | 171 |
|
---|
[296e124e] | 172 | draw_bevel(&drawctx, &source, close_hpos, close_vpos,
|
---|
| 173 | close_thickness, close_thickness, color_highlight, color_shadow);
|
---|
[a35b458] | 174 |
|
---|
[296e124e] | 175 | /* Close button surface */
|
---|
[a35b458] | 176 |
|
---|
[296e124e] | 177 | source_set_color(&source, color_surface);
|
---|
| 178 | drawctx_transfer(&drawctx, close_hpos + 1, close_vpos + 1,
|
---|
| 179 | close_thickness - 2, close_thickness - 2);
|
---|
[a35b458] | 180 |
|
---|
[296e124e] | 181 | /* Close button icon */
|
---|
[a35b458] | 182 |
|
---|
[61b5b73d] | 183 | draw_icon_cross(surface, close_hpos + 3, close_vpos + 3,
|
---|
| 184 | color_highlight, color_shadow);
|
---|
[a35b458] | 185 |
|
---|
[296e124e] | 186 | /* Window caption */
|
---|
[a35b458] | 187 |
|
---|
[2cc1ec0] | 188 | font_t *font;
|
---|
[b7fd2a0] | 189 | errno_t rc = embedded_font_create(&font, 16);
|
---|
[2cc1ec0] | 190 | if (rc != EOK) {
|
---|
| 191 | window_yield(widget->window);
|
---|
| 192 | return;
|
---|
| 193 | }
|
---|
[a35b458] | 194 |
|
---|
[2cc1ec0] | 195 | drawctx_set_font(&drawctx, font);
|
---|
[296e124e] | 196 | source_set_color(&source, widget->window->is_focused ?
|
---|
| 197 | color_caption_focus : color_caption_unfocus);
|
---|
[a35b458] | 198 |
|
---|
[6d5e378] | 199 | sysarg_t cpt_width;
|
---|
| 200 | sysarg_t cpt_height;
|
---|
[2cc1ec0] | 201 | font_get_box(font, widget->window->caption, &cpt_width, &cpt_height);
|
---|
[a35b458] | 202 |
|
---|
[296e124e] | 203 | bool draw_title =
|
---|
| 204 | (widget->width >= 2 * border_thickness + 2 * bevel_thickness +
|
---|
| 205 | close_thickness + cpt_width);
|
---|
[6d5e378] | 206 | if (draw_title) {
|
---|
[296e124e] | 207 | sysarg_t cpt_x = ((widget->width - cpt_width) / 2) + widget->hpos;
|
---|
| 208 | sysarg_t cpt_y = ((header_height - cpt_height) / 2) +
|
---|
| 209 | widget->vpos + border_thickness;
|
---|
[a35b458] | 210 |
|
---|
[296e124e] | 211 | if (widget->window->caption)
|
---|
| 212 | drawctx_print(&drawctx, widget->window->caption, cpt_x, cpt_y);
|
---|
[6d5e378] | 213 | }
|
---|
[a35b458] | 214 |
|
---|
[2cc1ec0] | 215 | font_release(font);
|
---|
[296e124e] | 216 | window_yield(widget->window);
|
---|
[6d5e378] | 217 | }
|
---|
| 218 |
|
---|
| 219 | static void root_destroy(widget_t *widget)
|
---|
| 220 | {
|
---|
| 221 | widget_deinit(widget);
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | static void root_reconfigure(widget_t *widget)
|
---|
| 225 | {
|
---|
| 226 | if (widget->window->is_decorated) {
|
---|
[feeac0d] | 227 | list_foreach(widget->children, link, widget_t, child) {
|
---|
[296e124e] | 228 | child->rearrange(child,
|
---|
[6d5e378] | 229 | widget->hpos + border_thickness,
|
---|
| 230 | widget->vpos + border_thickness + header_height,
|
---|
| 231 | widget->width - 2 * border_thickness,
|
---|
| 232 | widget->height - 2 * border_thickness - header_height);
|
---|
| 233 | }
|
---|
| 234 | } else {
|
---|
[feeac0d] | 235 | list_foreach(widget->children, link, widget_t, child) {
|
---|
[6d5e378] | 236 | child->rearrange(child, widget->hpos, widget->vpos,
|
---|
| 237 | widget->width, widget->height);
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | static void root_rearrange(widget_t *widget, sysarg_t hpos, sysarg_t vpos,
|
---|
| 243 | sysarg_t width, sysarg_t height)
|
---|
| 244 | {
|
---|
| 245 | widget_modify(widget, hpos, vpos, width, height);
|
---|
| 246 | if (widget->window->is_decorated) {
|
---|
| 247 | paint_internal(widget);
|
---|
[feeac0d] | 248 | list_foreach(widget->children, link, widget_t, child) {
|
---|
[1b20da0] | 249 | child->rearrange(child,
|
---|
[6d5e378] | 250 | hpos + border_thickness,
|
---|
| 251 | vpos + border_thickness + header_height,
|
---|
| 252 | width - 2 * border_thickness,
|
---|
| 253 | height - 2 * border_thickness - header_height);
|
---|
| 254 | }
|
---|
| 255 | } else {
|
---|
[feeac0d] | 256 | list_foreach(widget->children, link, widget_t, child) {
|
---|
[6d5e378] | 257 | child->rearrange(child, hpos, vpos, width, height);
|
---|
| 258 | }
|
---|
| 259 | }
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | static void root_repaint(widget_t *widget)
|
---|
| 263 | {
|
---|
| 264 | if (widget->window->is_decorated) {
|
---|
| 265 | paint_internal(widget);
|
---|
| 266 | }
|
---|
[feeac0d] | 267 | list_foreach(widget->children, link, widget_t, child) {
|
---|
[6d5e378] | 268 | child->repaint(child);
|
---|
| 269 | }
|
---|
| 270 | if (widget->window->is_decorated) {
|
---|
| 271 | window_damage(widget->window);
|
---|
| 272 | }
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | static void root_handle_keyboard_event(widget_t *widget, kbd_event_t event)
|
---|
| 276 | {
|
---|
| 277 | if (!list_empty(&widget->children)) {
|
---|
| 278 | widget_t *child = (widget_t *) list_first(&widget->children);
|
---|
| 279 | child->handle_keyboard_event(child, event);
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | static void root_handle_position_event(widget_t *widget, pos_event_t event)
|
---|
| 284 | {
|
---|
[a2e104e] | 285 | gfx_coord2_t pos;
|
---|
| 286 |
|
---|
[6d5e378] | 287 | if (widget->window->is_decorated) {
|
---|
| 288 | sysarg_t width = widget->width;
|
---|
| 289 | sysarg_t height = widget->height;
|
---|
| 290 |
|
---|
| 291 | bool btn_left = (event.btn_num == 1) && (event.type == POS_PRESS);
|
---|
| 292 |
|
---|
| 293 | bool left = (event.hpos < border_thickness);
|
---|
| 294 | bool right = (event.hpos >= width - border_thickness);
|
---|
| 295 | bool top = (event.vpos < border_thickness);
|
---|
| 296 | bool bottom = (event.vpos >= height - border_thickness);
|
---|
[ef20a91] | 297 | bool edge = left || right || top || bottom;
|
---|
| 298 |
|
---|
| 299 | bool cleft = (event.hpos < corner_size);
|
---|
| 300 | bool cright = (event.hpos >= width - corner_size);
|
---|
| 301 | bool ctop = (event.vpos < corner_size);
|
---|
| 302 | bool cbottom = (event.vpos >= height - corner_size);
|
---|
| 303 |
|
---|
[6d5e378] | 304 | bool header = (event.hpos >= border_thickness) &&
|
---|
| 305 | (event.hpos < width - border_thickness) &&
|
---|
| 306 | (event.vpos >= border_thickness) &&
|
---|
| 307 | (event.vpos < border_thickness + header_height);
|
---|
[296e124e] | 308 | bool close = (header) &&
|
---|
| 309 | (event.hpos >= width - border_thickness - close_thickness);
|
---|
[6d5e378] | 310 |
|
---|
[66a408f7] | 311 | bool isresize = widget->window->is_resizable;
|
---|
[ef20a91] | 312 | display_wnd_rsztype_t rsztype = 0;
|
---|
| 313 |
|
---|
| 314 | if (edge && ctop && cleft) {
|
---|
| 315 | rsztype = display_wr_top_left;
|
---|
| 316 | } else if (edge && cbottom && cleft) {
|
---|
| 317 | rsztype = display_wr_bottom_left;
|
---|
| 318 | } else if (edge && cbottom && cright) {
|
---|
| 319 | rsztype = display_wr_bottom_right;
|
---|
| 320 | } else if (edge && ctop && cright) {
|
---|
| 321 | rsztype = display_wr_top_right;
|
---|
| 322 | } else if (top) {
|
---|
| 323 | rsztype = display_wr_top;
|
---|
| 324 | } else if (left) {
|
---|
| 325 | rsztype = display_wr_left;
|
---|
| 326 | } else if (bottom) {
|
---|
| 327 | rsztype = display_wr_bottom;
|
---|
| 328 | } else if (right) {
|
---|
| 329 | rsztype = display_wr_right;
|
---|
| 330 | } else {
|
---|
| 331 | isresize = false;
|
---|
| 332 | }
|
---|
| 333 |
|
---|
| 334 | if (isresize) {
|
---|
| 335 | (void) set_cursor(widget->window,
|
---|
| 336 | display_cursor_from_wrsz(rsztype));
|
---|
| 337 | } else {
|
---|
[9242ad9] | 338 | (void) set_cursor(widget->window, dcurs_arrow);
|
---|
[ef20a91] | 339 | }
|
---|
[9242ad9] | 340 |
|
---|
[1e4a937] | 341 | pos.x = event.hpos;
|
---|
| 342 | pos.y = event.vpos;
|
---|
| 343 |
|
---|
[ef20a91] | 344 | if (isresize && btn_left) {
|
---|
| 345 | (void) display_window_resize_req(
|
---|
| 346 | widget->window->dwindow, rsztype, &pos);
|
---|
[6d5e378] | 347 | } else if (close && btn_left) {
|
---|
[338d0935] | 348 | window_close(widget->window);
|
---|
[6d5e378] | 349 | } else if (header && btn_left) {
|
---|
[a2e104e] | 350 | (void) display_window_move_req(widget->window->dwindow,
|
---|
| 351 | &pos);
|
---|
[6d5e378] | 352 | } else {
|
---|
[feeac0d] | 353 | list_foreach(widget->children, link, widget_t, child) {
|
---|
[6d5e378] | 354 | child->handle_position_event(child, event);
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 | } else {
|
---|
[feeac0d] | 358 | list_foreach(widget->children, link, widget_t, child) {
|
---|
[6d5e378] | 359 | child->handle_position_event(child, event);
|
---|
| 360 | }
|
---|
| 361 | }
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 | static void deliver_keyboard_event(window_t *win, kbd_event_t event)
|
---|
| 365 | {
|
---|
| 366 | if (win->focus) {
|
---|
| 367 | win->focus->handle_keyboard_event(win->focus, event);
|
---|
| 368 | } else {
|
---|
| 369 | win->root.handle_keyboard_event(&win->root, event);
|
---|
| 370 | }
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | static void deliver_position_event(window_t *win, pos_event_t event)
|
---|
| 374 | {
|
---|
| 375 | if (win->grab) {
|
---|
| 376 | win->grab->handle_position_event(win->grab, event);
|
---|
| 377 | } else {
|
---|
| 378 | win->root.handle_position_event(&win->root, event);
|
---|
| 379 | }
|
---|
| 380 | }
|
---|
| 381 |
|
---|
[62fbb7e] | 382 | static void handle_signal_event(window_t *win, signal_event_t event)
|
---|
[6d5e378] | 383 | {
|
---|
| 384 | widget_t *widget = (widget_t *) event.object;
|
---|
| 385 | slot_t slot = (slot_t) event.slot;
|
---|
| 386 | void *data = (void *) event.argument;
|
---|
| 387 |
|
---|
| 388 | slot(widget, data);
|
---|
| 389 |
|
---|
| 390 | free(data);
|
---|
| 391 | }
|
---|
| 392 |
|
---|
[62fbb7e] | 393 | static void handle_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y,
|
---|
| 394 | sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
|
---|
[6d5e378] | 395 | {
|
---|
[4645b2c] | 396 | gfx_bitmap_params_t params;
|
---|
| 397 | gfx_bitmap_alloc_t alloc;
|
---|
[3275736] | 398 | gfx_bitmap_t *new_bitmap = NULL;
|
---|
[0e6e77f] | 399 | gfx_coord2_t offs;
|
---|
[0680854] | 400 | gfx_coord2_t dpos;
|
---|
| 401 | display_info_t dinfo;
|
---|
| 402 | gfx_rect_t drect;
|
---|
[0e6e77f] | 403 | gfx_rect_t nrect;
|
---|
[3275736] | 404 | errno_t rc;
|
---|
[4645b2c] | 405 |
|
---|
[6d5e378] | 406 | if (width < 2 * border_thickness + header_min_width) {
|
---|
[4645b2c] | 407 | //win_damage(win->osess, 0, 0, 0, 0);
|
---|
[6d5e378] | 408 | return;
|
---|
| 409 | }
|
---|
[a35b458] | 410 |
|
---|
[6d5e378] | 411 | if (height < 2 * border_thickness + header_height) {
|
---|
[4645b2c] | 412 | //win_damage(win->osess, 0, 0, 0, 0);
|
---|
[6d5e378] | 413 | return;
|
---|
| 414 | }
|
---|
[a35b458] | 415 |
|
---|
[afcf704] | 416 | fibril_mutex_lock(&win->guard);
|
---|
| 417 |
|
---|
| 418 | /* Deallocate old bitmap. */
|
---|
| 419 | if (win->bitmap != NULL) {
|
---|
| 420 | gfx_bitmap_destroy(win->bitmap);
|
---|
| 421 | win->bitmap = NULL;
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | /* Deallocate old surface. */
|
---|
| 425 | if (win->surface != NULL) {
|
---|
| 426 | surface_destroy(win->surface);
|
---|
| 427 | win->surface = NULL;
|
---|
| 428 | }
|
---|
| 429 |
|
---|
| 430 | /* Resize the display window. */
|
---|
| 431 | offs.x = offset_x;
|
---|
| 432 | offs.y = offset_y;
|
---|
| 433 | nrect.p0.x = 0;
|
---|
| 434 | nrect.p0.y = 0;
|
---|
| 435 | nrect.p1.x = width;
|
---|
| 436 | nrect.p1.y = height;
|
---|
| 437 |
|
---|
| 438 | rc = display_window_resize(win->dwindow, &offs, &nrect);
|
---|
| 439 | if (rc != EOK)
|
---|
[6d5e378] | 440 | return;
|
---|
[a35b458] | 441 |
|
---|
[a8eed5f] | 442 | gfx_bitmap_params_init(¶ms);
|
---|
[afcf704] | 443 | #ifndef CONFIG_WIN_DOUBLE_BUF
|
---|
| 444 | params.flags = bmpf_direct_output;
|
---|
| 445 | #else
|
---|
| 446 | params.flags = 0;
|
---|
| 447 | #endif
|
---|
[4645b2c] | 448 | params.rect.p0.x = 0;
|
---|
| 449 | params.rect.p0.y = 0;
|
---|
| 450 | params.rect.p1.x = width;
|
---|
| 451 | params.rect.p1.y = height;
|
---|
| 452 |
|
---|
[afcf704] | 453 | rc = gfx_bitmap_create(win->gc, ¶ms, NULL, &new_bitmap);
|
---|
| 454 | if (rc != EOK) {
|
---|
| 455 | if (rc == ENOTSUP) {
|
---|
| 456 | /* Direct output is not supported */
|
---|
| 457 | params.flags &= ~bmpf_direct_output;
|
---|
| 458 | rc = gfx_bitmap_create(win->gc, ¶ms, NULL, &new_bitmap);
|
---|
| 459 | if (rc != EOK) {
|
---|
| 460 | fibril_mutex_unlock(&win->guard);
|
---|
| 461 | return;
|
---|
| 462 | }
|
---|
| 463 | }
|
---|
| 464 | }
|
---|
[4645b2c] | 465 |
|
---|
[afcf704] | 466 | rc = gfx_bitmap_get_alloc(new_bitmap, &alloc);
|
---|
[4645b2c] | 467 | if (rc != EOK) {
|
---|
[afcf704] | 468 | fibril_mutex_unlock(&win->guard);
|
---|
[4645b2c] | 469 | return;
|
---|
| 470 | }
|
---|
| 471 |
|
---|
[afcf704] | 472 | /* Allocate new surface. */
|
---|
[c45d8696] | 473 | surface_t *new_surface = surface_create(width, height, alloc.pixels,
|
---|
| 474 | SURFACE_FLAG_SHARED);
|
---|
[afcf704] | 475 | if (!new_surface) {
|
---|
| 476 | gfx_bitmap_destroy(new_bitmap);
|
---|
| 477 | fibril_mutex_unlock(&win->guard);
|
---|
| 478 | return;
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | /* Switch in new surface and bitmap. */
|
---|
[6d5e378] | 482 | win->surface = new_surface;
|
---|
[4645b2c] | 483 | win->bitmap = new_bitmap;
|
---|
[6d5e378] | 484 | fibril_mutex_unlock(&win->guard);
|
---|
[a35b458] | 485 |
|
---|
[62fbb7e] | 486 | /*
|
---|
| 487 | * Let all widgets in the tree alter their position and size.
|
---|
| 488 | * Widgets might also paint themselves onto the new surface.
|
---|
| 489 | */
|
---|
[6d5e378] | 490 | win->root.rearrange(&win->root, 0, 0, width, height);
|
---|
[a35b458] | 491 |
|
---|
[6d5e378] | 492 | fibril_mutex_lock(&win->guard);
|
---|
| 493 | surface_reset_damaged_region(win->surface);
|
---|
| 494 | fibril_mutex_unlock(&win->guard);
|
---|
[a35b458] | 495 |
|
---|
[0680854] | 496 | if (placement_flags != WINDOW_PLACEMENT_ANY) {
|
---|
| 497 | dpos.x = 0;
|
---|
| 498 | dpos.y = 0;
|
---|
[4645b2c] | 499 |
|
---|
[0680854] | 500 | rc = display_get_info(win->display, &dinfo);
|
---|
| 501 | if (rc != EOK) {
|
---|
| 502 | (void) gfx_bitmap_render(win->bitmap, NULL, NULL);
|
---|
| 503 | return;
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | drect = dinfo.rect;
|
---|
| 507 |
|
---|
| 508 | if (placement_flags & WINDOW_PLACEMENT_LEFT)
|
---|
| 509 | dpos.x = drect.p0.x;
|
---|
| 510 | else if (placement_flags & WINDOW_PLACEMENT_CENTER_X)
|
---|
[3e640e5] | 511 | dpos.x = (drect.p0.x + drect.p1.x - width) / 2;
|
---|
[0680854] | 512 | else
|
---|
| 513 | dpos.x = drect.p1.x - width;
|
---|
| 514 |
|
---|
| 515 | if (placement_flags & WINDOW_PLACEMENT_TOP)
|
---|
| 516 | dpos.y = drect.p0.y;
|
---|
| 517 | else if (placement_flags & WINDOW_PLACEMENT_CENTER_Y)
|
---|
| 518 | dpos.y = (drect.p0.y + drect.p1.y - height) / 2;
|
---|
| 519 | else
|
---|
| 520 | dpos.y = drect.p1.y - height;
|
---|
| 521 |
|
---|
| 522 | (void) display_window_move(win->dwindow, &dpos);
|
---|
[6d5e378] | 523 | }
|
---|
[0680854] | 524 |
|
---|
| 525 | (void) gfx_bitmap_render(win->bitmap, NULL, NULL);
|
---|
[6d5e378] | 526 | }
|
---|
| 527 |
|
---|
| 528 | static void handle_refresh(window_t *win)
|
---|
| 529 | {
|
---|
| 530 | win->root.repaint(&win->root);
|
---|
| 531 | }
|
---|
| 532 |
|
---|
| 533 | static void handle_damage(window_t *win)
|
---|
| 534 | {
|
---|
| 535 | sysarg_t x, y, width, height;
|
---|
[4645b2c] | 536 | gfx_rect_t rect;
|
---|
[6d5e378] | 537 | fibril_mutex_lock(&win->guard);
|
---|
| 538 | surface_get_damaged_region(win->surface, &x, &y, &width, &height);
|
---|
| 539 | surface_reset_damaged_region(win->surface);
|
---|
| 540 | fibril_mutex_unlock(&win->guard);
|
---|
| 541 |
|
---|
| 542 | if (width > 0 && height > 0) {
|
---|
[4645b2c] | 543 | rect.p0.x = x;
|
---|
| 544 | rect.p0.y = y;
|
---|
| 545 | rect.p1.x = x + width;
|
---|
| 546 | rect.p1.y = y + height;
|
---|
| 547 |
|
---|
[3275736] | 548 | if (win->bitmap != NULL)
|
---|
| 549 | (void) gfx_bitmap_render(win->bitmap, &rect, NULL);
|
---|
[6d5e378] | 550 | }
|
---|
| 551 | }
|
---|
| 552 |
|
---|
| 553 | static void destroy_children(widget_t *widget)
|
---|
| 554 | {
|
---|
| 555 | /* Recursively destroy widget tree in bottom-top order. */
|
---|
| 556 | while (!list_empty(&widget->children)) {
|
---|
| 557 | widget_t *child =
|
---|
| 558 | list_get_instance(list_first(&widget->children), widget_t, link);
|
---|
| 559 | destroy_children(child);
|
---|
| 560 | child->destroy(child);
|
---|
| 561 | }
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | static void handle_close(window_t *win)
|
---|
| 565 | {
|
---|
| 566 | destroy_children(&win->root);
|
---|
| 567 | win->root.destroy(&win->root);
|
---|
| 568 | win->grab = NULL;
|
---|
| 569 | win->focus = NULL;
|
---|
| 570 |
|
---|
[94f3747] | 571 | gfx_bitmap_destroy(win->bitmap);
|
---|
| 572 |
|
---|
| 573 | /*
|
---|
| 574 | * XXX Here we should properly destroy the IPC GC. We only have
|
---|
| 575 | * the generic GC so either it would need to be cast back or
|
---|
| 576 | * GC needs a virtual destructor.
|
---|
| 577 | */
|
---|
| 578 |
|
---|
[4645b2c] | 579 | display_window_destroy(win->dwindow);
|
---|
| 580 | display_close(win->display);
|
---|
[6d5e378] | 581 |
|
---|
| 582 | while (!list_empty(&win->events.list)) {
|
---|
[21eeb653] | 583 | window_event_t *event = (window_event_t *) list_first(&win->events.list);
|
---|
| 584 | list_remove(&event->link);
|
---|
| 585 | free(event);
|
---|
[6d5e378] | 586 | }
|
---|
| 587 |
|
---|
| 588 | if (win->surface) {
|
---|
| 589 | surface_destroy(win->surface);
|
---|
| 590 | }
|
---|
| 591 |
|
---|
| 592 | free(win->caption);
|
---|
| 593 |
|
---|
| 594 | free(win);
|
---|
| 595 | }
|
---|
| 596 |
|
---|
| 597 | /* Window event loop. Runs in own dedicated fibril. */
|
---|
[b7fd2a0] | 598 | static errno_t event_loop(void *arg)
|
---|
[6d5e378] | 599 | {
|
---|
| 600 | bool is_main = false;
|
---|
| 601 | bool terminate = false;
|
---|
| 602 | window_t *win = (window_t *) arg;
|
---|
| 603 |
|
---|
| 604 | while (true) {
|
---|
| 605 | window_event_t *event = (window_event_t *) prodcons_consume(&win->events);
|
---|
| 606 |
|
---|
| 607 | switch (event->type) {
|
---|
| 608 | case ET_KEYBOARD_EVENT:
|
---|
| 609 | deliver_keyboard_event(win, event->data.kbd);
|
---|
| 610 | break;
|
---|
| 611 | case ET_POSITION_EVENT:
|
---|
| 612 | deliver_position_event(win, event->data.pos);
|
---|
| 613 | break;
|
---|
| 614 | case ET_SIGNAL_EVENT:
|
---|
[62fbb7e] | 615 | handle_signal_event(win, event->data.signal);
|
---|
[6d5e378] | 616 | break;
|
---|
| 617 | case ET_WINDOW_RESIZE:
|
---|
[62fbb7e] | 618 | handle_resize(win, event->data.resize.offset_x,
|
---|
| 619 | event->data.resize.offset_y, event->data.resize.width,
|
---|
| 620 | event->data.resize.height, event->data.resize.placement_flags);
|
---|
[6d5e378] | 621 | break;
|
---|
[290a0f0] | 622 | case ET_WINDOW_FOCUS:
|
---|
| 623 | if (!win->is_focused) {
|
---|
| 624 | win->is_focused = true;
|
---|
| 625 | handle_refresh(win);
|
---|
| 626 | }
|
---|
| 627 | break;
|
---|
| 628 | case ET_WINDOW_UNFOCUS:
|
---|
| 629 | if (win->is_focused) {
|
---|
| 630 | win->is_focused = false;
|
---|
| 631 | handle_refresh(win);
|
---|
| 632 | }
|
---|
| 633 | break;
|
---|
[6d5e378] | 634 | case ET_WINDOW_REFRESH:
|
---|
| 635 | handle_refresh(win);
|
---|
| 636 | break;
|
---|
| 637 | case ET_WINDOW_DAMAGE:
|
---|
| 638 | handle_damage(win);
|
---|
| 639 | break;
|
---|
| 640 | case ET_WINDOW_CLOSE:
|
---|
| 641 | is_main = win->is_main;
|
---|
| 642 | handle_close(win);
|
---|
| 643 | terminate = true;
|
---|
| 644 | break;
|
---|
| 645 | default:
|
---|
| 646 | break;
|
---|
| 647 | }
|
---|
| 648 |
|
---|
| 649 | free(event);
|
---|
| 650 | if (terminate) {
|
---|
| 651 | break;
|
---|
| 652 | }
|
---|
| 653 | }
|
---|
| 654 |
|
---|
| 655 | if (is_main) {
|
---|
| 656 | exit(0); /* Terminate whole task. */
|
---|
| 657 | }
|
---|
| 658 | return 0;
|
---|
| 659 | }
|
---|
| 660 |
|
---|
[10cb47e] | 661 | window_t *window_open(const char *winreg, const void *data,
|
---|
| 662 | window_flags_t flags, const char *caption)
|
---|
[6d5e378] | 663 | {
|
---|
[0e6e77f] | 664 | display_wnd_params_t wparams;
|
---|
| 665 |
|
---|
[3275736] | 666 | window_t *win = (window_t *) calloc(1, sizeof(window_t));
|
---|
[ba02baa] | 667 | if (!win)
|
---|
[6d5e378] | 668 | return NULL;
|
---|
[a35b458] | 669 |
|
---|
[2c7fdaa] | 670 | win->is_main = flags & WINDOW_MAIN;
|
---|
| 671 | win->is_decorated = flags & WINDOW_DECORATED;
|
---|
[66a408f7] | 672 | win->is_resizable = flags & WINDOW_RESIZEABLE;
|
---|
[290a0f0] | 673 | win->is_focused = true;
|
---|
[6d5e378] | 674 | prodcons_initialize(&win->events);
|
---|
| 675 | fibril_mutex_initialize(&win->guard);
|
---|
[a35b458] | 676 |
|
---|
[10cb47e] | 677 | widget_init(&win->root, NULL, data);
|
---|
[6d5e378] | 678 | win->root.window = win;
|
---|
| 679 | win->root.destroy = root_destroy;
|
---|
| 680 | win->root.reconfigure = root_reconfigure;
|
---|
| 681 | win->root.rearrange = root_rearrange;
|
---|
| 682 | win->root.repaint = root_repaint;
|
---|
| 683 | win->root.handle_keyboard_event = root_handle_keyboard_event;
|
---|
| 684 | win->root.handle_position_event = root_handle_position_event;
|
---|
| 685 | win->grab = NULL;
|
---|
| 686 | win->focus = NULL;
|
---|
[9242ad9] | 687 | win->cursor = dcurs_arrow;
|
---|
[0e6e77f] | 688 |
|
---|
| 689 | /* Allocate resources for new surface. */
|
---|
| 690 | win->surface = surface_create(100, 100, NULL, SURFACE_FLAG_SHARED);
|
---|
| 691 | if (win->surface == NULL) {
|
---|
| 692 | free(win);
|
---|
| 693 | return NULL;
|
---|
| 694 | }
|
---|
[a35b458] | 695 |
|
---|
[4645b2c] | 696 | errno_t rc = display_open(winreg, &win->display);
|
---|
[6d5e378] | 697 | if (rc != EOK) {
|
---|
[0e6e77f] | 698 | surface_destroy(win->surface);
|
---|
| 699 | free(win);
|
---|
| 700 | return NULL;
|
---|
| 701 | }
|
---|
| 702 |
|
---|
| 703 | /* Window dimensions are not know at this time */
|
---|
| 704 | display_wnd_params_init(&wparams);
|
---|
| 705 | wparams.rect.p0.x = 0;
|
---|
| 706 | wparams.rect.p0.y = 0;
|
---|
| 707 | wparams.rect.p1.x = 100;
|
---|
| 708 | wparams.rect.p1.y = 100;
|
---|
[9b502dd] | 709 | wparams.min_size.x = 2 * border_thickness + header_min_width;
|
---|
| 710 | wparams.min_size.y = 2 * border_thickness + header_height;
|
---|
[0e6e77f] | 711 |
|
---|
| 712 | rc = display_window_create(win->display, &wparams, &window_cb,
|
---|
| 713 | (void *) win, &win->dwindow);
|
---|
| 714 | if (rc != EOK) {
|
---|
| 715 | display_close(win->display);
|
---|
| 716 | surface_destroy(win->surface);
|
---|
| 717 | free(win);
|
---|
| 718 | return NULL;
|
---|
| 719 | }
|
---|
| 720 |
|
---|
| 721 | rc = display_window_get_gc(win->dwindow, &win->gc);
|
---|
| 722 | if (rc != EOK) {
|
---|
| 723 | display_window_destroy(win->dwindow);
|
---|
| 724 | display_close(win->display);
|
---|
| 725 | surface_destroy(win->surface);
|
---|
[6d5e378] | 726 | free(win);
|
---|
| 727 | return NULL;
|
---|
| 728 | }
|
---|
[a35b458] | 729 |
|
---|
[ba02baa] | 730 | if (caption == NULL)
|
---|
[6d5e378] | 731 | win->caption = NULL;
|
---|
[ba02baa] | 732 | else
|
---|
[6d5e378] | 733 | win->caption = str_dup(caption);
|
---|
[a35b458] | 734 |
|
---|
[6d5e378] | 735 | return win;
|
---|
| 736 | }
|
---|
| 737 |
|
---|
[62fbb7e] | 738 | void window_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y,
|
---|
| 739 | sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
|
---|
[6d5e378] | 740 | {
|
---|
| 741 | window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
| 742 | if (event) {
|
---|
| 743 | link_initialize(&event->link);
|
---|
| 744 | event->type = ET_WINDOW_RESIZE;
|
---|
[62fbb7e] | 745 | event->data.resize.offset_x = offset_x;
|
---|
| 746 | event->data.resize.offset_y = offset_y;
|
---|
| 747 | event->data.resize.width = width;
|
---|
| 748 | event->data.resize.height = height;
|
---|
| 749 | event->data.resize.placement_flags = placement_flags;
|
---|
[6d5e378] | 750 | prodcons_produce(&win->events, &event->link);
|
---|
| 751 | }
|
---|
| 752 | }
|
---|
| 753 |
|
---|
[b7fd2a0] | 754 | errno_t window_set_caption(window_t *win, const char *caption)
|
---|
[78188e5] | 755 | {
|
---|
| 756 | char *cap;
|
---|
[a35b458] | 757 |
|
---|
[78188e5] | 758 | if (caption == NULL) {
|
---|
| 759 | win->caption = NULL;
|
---|
| 760 | } else {
|
---|
| 761 | cap = str_dup(caption);
|
---|
| 762 | if (cap == NULL)
|
---|
| 763 | return ENOMEM;
|
---|
| 764 | free(win->caption);
|
---|
| 765 | win->caption = cap;
|
---|
| 766 | }
|
---|
[a35b458] | 767 |
|
---|
[78188e5] | 768 | win->is_focused = false;
|
---|
| 769 | handle_refresh(win);
|
---|
[a35b458] | 770 |
|
---|
[78188e5] | 771 | return EOK;
|
---|
| 772 | }
|
---|
| 773 |
|
---|
[6d5e378] | 774 | void window_refresh(window_t *win)
|
---|
| 775 | {
|
---|
| 776 | window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
| 777 | if (event) {
|
---|
| 778 | link_initialize(&event->link);
|
---|
| 779 | event->type = ET_WINDOW_REFRESH;
|
---|
| 780 | prodcons_produce(&win->events, &event->link);
|
---|
| 781 | }
|
---|
| 782 | }
|
---|
| 783 |
|
---|
| 784 | void window_damage(window_t *win)
|
---|
| 785 | {
|
---|
| 786 | window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
|
---|
| 787 | if (event) {
|
---|
| 788 | link_initialize(&event->link);
|
---|
| 789 | event->type = ET_WINDOW_DAMAGE;
|
---|
| 790 | prodcons_produce(&win->events, &event->link);
|
---|
| 791 | }
|
---|
| 792 | }
|
---|
| 793 |
|
---|
| 794 | widget_t *window_root(window_t *win)
|
---|
| 795 | {
|
---|
| 796 | return &win->root;
|
---|
| 797 | }
|
---|
| 798 |
|
---|
| 799 | void window_exec(window_t *win)
|
---|
| 800 | {
|
---|
| 801 | fid_t ev_fid = fibril_create(event_loop, win);
|
---|
[b43edabe] | 802 | if (!ev_fid) {
|
---|
[6d5e378] | 803 | return;
|
---|
| 804 | }
|
---|
| 805 | fibril_add_ready(ev_fid);
|
---|
| 806 | }
|
---|
| 807 |
|
---|
| 808 | surface_t *window_claim(window_t *win)
|
---|
| 809 | {
|
---|
| 810 | fibril_mutex_lock(&win->guard);
|
---|
| 811 | return win->surface;
|
---|
| 812 | }
|
---|
| 813 |
|
---|
| 814 | void window_yield(window_t *win)
|
---|
| 815 | {
|
---|
| 816 | fibril_mutex_unlock(&win->guard);
|
---|
| 817 | }
|
---|
| 818 |
|
---|
| 819 | void window_close(window_t *win)
|
---|
| 820 | {
|
---|
[338d0935] | 821 | window_event_t *event;
|
---|
| 822 |
|
---|
| 823 | event = (window_event_t *) calloc(1, sizeof(window_event_t));
|
---|
| 824 | if (event == NULL)
|
---|
| 825 | return;
|
---|
| 826 |
|
---|
| 827 | link_initialize(&event->link);
|
---|
| 828 | event->type = ET_WINDOW_CLOSE;
|
---|
| 829 | prodcons_produce(&win->events, &event->link);
|
---|
| 830 | }
|
---|
| 831 |
|
---|
| 832 | static void window_close_event(void *arg)
|
---|
| 833 | {
|
---|
| 834 | window_t *win = (window_t *) arg;
|
---|
| 835 |
|
---|
| 836 | window_close(win);
|
---|
[6d5e378] | 837 | }
|
---|
| 838 |
|
---|
[b0a94854] | 839 | static void window_focus_event(void *arg)
|
---|
| 840 | {
|
---|
| 841 | window_t *win = (window_t *) arg;
|
---|
| 842 | window_event_t *event;
|
---|
| 843 |
|
---|
| 844 | event = (window_event_t *) calloc(1, sizeof(window_event_t));
|
---|
| 845 | if (event == NULL)
|
---|
| 846 | return;
|
---|
| 847 |
|
---|
| 848 | link_initialize(&event->link);
|
---|
| 849 | event->type = ET_WINDOW_FOCUS;
|
---|
| 850 | prodcons_produce(&win->events, &event->link);
|
---|
| 851 | }
|
---|
| 852 |
|
---|
[287688f2] | 853 | static void window_kbd_event(void *arg, kbd_event_t *kevent)
|
---|
| 854 | {
|
---|
| 855 | window_t *win = (window_t *) arg;
|
---|
| 856 | window_event_t *event;
|
---|
| 857 |
|
---|
| 858 | event = (window_event_t *) calloc(1, sizeof(window_event_t));
|
---|
| 859 | if (event == NULL)
|
---|
| 860 | return;
|
---|
| 861 |
|
---|
| 862 | link_initialize(&event->link);
|
---|
| 863 | event->type = ET_KEYBOARD_EVENT;
|
---|
| 864 | event->data.kbd = *kevent;
|
---|
| 865 | prodcons_produce(&win->events, &event->link);
|
---|
| 866 | }
|
---|
| 867 |
|
---|
[f7fb2b21] | 868 | static void window_pos_event(void *arg, pos_event_t *pevent)
|
---|
| 869 | {
|
---|
| 870 | window_t *win = (window_t *) arg;
|
---|
| 871 | window_event_t *event;
|
---|
| 872 |
|
---|
| 873 | event = (window_event_t *) calloc(1, sizeof(window_event_t));
|
---|
| 874 | if (event == NULL)
|
---|
| 875 | return;
|
---|
| 876 |
|
---|
| 877 | link_initialize(&event->link);
|
---|
| 878 | event->type = ET_POSITION_EVENT;
|
---|
| 879 | event->data.pos = *pevent;
|
---|
| 880 | prodcons_produce(&win->events, &event->link);
|
---|
| 881 | }
|
---|
| 882 |
|
---|
[e022819] | 883 | static void window_resize_event(void *arg, gfx_rect_t *nrect)
|
---|
| 884 | {
|
---|
| 885 | window_t *win = (window_t *) arg;
|
---|
| 886 | window_event_t *event;
|
---|
| 887 |
|
---|
[66a408f7] | 888 | if (!win->is_resizable)
|
---|
| 889 | return;
|
---|
| 890 |
|
---|
[e022819] | 891 | event = (window_event_t *) calloc(1, sizeof(window_event_t));
|
---|
| 892 | if (event == NULL)
|
---|
| 893 | return;
|
---|
| 894 |
|
---|
| 895 | link_initialize(&event->link);
|
---|
| 896 | event->type = ET_WINDOW_RESIZE;
|
---|
| 897 | event->data.resize.offset_x = nrect->p0.x;
|
---|
| 898 | event->data.resize.offset_y = nrect->p0.y;
|
---|
| 899 | event->data.resize.width = nrect->p1.x - nrect->p0.x;
|
---|
| 900 | event->data.resize.height = nrect->p1.y - nrect->p0.y;
|
---|
| 901 | event->data.resize.placement_flags = WINDOW_PLACEMENT_ANY;
|
---|
| 902 | prodcons_produce(&win->events, &event->link);
|
---|
| 903 | }
|
---|
| 904 |
|
---|
[b0a94854] | 905 | static void window_unfocus_event(void *arg)
|
---|
| 906 | {
|
---|
| 907 | window_t *win = (window_t *) arg;
|
---|
| 908 | window_event_t *event;
|
---|
| 909 |
|
---|
| 910 | event = (window_event_t *) calloc(1, sizeof(window_event_t));
|
---|
| 911 | if (event == NULL)
|
---|
| 912 | return;
|
---|
| 913 |
|
---|
| 914 | link_initialize(&event->link);
|
---|
| 915 | event->type = ET_WINDOW_UNFOCUS;
|
---|
| 916 | prodcons_produce(&win->events, &event->link);
|
---|
| 917 | }
|
---|
| 918 |
|
---|
[6d5e378] | 919 | /** @}
|
---|
| 920 | */
|
---|