window: Drop the window widget

It was just a temporary convenience for moving things over.
dev
Kristian Høgsberg 13 years ago
parent cadd0f5cd9
commit 75bc667a70
  1. 38
      clients/desktop-shell.c
  2. 25
      clients/dnd.c
  3. 8
      clients/eventdemo.c
  4. 24
      clients/flower.c
  5. 8
      clients/resizor.c
  6. 5
      clients/smoke.c
  7. 2
      clients/tablet-shell.c
  8. 17
      clients/terminal.c
  9. 60
      clients/window.c

@ -59,7 +59,9 @@ struct surface {
struct panel { struct panel {
struct surface base; struct surface base;
struct window *window; struct window *window;
struct widget *widget;
struct window *menu; struct window *menu;
struct wl_list launcher_list;
}; };
struct background { struct background {
@ -81,10 +83,12 @@ struct panel_launcher {
cairo_surface_t *icon; cairo_surface_t *icon;
int pressed; int pressed;
const char *path; const char *path;
struct wl_list link;
}; };
struct unlock_dialog { struct unlock_dialog {
struct window *window; struct window *window;
struct widget *widget;
struct widget *button; struct widget *button;
int closing; int closing;
@ -164,19 +168,17 @@ panel_launcher_activate(struct panel_launcher *widget)
} }
static void static void
panel_draw_launcher(struct widget *widget, void *data) panel_draw_launcher(struct panel_launcher *launcher, void *data)
{ {
cairo_t *cr = data; cairo_t *cr = data;
struct panel_launcher *pi;
int x, y, width, height; int x, y, width, height;
double dx, dy; double dx, dy;
pi = widget_get_user_data(widget); width = cairo_image_surface_get_width(launcher->icon);
width = cairo_image_surface_get_width(pi->icon); height = cairo_image_surface_get_height(launcher->icon);
height = cairo_image_surface_get_height(pi->icon);
x = 0; x = 0;
y = -height / 2; y = -height / 2;
if (pi->pressed) { if (launcher->pressed) {
x++; x++;
y++; y++;
} }
@ -184,14 +186,15 @@ panel_draw_launcher(struct widget *widget, void *data)
dx = x; dx = x;
dy = y; dy = y;
cairo_user_to_device(cr, &dx, &dy); cairo_user_to_device(cr, &dx, &dy);
widget_set_allocation(widget, dx, dy, width, height); widget_set_allocation(launcher->widget, dx, dy, width, height);
cairo_set_source_surface(cr, pi->icon, x, y); cairo_set_source_surface(cr, launcher->icon, x, y);
cairo_paint(cr); cairo_paint(cr);
if (window_get_focus_widget(pi->panel->window) == widget) { if (window_get_focus_widget(launcher->panel->window) ==
launcher->widget) {
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4);
cairo_mask_surface(cr, pi->icon, x, y); cairo_mask_surface(cr, launcher->icon, x, y);
} }
cairo_translate(cr, width + 10, 0); cairo_translate(cr, width + 10, 0);
@ -212,8 +215,9 @@ panel_redraw_handler(struct window *window, void *data)
{ {
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr; cairo_t *cr;
struct panel_launcher *launcher;
struct panel *panel = window_get_user_data(window);
window_draw(window);
surface = window_get_surface(window); surface = window_get_surface(window);
cr = cairo_create(surface); cr = cairo_create(surface);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
@ -222,11 +226,11 @@ panel_redraw_handler(struct window *window, void *data)
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_translate(cr, 10, 32 / 2); cairo_translate(cr, 10, 32 / 2);
window_for_each_widget(window, panel_draw_launcher, cr); wl_list_for_each(launcher, &panel->launcher_list, link)
panel_draw_launcher(launcher, cr);
cairo_destroy(cr); cairo_destroy(cr);
cairo_surface_destroy(surface); cairo_surface_destroy(surface);
window_flush(window);
} }
static int static int
@ -291,6 +295,7 @@ panel_create(struct display *display)
panel->base.configure = panel_configure; panel->base.configure = panel_configure;
panel->window = window_create(display, 0, 0); panel->window = window_create(display, 0, 0);
panel->widget = window_add_widget(panel->window, panel);
window_set_title(panel->window, "panel"); window_set_title(panel->window, "panel");
window_set_decoration(panel->window, 0); window_set_decoration(panel->window, 0);
@ -298,8 +303,8 @@ panel_create(struct display *display)
window_set_custom(panel->window); window_set_custom(panel->window);
window_set_user_data(panel->window, panel); window_set_user_data(panel->window, panel);
widget_set_button_handler(window_get_widget(panel->window), widget_set_button_handler(panel->widget, panel_button_handler);
panel_button_handler); wl_list_init(&panel->launcher_list);
return panel; return panel;
} }
@ -315,6 +320,8 @@ panel_add_launcher(struct panel *panel, const char *icon, const char *path)
launcher->path = strdup(path); launcher->path = strdup(path);
launcher->panel = panel; launcher->panel = panel;
wl_list_insert(panel->launcher_list.prev, &launcher->link);
launcher->widget = window_add_widget(panel->window, launcher); launcher->widget = window_add_widget(panel->window, launcher);
widget_set_enter_handler(launcher->widget, widget_set_enter_handler(launcher->widget,
panel_launcher_enter_handler); panel_launcher_enter_handler);
@ -485,6 +492,7 @@ unlock_dialog_create(struct desktop *desktop)
memset(dialog, 0, sizeof *dialog); memset(dialog, 0, sizeof *dialog);
dialog->window = window_create(display, 260, 230); dialog->window = window_create(display, 260, 230);
dialog->widget = window_add_widget(dialog->window, dialog);
window_set_title(dialog->window, "Unlock your desktop"); window_set_title(dialog->window, "Unlock your desktop");
window_set_custom(dialog->window); window_set_custom(dialog->window);

@ -38,6 +38,7 @@
struct dnd { struct dnd {
struct window *window; struct window *window;
struct widget *widget;
struct display *display; struct display *display;
uint32_t key; uint32_t key;
struct item *items[16]; struct item *items[16];
@ -365,8 +366,7 @@ dnd_button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct window *window = data; struct dnd *dnd = data;
struct dnd *dnd = window_get_user_data(window);
int32_t x, y; int32_t x, y;
struct item *item; struct item *item;
struct rectangle allocation; struct rectangle allocation;
@ -406,7 +406,7 @@ dnd_button_handler(struct widget *widget,
"text/plain; charset=utf-8"); "text/plain; charset=utf-8");
wl_data_device_start_drag(input_get_data_device(input), wl_data_device_start_drag(input_get_data_device(input),
dnd_drag->data_source, dnd_drag->data_source,
window_get_wl_surface(window), window_get_wl_surface(dnd->window),
time); time);
input_set_pointer_image(input, time, POINTER_DRAGGING); input_set_pointer_image(input, time, POINTER_DRAGGING);
@ -437,10 +437,7 @@ dnd_enter_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int32_t x, int32_t y, void *data) int32_t x, int32_t y, void *data)
{ {
struct window *window = data; return lookup_cursor(data, x, y);
struct dnd *dnd = window_get_user_data(window);
return lookup_cursor(dnd, x, y);
} }
static int static int
@ -448,10 +445,7 @@ dnd_motion_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int32_t x, int32_t y, void *data) int32_t x, int32_t y, void *data)
{ {
struct window *window = data; return lookup_cursor(data, x, y);
struct dnd *dnd = window_get_user_data(window);
return lookup_cursor(dnd, x, y);
} }
static void static void
@ -516,7 +510,6 @@ dnd_create(struct display *display)
struct dnd *dnd; struct dnd *dnd;
int i, x, y; int i, x, y;
int32_t width, height; int32_t width, height;
struct widget *widget;
dnd = malloc(sizeof *dnd); dnd = malloc(sizeof *dnd);
if (dnd == NULL) if (dnd == NULL)
@ -524,6 +517,7 @@ dnd_create(struct display *display)
memset(dnd, 0, sizeof *dnd); memset(dnd, 0, sizeof *dnd);
dnd->window = window_create(display, 400, 400); dnd->window = window_create(display, 400, 400);
dnd->widget = window_add_widget(dnd->window, dnd);
window_set_title(dnd->window, "Wayland Drag and Drop Demo"); window_set_title(dnd->window, "Wayland Drag and Drop Demo");
dnd->display = display; dnd->display = display;
@ -545,10 +539,9 @@ dnd_create(struct display *display)
window_set_data_handler(dnd->window, dnd_data_handler); window_set_data_handler(dnd->window, dnd_data_handler);
window_set_drop_handler(dnd->window, dnd_drop_handler); window_set_drop_handler(dnd->window, dnd_drop_handler);
widget = window_get_widget(dnd->window); widget_set_enter_handler(dnd->widget, dnd_enter_handler);
widget_set_enter_handler(widget, dnd_enter_handler); widget_set_motion_handler(dnd->widget, dnd_motion_handler);
widget_set_motion_handler(widget, dnd_motion_handler); widget_set_button_handler(dnd->widget, dnd_button_handler);
widget_set_button_handler(widget, dnd_button_handler);
width = 4 * (item_width + item_padding) + item_padding; width = 4 * (item_width + item_padding) + item_padding;
height = 4 * (item_height + item_padding) + item_padding; height = 4 * (item_height + item_padding) + item_padding;

