diff options
author | Kristian Høgsberg <krh@bitplanet.net> | 2012-01-10 19:11:42 -0500 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2012-01-10 19:11:42 -0500 |
commit | bb97700474968d3a0d1869cb777b092b6d46637b (patch) | |
tree | c8fd8fe1c8559bfbdbe6d86dfb121df1a7e6a2bd | |
parent | 27ff086b8edb6387c8710013a41ce631babc3e1a (diff) |
window: Get rid of the window child allocation concept
-rw-r--r-- | clients/desktop-shell.c | 6 | ||||
-rw-r--r-- | clients/dnd.c | 11 | ||||
-rw-r--r-- | clients/eventdemo.c | 10 | ||||
-rw-r--r-- | clients/gears.c | 8 | ||||
-rw-r--r-- | clients/image.c | 6 | ||||
-rw-r--r-- | clients/resizor.c | 33 | ||||
-rw-r--r-- | clients/tablet-shell.c | 4 | ||||
-rw-r--r-- | clients/terminal.c | 83 | ||||
-rw-r--r-- | clients/view.c | 5 | ||||
-rw-r--r-- | clients/window.c | 107 | ||||
-rw-r--r-- | clients/window.h | 21 | ||||
-rw-r--r-- | clients/wscreensaver.c | 4 |
12 files changed, 147 insertions, 151 deletions
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c index 49aa013..09fc1c9 100644 --- a/clients/desktop-shell.c +++ b/clients/desktop-shell.c @@ -393,9 +393,7 @@ background_configure(void *data, struct background *background = (struct background *) window_get_user_data(window); - window_set_child_size(background->window, width, height); - widget_set_allocation(background->widget, 0, 0, width, height); - window_schedule_redraw(background->window); + widget_schedule_resize(background->widget, width, height); } static void @@ -410,7 +408,7 @@ unlock_dialog_redraw_handler(struct widget *widget, void *data) surface = window_get_surface(dialog->window); cr = cairo_create(surface); - window_get_child_allocation(dialog->window, &allocation); + widget_get_allocation(dialog->widget, &allocation); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); diff --git a/clients/dnd.c b/clients/dnd.c index 0498c5d..27b11c0 100644 --- a/clients/dnd.c +++ b/clients/dnd.c @@ -170,7 +170,7 @@ dnd_redraw_handler(struct widget *widget, void *data) surface = window_get_surface(dnd->window); cr = cairo_create(surface); - window_get_child_allocation(dnd->window, &allocation); + widget_get_allocation(dnd->widget, &allocation); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); @@ -222,7 +222,7 @@ dnd_get_item(struct dnd *dnd, int32_t x, int32_t y) struct rectangle allocation; int i; - window_get_child_allocation(dnd->window, &allocation); + widget_get_allocation(dnd->widget, &allocation); x -= allocation.x; y -= allocation.y; @@ -363,7 +363,7 @@ dnd_button_handler(struct widget *widget, struct dnd_drag *dnd_drag; int i; - window_get_child_allocation(dnd->window, &allocation); + widget_get_allocation(dnd->widget, &allocation); input_get_position(input, &x, &y); item = dnd_get_item(dnd, x, y); x -= allocation.x; @@ -468,7 +468,7 @@ dnd_receive_func(void *data, size_t len, int32_t x, int32_t y, void *user_data) return; } - window_get_child_allocation(dnd->window, &allocation); + widget_get_allocation(dnd->widget, &allocation); item = item_create(dnd->display, x - message->x_offset - allocation.x, y - message->y_offset - allocation.y, @@ -535,9 +535,8 @@ dnd_create(struct display *display) width = 4 * (item_width + item_padding) + item_padding; height = 4 * (item_height + item_padding) + item_padding; - window_set_child_size(dnd->window, width, height); - window_schedule_redraw(dnd->window); + widget_schedule_resize(dnd->widget, width, height); return dnd; } diff --git a/clients/eventdemo.c b/clients/eventdemo.c index 5f70bc1..b8cb344 100644 --- a/clients/eventdemo.c +++ b/clients/eventdemo.c @@ -107,7 +107,7 @@ redraw_handler(struct widget *widget, void *data) if (log_redraw) printf("redraw\n"); - window_get_child_allocation(e->window, &rect); + widget_get_allocation(e->widget, &rect); surface = window_get_surface(e->window); cr = cairo_create(surface); @@ -150,7 +150,7 @@ resize_handler(struct widget *widget, height = height_max; /* set the new window dimensions */ - window_set_child_size(e->window, width, height); + widget_set_size(e->widget, width, height); } /** @@ -266,12 +266,6 @@ eventdemo_create(struct display *d) if(e == NULL) return NULL; - /* Creates a new window with the given title, width and height. - * To set the size of the window for a given usable areas width - * and height in a window decoration agnostic way use: - * window_set_child_size(struct window *window, - * int32_t width, int32_t height); - */ e->window = window_create(d, width, height); e->widget = window_add_widget(e->window, e); window_set_title(e->window, title); diff --git a/clients/gears.c b/clients/gears.c index 5dfb47a..e94152d 100644 --- a/clients/gears.c +++ b/clients/gears.c @@ -221,7 +221,7 @@ redraw_handler(struct widget *widget, void *data) struct wl_callback *callback; struct gears *gears = data; - window_get_child_allocation(gears->window, &allocation); + widget_get_allocation(gears->widget, &allocation); window_get_allocation(gears->window, &window_allocation); if (display_acquire_window_surface(gears->d, @@ -232,7 +232,7 @@ redraw_handler(struct widget *widget, void *data) } glViewport(allocation.x, - window_allocation.height - allocation.height - allocation.x, + window_allocation.height - allocation.height - allocation.y, allocation.width, allocation.height); glScissor(allocation.x, window_allocation.height - allocation.height - allocation.y, @@ -293,7 +293,7 @@ resize_handler(struct widget *widget, height = 300; } - window_set_child_size(gears->window, width, height); + widget_set_size(gears->widget, width, height); } static void @@ -361,7 +361,7 @@ gears_create(struct display *display) window_set_keyboard_focus_handler(gears->window, keyboard_focus_handler); - frame_callback(gears, NULL, 0); + window_schedule_resize(gears->window, width, height); return gears; } diff --git a/clients/image.c b/clients/image.c index 517bb47..71dd897 100644 --- a/clients/image.c +++ b/clients/image.c @@ -142,7 +142,7 @@ redraw_handler(struct widget *widget, void *data) cairo_t *cr; cairo_surface_t *surface; - window_get_child_allocation(image->window, &allocation); + widget_get_allocation(image->widget, &allocation); pb = gdk_pixbuf_new_from_file_at_size(image->filename, allocation.width, @@ -153,7 +153,7 @@ redraw_handler(struct widget *widget, void *data) surface = window_get_surface(image->window); cr = cairo_create(surface); - window_get_child_allocation(image->window, &allocation); + widget_get_allocation(image->widget, &allocation); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); @@ -215,7 +215,7 @@ image_create(struct display *display, const char *filename) window_set_keyboard_focus_handler(image->window, keyboard_focus_handler); - window_schedule_redraw(image->window); + widget_schedule_resize(image->widget, 500, 400); return image; } diff --git a/clients/resizor.c b/clients/resizor.c index 945f2ae..7699bed 100644 --- a/clients/resizor.c +++ b/clients/resizor.c @@ -53,9 +53,6 @@ struct resizor { static void frame_callback(void *data, struct wl_callback *callback, uint32_t time) { - static const struct wl_callback_listener listener = { - frame_callback - }; struct resizor *resizor = data; double force, height; @@ -79,24 +76,18 @@ frame_callback(void *data, struct wl_callback *callback, uint32_t time) resizor->height.previous = 200; } - window_set_child_size(resizor->window, resizor->width, height + 0.5); - - window_schedule_redraw(resizor->window); + widget_schedule_resize(resizor->widget, resizor->width, height + 0.5); if (resizor->frame_callback) { wl_callback_destroy(resizor->frame_callback); resizor->frame_callback = NULL; } - - if (fabs(resizor->height.previous - resizor->height.target) > 0.1) { - resizor->frame_callback = - wl_surface_frame( - window_get_wl_surface(resizor->window)); - wl_callback_add_listener(resizor->frame_callback, &listener, - resizor); - } } +static const struct wl_callback_listener listener = { + frame_callback +}; + static void redraw_handler(struct widget *widget, void *data) { @@ -105,7 +96,7 @@ redraw_handler(struct widget *widget, void *data) cairo_t *cr; struct rectangle allocation; - window_get_child_allocation(resizor->window, &allocation); + widget_get_allocation(resizor->widget, &allocation); surface = window_get_surface(resizor->window); @@ -121,6 +112,15 @@ redraw_handler(struct widget *widget, void *data) cairo_destroy(cr); cairo_surface_destroy(surface); + + if (fabs(resizor->height.previous - resizor->height.target) > 0.1) { + resizor->frame_callback = + wl_surface_frame( + window_get_wl_surface(resizor->window)); + wl_callback_add_listener(resizor->frame_callback, &listener, + resizor); + } + } static void @@ -222,10 +222,9 @@ resizor_create(struct display *display) resizor->height.target = resizor->height.current; height = resizor->height.current + 0.5; - window_set_child_size(resizor->window, resizor->width, height); widget_set_button_handler(resizor->widget, button_handler); - window_schedule_redraw(resizor->window); + widget_schedule_resize(resizor->widget, resizor->width, height); return resizor; } diff --git a/clients/tablet-shell.c b/clients/tablet-shell.c index 2331e68..1f73ba1 100644 --- a/clients/tablet-shell.c +++ b/clients/tablet-shell.c @@ -122,7 +122,7 @@ homescreen_draw(struct tablet_shell *shell) int x, y, i, width, height, vmargin, hmargin, vpadding, hpadding; window_create_surface(shell->homescreen); - window_get_child_allocation(shell->homescreen, &allocation); + window_get_allocation(shell->homescreen, &allocation); surface = window_get_surface(shell->homescreen); cr = cairo_create(surface); @@ -176,7 +176,7 @@ lockscreen_draw(struct tablet_shell *shell) int width, height; window_create_surface(shell->lockscreen); - window_get_child_allocation(shell->lockscreen, &allocation); + window_get_allocation(shell->lockscreen, &allocation); surface = window_get_surface(shell->lockscreen); cr = cairo_create(surface); diff --git a/clients/terminal.c b/clients/terminal.c index b6e3139..06a7a1f 100644 --- a/clients/terminal.c +++ b/clients/terminal.c @@ -499,7 +499,7 @@ terminal_compare_position(struct terminal *terminal, struct rectangle allocation; int top_margin, side_margin, col, row, ref_x; - window_get_child_allocation(terminal->window, &allocation); + widget_get_allocation(terminal->widget, &allocation); side_margin = allocation.x + (allocation.width - terminal->width * terminal->extents.max_x_advance) / 2; top_margin = allocation.y + (allocation.height - terminal->height * terminal->extents.height) / 2; @@ -694,7 +694,7 @@ terminal_shift_line(struct terminal *terminal, int d) } static void -terminal_resize(struct terminal *terminal, int width, int height) +terminal_resize_cells(struct terminal *terminal, int width, int height) { size_t size; union utf8_char *data; @@ -704,7 +704,6 @@ terminal_resize(struct terminal *terminal, int width, int height) int i, l, total_rows; struct rectangle allocation; struct winsize ws; - int32_t pixel_width, pixel_height; if (width < 1) width = 1; @@ -713,15 +712,6 @@ terminal_resize(struct terminal *terminal, int width, int height) if (terminal->width == width && terminal->height == height) return; - if (!terminal->fullscreen) { - pixel_width = width * - terminal->extents.max_x_advance + 2 * terminal->margin; - pixel_height = height * - terminal->extents.height + 2 * terminal->margin; - window_set_child_size(terminal->window, - pixel_width, pixel_height); - } - data_pitch = width * sizeof(union utf8_char); size = data_pitch * height; data = malloc(size); @@ -771,12 +761,46 @@ terminal_resize(struct terminal *terminal, int width, int height) /* Update the window size */ ws.ws_row = terminal->height; ws.ws_col = terminal->width; - window_get_child_allocation(terminal->window, &allocation); + widget_get_allocation(terminal->widget, &allocation); ws.ws_xpixel = allocation.width; ws.ws_ypixel = allocation.height; ioctl(terminal->master, TIOCSWINSZ, &ws); } +static void +resize_handler(struct widget *widget, + int32_t width, int32_t height, void *data) +{ + struct terminal *terminal = data; + int32_t columns, rows, m; + + m = 2 * terminal->margin; + columns = (width - m) / (int32_t) terminal->extents.max_x_advance; + rows = (height - m) / (int32_t) terminal->extents.height; + + if (!terminal->fullscreen) { + width = columns * terminal->extents.max_x_advance + m; + height = rows * terminal->extents.height + m; + widget_set_size(terminal->widget, width, height); + } + + terminal_resize_cells(terminal, columns, rows); +} + +static void +terminal_resize(struct terminal *terminal, int columns, int rows) +{ + int32_t width, height, m; + + if (terminal->fullscreen) + return; + + m = 2 * terminal->margin; + width = columns * terminal->extents.max_x_advance + m; + height = rows * terminal->extents.height + m; + widget_schedule_resize(terminal->widget, width, height); +} + struct color_scheme DEFAULT_COLORS = { { {0, 0, 0, 1}, /* black */ @@ -915,7 +939,7 @@ redraw_handler(struct widget *widget, void *data) cairo_font_extents_t extents; surface = window_get_surface(terminal->window); - window_get_child_allocation(terminal->window, &allocation); + widget_get_allocation(terminal->widget, &allocation); cr = cairo_create(surface); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); @@ -1011,25 +1035,6 @@ terminal_write(struct terminal *terminal, const char *data, size_t length) } static void -resize_handler(struct widget *widget, - int32_t pixel_width, int32_t pixel_height, void *data) -{ - struct terminal *terminal = data; - int32_t width, height; - - width = (pixel_width - 2 * terminal->margin) / - (int32_t) terminal->extents.max_x_advance; - height = (pixel_height - 2 * terminal->margin) / - (int32_t) terminal->extents.height; - - if (terminal->fullscreen) - window_set_child_size(terminal->window, - pixel_width, pixel_height); - - terminal_resize(terminal, width, height); -} - -static void terminal_data(struct terminal *terminal, const char *data, size_t length); static void @@ -1488,10 +1493,8 @@ handle_escape(struct terminal *terminal) switch (args[0]) { case 4: /* resize px */ if (set[1] && set[2]) { - window_set_child_size(terminal->window, - args[2], args[1]); - resize_handler(terminal->widget, - args[2], args[1], terminal); + widget_schedule_resize(terminal->widget, + args[2], args[1]); } break; case 8: /* resize ch */ @@ -1500,13 +1503,13 @@ handle_escape(struct terminal *terminal) } break; case 13: /* report position */ - window_get_child_allocation(terminal->window, &allocation); + widget_get_allocation(terminal->widget, &allocation); snprintf(response, MAX_RESPONSE, "\e[3;%d;%dt", allocation.x, allocation.y); terminal_write(terminal, response, strlen(response)); break; case 14: /* report px */ - window_get_child_allocation(terminal->window, &allocation); + widget_get_allocation(terminal->widget, &allocation); snprintf(response, MAX_RESPONSE, "\e[4;%d;%dt", allocation.height, allocation.width); terminal_write(terminal, response, strlen(response)); @@ -2354,8 +2357,6 @@ terminal_run(struct terminal *terminal, const char *path) if (!terminal->fullscreen) terminal_resize(terminal, 80, 24); - window_schedule_redraw(terminal->window); - return 0; } diff --git a/clients/view.c b/clients/view.c index 6c12f97..fd8b056 100644 --- a/clients/view.c +++ b/clients/view.c @@ -66,7 +66,7 @@ view_draw(struct view *view) window_draw(view->window); - window_get_child_allocation(view->window, &allocation); + widget_get_allocation(view->widget, &allocation); surface = window_get_surface(view->window); @@ -124,8 +124,7 @@ resize_handler(struct widget *widget, { struct view *view = data; - window_set_child_size(view->window, width, height); - window_schedule_redraw(window); + widget_set_size(view->widget, width, height); } static void diff --git a/clients/window.c b/clients/window.c index c81aed3..492d951 100644 --- a/clients/window.c +++ b/clients/window.c @@ -1112,6 +1112,26 @@ widget_get_allocation(struct widget *widget, struct rectangle *allocation) } void +widget_set_size(struct widget *widget, int32_t width, int32_t height) +{ + struct window *window = widget->window; + + widget->allocation.width = width; + widget->allocation.height = height; + + window->allocation.x = 0; + window->allocation.y = 0; + if (widget->window->decoration) { + window->allocation.width = width + 20 + widget->window->margin; + window->allocation.height = + height + 60 + widget->window->margin; + } else { + window->allocation.width = width; + window->allocation.height = height; + } +} + +void widget_set_allocation(struct widget *widget, int32_t x, int32_t y, int32_t width, int32_t height) { @@ -1911,12 +1931,17 @@ static void window_resize(struct window *window, int32_t width, int32_t height) { struct rectangle allocation; + struct widget *widget; + int decoration_width, decoration_height; + + decoration_width = 20 + window->margin * 2; + decoration_height = 60 + window->margin * 2; if (window->decoration) { - allocation.x = 20; - allocation.y = 60; - allocation.width = width - 20 - window->margin * 2; - allocation.height = height - 60 - window->margin * 2; + allocation.x = 10 + window->margin; + allocation.y = 50 + window->margin; + allocation.width = width - decoration_width; + allocation.height = height - decoration_height; } else { allocation.x = 0; allocation.y = 0; @@ -1924,17 +1949,26 @@ window_resize(struct window *window, int32_t width, int32_t height) allocation.height = height; } - window->allocation.width = width; - window->allocation.height = height; - - widget_set_allocation(window->widget, allocation.x, allocation.y, + widget = window->widget; + widget_set_allocation(widget, allocation.x, allocation.y, allocation.width, allocation.height); - if (window->widget->resize_handler) - window->widget->resize_handler(window->widget, - allocation.width, - allocation.height, - window->widget->user_data); + if (widget->resize_handler) + widget->resize_handler(widget, + allocation.width, + allocation.height, + widget->user_data); + + if (window->decoration) { + window->allocation.x = 0; + window->allocation.y = 0; + window->allocation.width = + widget->allocation.width + decoration_width; + window->allocation.height = + widget->allocation.height + decoration_height; + } else { + window->allocation = widget->allocation; + } window_schedule_redraw(window); } @@ -1962,6 +1996,21 @@ window_schedule_resize(struct window *window, int width, int height) } } +void +widget_schedule_resize(struct widget *widget, int32_t width, int32_t height) +{ + struct window *window = widget->window; + + if (widget->window->decoration) { + window_schedule_resize(window, + width + 20 + 2 * window->margin, + height + 60 + 2 * window->margin); + + } else { + window_schedule_resize(window, width, height); + } +} + static void handle_configure(void *data, struct wl_shell_surface *shell_surface, uint32_t time, uint32_t edges, @@ -2001,38 +2050,6 @@ window_get_allocation(struct window *window, *allocation = window->allocation; } -void -window_get_child_allocation(struct window *window, - struct rectangle *allocation) -{ - if (!window->decoration) { - *allocation = window->allocation; - } else { - allocation->x = window->margin + 10; - allocation->y = window->margin + 50; - allocation->width = - window->allocation.width - 20 - window->margin * 2; - allocation->height = - window->allocation.height - 60 - window->margin * 2; - } -} - -void -window_set_child_size(struct window *window, int32_t width, int32_t height) -{ - if (window->decoration) { - window->allocation.x = 20 + window->margin; - window->allocation.y = 60 + window->margin; - window->allocation.width = width + 20 + window->margin * 2; - window->allocation.height = height + 60 + window->margin * 2; - } else { - window->allocation.x = 0; - window->allocation.y = 0; - window->allocation.width = width; - window->allocation.height = height; - } -} - static void widget_redraw(struct widget *widget) { diff --git a/clients/window.h b/clients/window.h index 0bc7e5a..3252c89 100644 --- a/clients/window.h +++ b/clients/window.h @@ -222,28 +222,13 @@ struct widget * window_get_focus_widget(struct window *window); struct display * window_get_display(struct window *window); -struct widget * -window_get_widget(struct window *window); - void window_move(struct window *window, struct input *input, uint32_t time); - void -window_draw(struct window *window); - -void -window_get_allocation(struct window *window, - struct rectangle *allocation); - -void -window_get_child_allocation(struct window *window, - struct rectangle *allocation); - +window_get_allocation(struct window *window, struct rectangle *allocation); void window_set_transparent(struct window *window, int transparent); void -window_set_child_size(struct window *window, int32_t width, int32_t height); -void window_schedule_redraw(struct window *window); void window_schedule_resize(struct window *window, int width, int height); @@ -334,6 +319,10 @@ widget_get_allocation(struct widget *widget, struct rectangle *allocation); void widget_set_allocation(struct widget *widget, int32_t x, int32_t y, int32_t width, int32_t height); +void +widget_set_size(struct widget *widget, int32_t width, int32_t height); +void +widget_schedule_resize(struct widget *widget, int32_t width, int32_t height); void * widget_get_user_data(struct widget *widget); diff --git a/clients/wscreensaver.c b/clients/wscreensaver.c index d283125..308019b 100644 --- a/clients/wscreensaver.c +++ b/clients/wscreensaver.c @@ -90,7 +90,7 @@ redraw_handler(struct widget *widget, void *data) mi->swap_buffers = 0; - window_get_child_allocation(mi->window, &drawarea); + widget_get_allocation(mi->widget, &drawarea); window_get_allocation(mi->window, &winarea); if (display_acquire_window_surface(wscr->display, @@ -182,7 +182,7 @@ create_modeinfo(struct wscreensaver *wscr, struct window *window) if (!mi) return NULL; - window_get_child_allocation(window, &drawarea); + window_get_allocation(window, &drawarea); mi->priv = wscr; mi->eglctx = EGL_NO_CONTEXT; |