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
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);
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);
struct rectangle allocation;
int i;
- window_get_child_allocation(dnd->window, &allocation);
+ widget_get_allocation(dnd->widget, &allocation);
x -= allocation.x;
y -= allocation.y;
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;
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,
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;
}
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);
height = height_max;
/* set the new window dimensions */
- window_set_child_size(e->window, width, height);
+ widget_set_size(e->widget, width, height);
}
/**
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);
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,
}
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,
height = 300;
}
- window_set_child_size(gears->window, width, height);
+ widget_set_size(gears->widget, width, height);
}
static void
window_set_keyboard_focus_handler(gears->window,
keyboard_focus_handler);
- frame_callback(gears, NULL, 0);
+ window_schedule_resize(gears->window, width, height);
return gears;
}
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,
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);
window_set_keyboard_focus_handler(image->window,
keyboard_focus_handler);
- window_schedule_redraw(image->window);
+ widget_schedule_resize(image->widget, 500, 400);
return image;
}
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;
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)
{
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);
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
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;
}
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);
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);
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;
}
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;
int i, l, total_rows;
struct rectangle allocation;
struct winsize ws;
- int32_t pixel_width, pixel_height;
if (width < 1)
width = 1;
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);
/* 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 */
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);
}
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
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 */
}
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));
if (!terminal->fullscreen)
terminal_resize(terminal, 80, 24);
- window_schedule_redraw(terminal->window);
-
return 0;
}
window_draw(view->window);
- window_get_child_allocation(view->window, &allocation);
+ widget_get_allocation(view->widget, &allocation);
surface = window_get_surface(view->window);
{
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
}
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)
{
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;
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);
}
}
}
+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,
*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)
{
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);
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);
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,
if (!mi)
return NULL;
- window_get_child_allocation(window, &drawarea);
+ window_get_allocation(window, &drawarea);
mi->priv = wscr;
mi->eglctx = EGL_NO_CONTEXT;