@ -83,6 +83,7 @@ static int log_motion = 0;
*/ */
struct eventdemo { struct eventdemo {
struct window *window; struct window *window;
struct widget *widget;
struct display *display; struct display *display;
unsigned int x, y, w, h; unsigned int x, y, w, h;
@ -285,6 +286,7 @@ eventdemo_create(struct display *d)
* int32_t width, int32_t height); * int32_t width, int32_t height);
*/ */
e->window = window_create(d, width, height); e->window = window_create(d, width, height);
e->widget = window_add_widget(e->window, e);
window_set_title(e->window, title); window_set_title(e->window, title);
e->display = d; e->display = d;
@ -314,12 +316,10 @@ eventdemo_create(struct display *d)
window_set_key_handler(e->window, key_handler); window_set_key_handler(e->window, key_handler);
/* Set the callback button handler for the window */ /* Set the callback button handler for the window */
widget_set_button_handler(window_get_widget(e->window), widget_set_button_handler(e->widget, button_handler);
button_handler);
/* Set the callback motion handler for the window */ /* Set the callback motion handler for the window */
widget_set_motion_handler(window_get_widget(e->window), widget_set_motion_handler(e->widget, motion_handler);
motion_handler);
/* Demonstrate how to create a borderless window. /* Demonstrate how to create a borderless window.
Move windows with META + left mouse button. Move windows with META + left mouse button.

@ -36,6 +36,13 @@
#include <wayland-client.h> #include <wayland-client.h>
#include "window.h" #include "window.h"
struct flower {
struct display *display;
struct window *window;
struct widget *widget;
int width, height;
};
static void static void
set_random_color(cairo_t *cr) set_random_color(cairo_t *cr)
{ {
@ -109,18 +116,12 @@ button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct window *window = data; struct flower *flower = data;
if (state) if (state)
window_move(window, input, time); window_move(flower->window, input, time);
} }
struct flower {
struct display *display;
struct window *window;
int width, height;
};
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cairo_surface_t *s; cairo_surface_t *s;
@ -141,6 +142,7 @@ int main(int argc, char *argv[])
flower.height = 200; flower.height = 200;
flower.display = d; flower.display = d;
flower.window = window_create(d, flower.width, flower.height); flower.window = window_create(d, flower.width, flower.height);
flower.widget = window_add_widget(flower.window, &flower);
window_set_title(flower.window, "flower"); window_set_title(flower.window, "flower");
window_set_decoration(flower.window, 0); window_set_decoration(flower.window, 0);
@ -156,10 +158,8 @@ int main(int argc, char *argv[])
cairo_surface_destroy(s); cairo_surface_destroy(s);
window_flush(flower.window); window_flush(flower.window);
widget_set_motion_handler(window_get_widget(flower.window), widget_set_motion_handler(flower.widget, motion_handler);
motion_handler); widget_set_button_handler(flower.widget, button_handler);
widget_set_button_handler(window_get_widget(flower.window),
button_handler);
window_set_user_data(flower.window, &flower); window_set_user_data(flower.window, &flower);
display_run(d); display_run(d);

@ -38,6 +38,7 @@
struct resizor { struct resizor {
struct display *display; struct display *display;
struct window *window; struct window *window;
struct widget *widget;
struct window *menu; struct window *menu;
int32_t width; int32_t width;
@ -194,8 +195,7 @@ button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct window *window = data; struct resizor *resizor = data;
struct resizor *resizor = window_get_user_data(window);
switch (button) { switch (button) {
case BTN_RIGHT: case BTN_RIGHT:
@ -217,6 +217,7 @@ resizor_create(struct display *display)
memset(resizor, 0, sizeof *resizor); memset(resizor, 0, sizeof *resizor);
resizor->window = window_create(display, 500, 400); resizor->window = window_create(display, 500, 400);
resizor->widget = window_add_widget(resizor->window, resizor);
window_set_title(resizor->window, "Wayland Resizor"); window_set_title(resizor->window, "Wayland Resizor");
resizor->display = display; resizor->display = display;
@ -233,8 +234,7 @@ resizor_create(struct display *display)
height = resizor->height.current + 0.5; height = resizor->height.current + 0.5;
window_set_child_size(resizor->window, resizor->width, height); window_set_child_size(resizor->window, resizor->width, height);
widget_set_button_handler(window_get_widget(resizor->window), widget_set_button_handler(resizor->widget, button_handler);
button_handler);
resizor_draw(resizor); resizor_draw(resizor);

@ -38,6 +38,7 @@
struct smoke { struct smoke {
struct display *display; struct display *display;
struct window *window; struct window *window;
struct widget *widget;
cairo_surface_t *surface; cairo_surface_t *surface;
int x, y, width, height; int x, y, width, height;
int offset, current; int offset, current;
@ -267,6 +268,7 @@ int main(int argc, char *argv[])
smoke.height = 200; smoke.height = 200;
smoke.display = d; smoke.display = d;
smoke.window = window_create(d, smoke.width, smoke.height); smoke.window = window_create(d, smoke.width, smoke.height);
smoke.widget = window_add_widget(smoke.window, &smoke);
window_set_title(smoke.window, "smoke"); window_set_title(smoke.window, "smoke");
window_set_buffer_type(smoke.window, WINDOW_BUFFER_TYPE_SHM); window_set_buffer_type(smoke.window, WINDOW_BUFFER_TYPE_SHM);
@ -289,8 +291,7 @@ int main(int argc, char *argv[])
window_flush(smoke.window); window_flush(smoke.window);
widget_set_motion_handler(window_get_widget(smoke.window), widget_set_motion_handler(smoke.widget, smoke_motion_handler);
smoke_motion_handler);
window_set_user_data(smoke.window, &smoke); window_set_user_data(smoke.window, &smoke);
frame_callback(&smoke, NULL, 0); frame_callback(&smoke, NULL, 0);

@ -220,8 +220,6 @@ show_lockscreen(void *data, struct tablet_shell *tablet_shell)
window_set_user_data(shell->lockscreen, shell); window_set_user_data(shell->lockscreen, shell);
window_set_decoration(shell->lockscreen, 0); window_set_decoration(shell->lockscreen, 0);
window_set_custom(shell->lockscreen); window_set_custom(shell->lockscreen);
widget_set_button_handler(window_get_widget(shell->lockscreen),
lockscreen_button_handler);
tablet_shell_set_lockscreen(shell->tablet_shell, tablet_shell_set_lockscreen(shell->tablet_shell,
window_get_wl_surface(shell->lockscreen)); window_get_wl_surface(shell->lockscreen));

@ -356,6 +356,7 @@ enum escape_state {
struct terminal { struct terminal {
struct window *window; struct window *window;
struct widget *widget;
struct display *display; struct display *display;
union utf8_char *data; union utf8_char *data;
struct task io_task; struct task io_task;
@ -2228,8 +2229,7 @@ button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int button, int state, void *data) int button, int state, void *data)
{ {
struct window *window = data; struct terminal *terminal = data;
struct terminal *terminal = window_get_user_data(window);
switch (button) { switch (button) {
case 272: case 272:
@ -2240,7 +2240,7 @@ button_handler(struct widget *widget,
&terminal->selection_start_y); &terminal->selection_start_y);
terminal->selection_end_x = terminal->selection_start_x; terminal->selection_end_x = terminal->selection_start_x;
terminal->selection_end_y = terminal->selection_start_y; terminal->selection_end_y = terminal->selection_start_y;
window_schedule_redraw(window); widget_schedule_redraw(widget);
} else { } else {
terminal->dragging = 0; terminal->dragging = 0;
} }
@ -2253,8 +2253,7 @@ motion_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int32_t x, int32_t y, void *data) int32_t x, int32_t y, void *data)
{ {
struct window *window = data; struct terminal *terminal = data;
struct terminal *terminal = window_get_user_data(window);
if (terminal->dragging) { if (terminal->dragging) {
input_get_position(input, input_get_position(input,
@ -2284,6 +2283,7 @@ terminal_create(struct display *display, int fullscreen)
terminal->margin_top = 0; terminal->margin_top = 0;
terminal->margin_bottom = -1; terminal->margin_bottom = -1;
terminal->window = window_create(display, 500, 400); terminal->window = window_create(display, 500, 400);
terminal->widget = window_add_widget(terminal->window, terminal);
window_set_title(terminal->window, "Wayland Terminal"); window_set_title(terminal->window, "Wayland Terminal");
init_state_machine(&terminal->state_machine); init_state_machine(&terminal->state_machine);
@ -2299,11 +2299,8 @@ terminal_create(struct display *display, int fullscreen)
window_set_key_handler(terminal->window, key_handler); window_set_key_handler(terminal->window, key_handler);
window_set_keyboard_focus_handler(terminal->window, window_set_keyboard_focus_handler(terminal->window,
keyboard_focus_handler); keyboard_focus_handler);
widget_set_button_handler(window_get_widget(terminal->window), widget_set_button_handler(terminal->widget, button_handler);
button_handler); widget_set_motion_handler(terminal->widget, motion_handler);
widget_set_motion_handler(window_get_widget(terminal->window),
motion_handler);
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
cr = cairo_create(surface); cr = cairo_create(surface);

@ -107,7 +107,6 @@ enum {
struct window { struct window {
struct display *display; struct display *display;
struct window *parent; struct window *parent;
struct widget *widget;
struct wl_surface *surface; struct wl_surface *surface;
struct wl_shell_surface *shell_surface; struct wl_shell_surface *shell_surface;
char *title; char *title;
@ -183,6 +182,7 @@ struct output {
struct menu { struct menu {
struct window *window; struct window *window;
struct widget *widget;
const char **entries; const char **entries;
uint32_t time; uint32_t time;
int current; int current;
@ -918,12 +918,6 @@ window_get_display(struct window *window)
return window->display; return window->display;
} }
struct widget *
window_get_widget(struct window *window)
{
return window->widget;
}
void void
window_create_surface(struct window *window) window_create_surface(struct window *window)
{ {
@ -1065,6 +1059,7 @@ window_add_widget(struct window *window, void *data)
memset(widget, 0, sizeof *widget); memset(widget, 0, sizeof *widget);
widget->window = window; widget->window = window;
widget->user_data = data; widget->user_data = data;
widget->allocation = window->allocation;
wl_list_insert(&window->widget_list, &widget->link); wl_list_insert(&window->widget_list, &widget->link);
return widget; return widget;
@ -1879,6 +1874,7 @@ handle_configure(void *data, struct wl_shell_surface *shell_surface,
int32_t width, int32_t height) int32_t width, int32_t height)
{ {
struct window *window = data; struct window *window = data;
struct widget *widget;
int32_t child_width, child_height; int32_t child_width, child_height;
/* FIXME: this is probably the wrong place to check for width /* FIXME: this is probably the wrong place to check for width
@ -1903,6 +1899,9 @@ handle_configure(void *data, struct wl_shell_surface *shell_surface,
if (window->redraw_handler) if (window->redraw_handler)
window_schedule_redraw(window); window_schedule_redraw(window);
} }
wl_list_for_each(widget, &window->widget_list, link)
widget->allocation = window->allocation;
} }
static void static void
@ -1959,8 +1958,6 @@ window_set_child_size(struct window *window, int32_t width, int32_t height)
window->allocation.width = width; window->allocation.width = width;
window->allocation.height = height; window->allocation.height = height;
} }
window->widget->allocation = window->allocation;
} }
static void static void
@ -2146,7 +2143,6 @@ window_create_internal(struct display *display, struct window *parent,
window->transparent = 1; window->transparent = 1;
wl_list_init(&window->widget_list); wl_list_init(&window->widget_list);
window->widget = window_add_widget(window, window);
if (display->dpy) if (display->dpy)
#ifdef HAVE_CAIRO_EGL #ifdef HAVE_CAIRO_EGL
@ -2208,7 +2204,7 @@ menu_set_item(struct menu *menu, int sy)
next = (sy - 8) / 20; next = (sy - 8) / 20;
if (menu->current != next) { if (menu->current != next) {
menu->current = next; menu->current = next;
widget_schedule_redraw(menu->window->widget); widget_schedule_redraw(menu->widget);
} }
return POINTER_LEFT_PTR; return POINTER_LEFT_PTR;
@ -2219,10 +2215,7 @@ menu_motion_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int32_t x, int32_t y, void *data) int32_t x, int32_t y, void *data)
{ {
struct window *window = data; return menu_set_item(data, y);
struct menu *menu = window_get_user_data(window);
return menu_set_item(menu, y);
} }
static int static int
@ -2230,21 +2223,13 @@ menu_enter_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
int32_t x, int32_t y, void *data) int32_t x, int32_t y, void *data)
{ {
struct window *window = data; return menu_set_item(data, y);
struct menu *menu = window_get_user_data(window);
menu_set_item(menu, y);
return POINTER_LEFT_PTR;
} }
static void static void
menu_leave_handler(struct widget *widget, struct input *input, void *data) menu_leave_handler(struct widget *widget, struct input *input, void *data)
{ {
struct window *window = data; menu_set_item(data, -200);
struct menu *menu = window_get_user_data(window);
menu_set_item(menu, -200);
} }
static void static void
@ -2253,14 +2238,13 @@ menu_button_handler(struct widget *widget,
int button, int state, void *data) int button, int state, void *data)
{ {
struct window *window = data; struct menu *menu = data;
struct menu *menu = window_get_user_data(window);
/* Either relase after press-drag-release or click-motion-click. */ /* Either relase after press-drag-release or click-motion-click. */
if (state == 0 && time - menu->time > 500) { if (state == 0 && time - menu->time > 500) {
menu->func(window->parent, menu->func(menu->window->parent,
menu->current, window->parent->user_data); menu->current, menu->window->parent->user_data);
window_destroy(window); window_destroy(widget->window);
} }
} }
@ -2272,9 +2256,6 @@ menu_redraw_handler(struct window *window, void *data)
struct menu *menu = data; struct menu *menu = data;
int32_t width, height, i; int32_t width, height, i;
width = 200;
height = menu->count * 20 + margin * 2;
window_set_child_size(window, width, height);
window_create_surface(window); window_create_surface(window);
cr = cairo_create(window->cairo_surface); cr = cairo_create(window->cairo_surface);
@ -2317,16 +2298,19 @@ window_create_menu(struct display *display,
{ {
struct window *window; struct window *window;
struct menu *menu; struct menu *menu;
const int32_t margin = 3;
menu = malloc(sizeof *menu); menu = malloc(sizeof *menu);
if (!menu) if (!menu)
return NULL; return NULL;
window = window_create_internal(parent->display, parent, 0, 0); window = window_create_internal(parent->display, parent,
200, count * 20 + margin * 2);
if (!window) if (!window)
return NULL; return NULL;
menu->window = window; menu->window = window;
menu->widget = window_add_widget(menu->window, menu);
menu->entries = entries; menu->entries = entries;
menu->count = count; menu->count = count;
menu->time = time; menu->time = time;
@ -2344,10 +2328,10 @@ window_create_menu(struct display *display,
window_set_redraw_handler(window, menu_redraw_handler); window_set_redraw_handler(window, menu_redraw_handler);
window_set_user_data(window, menu); window_set_user_data(window, menu);
widget_set_enter_handler(window->widget, menu_enter_handler); widget_set_enter_handler(menu->widget, menu_enter_handler);
widget_set_leave_handler(window->widget, menu_leave_handler); widget_set_leave_handler(menu->widget, menu_leave_handler);
widget_set_motion_handler(window->widget, menu_motion_handler); widget_set_motion_handler(menu->widget, menu_motion_handler);
widget_set_button_handler(window->widget, menu_button_handler); widget_set_button_handler(menu->widget, menu_button_handler);
return window; return window;
} }

Loading…
Cancel
Save