window: Rename item to widget

It's a widget.
This commit is contained in:
Kristian Høgsberg 2012-01-08 15:09:53 -05:00
parent 4f7dcd6eb1
commit c51f79954b
3 changed files with 120 additions and 120 deletions

View File

@ -75,8 +75,8 @@ struct output {
struct background *background; struct background *background;
}; };
struct panel_item { struct panel_widget {
struct item *item; struct widget *widget;
struct panel *panel; struct panel *panel;
cairo_surface_t *icon; cairo_surface_t *icon;
int pressed; int pressed;
@ -85,7 +85,7 @@ struct panel_item {
struct unlock_dialog { struct unlock_dialog {
struct window *window; struct window *window;
struct item *button; struct widget *button;
int closing; int closing;
struct desktop *desktop; struct desktop *desktop;
@ -144,7 +144,7 @@ show_menu(struct panel *panel, struct input *input, uint32_t time)
} }
static void static void
panel_activate_item(struct panel *panel, struct panel_item *item) panel_activate_widget(struct panel *panel, struct panel_widget *widget)
{ {
pid_t pid; pid_t pid;
@ -157,21 +157,21 @@ panel_activate_item(struct panel *panel, struct panel_item *item)
if (pid) if (pid)
return; return;
if (execl(item->path, item->path, NULL) < 0) { if (execl(widget->path, widget->path, NULL) < 0) {
fprintf(stderr, "execl failed: %m\n"); fprintf(stderr, "execl failed: %m\n");
exit(1); exit(1);
} }
} }
static void static void
panel_draw_item(struct item *item, void *data) panel_draw_widget(struct widget *widget, void *data)
{ {
cairo_t *cr = data; cairo_t *cr = data;
struct panel_item *pi; struct panel_widget *pi;
int x, y, width, height; int x, y, width, height;
double dx, dy; double dx, dy;
pi = item_get_user_data(item); pi = widget_get_user_data(widget);
width = cairo_image_surface_get_width(pi->icon); width = cairo_image_surface_get_width(pi->icon);
height = cairo_image_surface_get_height(pi->icon); height = cairo_image_surface_get_height(pi->icon);
x = 0; x = 0;
@ -184,12 +184,12 @@ panel_draw_item(struct item *item, void *data)
dx = x; dx = x;
dy = y; dy = y;
cairo_user_to_device(cr, &dx, &dy); cairo_user_to_device(cr, &dx, &dy);
item_set_allocation(item, dx, dy, width, height); widget_set_allocation(widget, dx, dy, width, height);
cairo_set_source_surface(cr, pi->icon, x, y); cairo_set_source_surface(cr, pi->icon, x, y);
cairo_paint(cr); cairo_paint(cr);
if (window_get_focus_item(pi->panel->window) == item) { if (window_get_focus_widget(pi->panel->window) == 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, pi->icon, x, y);
} }
@ -222,7 +222,7 @@ 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_item(window, panel_draw_item, cr); window_for_each_widget(window, panel_draw_widget, cr);
cairo_destroy(cr); cairo_destroy(cr);
cairo_surface_destroy(surface); cairo_surface_destroy(surface);
@ -230,8 +230,8 @@ panel_redraw_handler(struct window *window, void *data)
} }
static void static void
panel_item_focus_handler(struct window *window, panel_widget_focus_handler(struct window *window,
struct item *focus, void *data) struct widget *focus, void *data)
{ {
window_schedule_redraw(window); window_schedule_redraw(window);
} }
@ -242,15 +242,15 @@ panel_button_handler(struct window *window,
int button, int state, void *data) int button, int state, void *data)
{ {
struct panel *panel = data; struct panel *panel = data;
struct panel_item *pi; struct panel_widget *pi;
struct item *focus; struct widget *focus;
focus = window_get_focus_item(panel->window); focus = window_get_focus_widget(panel->window);
if (focus && button == BTN_LEFT) { if (focus && button == BTN_LEFT) {
pi = item_get_user_data(focus); pi = widget_get_user_data(focus);
window_schedule_redraw(panel->window); window_schedule_redraw(panel->window);
if (state == 0) if (state == 0)
panel_activate_item(panel, pi); panel_activate_widget(panel, pi);
} else if (button == BTN_RIGHT) { } else if (button == BTN_RIGHT) {
if (state) if (state)
show_menu(panel, input, time); show_menu(panel, input, time);
@ -285,22 +285,22 @@ 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);
window_set_button_handler(panel->window, panel_button_handler); window_set_button_handler(panel->window, panel_button_handler);
window_set_item_focus_handler(panel->window, panel_item_focus_handler); window_set_widget_focus_handler(panel->window, panel_widget_focus_handler);
return panel; return panel;
} }
static void static void
panel_add_item(struct panel *panel, const char *icon, const char *path) panel_add_widget(struct panel *panel, const char *icon, const char *path)
{ {
struct panel_item *item; struct panel_widget *widget;
item = malloc(sizeof *item); widget = malloc(sizeof *widget);
memset(item, 0, sizeof *item); memset(widget, 0, sizeof *widget);
item->icon = cairo_image_surface_create_from_png(icon); widget->icon = cairo_image_surface_create_from_png(icon);
item->path = strdup(path); widget->path = strdup(path);
item->panel = panel; widget->panel = panel;
window_add_item(panel->window, item); window_add_widget(panel->window, widget);
} }
static void static void
@ -375,7 +375,7 @@ unlock_dialog_draw(struct unlock_dialog *dialog)
cairo_set_source_rgba(cr, 0, 0, 0, 0.6); cairo_set_source_rgba(cr, 0, 0, 0, 0.6);
cairo_paint(cr); cairo_paint(cr);
if (window_get_focus_item(dialog->window) == dialog->button) if (window_get_focus_widget(dialog->window) == dialog->button)
f = 1.0; f = 1.0;
else else
f = 0.7; f = 0.7;
@ -391,7 +391,7 @@ unlock_dialog_draw(struct unlock_dialog *dialog)
cairo_arc(cr, cx, cy, r, 0.0, 2.0 * M_PI); cairo_arc(cr, cx, cy, r, 0.0, 2.0 * M_PI);
cairo_fill(cr); cairo_fill(cr);
item_set_allocation(dialog->button, widget_set_allocation(dialog->button,
allocation.x + cx - r, allocation.x + cx - r,
allocation.y + cy - r, 2 * r, 2 * r); allocation.y + cy - r, 2 * r, 2 * r);
cairo_pattern_destroy(pat); cairo_pattern_destroy(pat);
@ -411,9 +411,9 @@ unlock_dialog_button_handler(struct window *window,
{ {
struct unlock_dialog *dialog = data; struct unlock_dialog *dialog = data;
struct desktop *desktop = dialog->desktop; struct desktop *desktop = dialog->desktop;
struct item *focus; struct widget *focus;
focus = window_get_focus_item(dialog->window); focus = window_get_focus_widget(dialog->window);
if (focus && button == BTN_LEFT) { if (focus && button == BTN_LEFT) {
if (state == 0 && !dialog->closing) { if (state == 0 && !dialog->closing) {
display_defer(desktop->display, &desktop->unlock_task); display_defer(desktop->display, &desktop->unlock_task);
@ -438,8 +438,8 @@ unlock_dialog_keyboard_focus_handler(struct window *window,
} }
static void static void
unlock_dialog_item_focus_handler(struct window *window, unlock_dialog_widget_focus_handler(struct window *window,
struct item *focus, void *data) struct widget *focus, void *data)
{ {
window_schedule_redraw(window); window_schedule_redraw(window);
} }
@ -464,9 +464,9 @@ unlock_dialog_create(struct desktop *desktop)
window_set_keyboard_focus_handler(dialog->window, window_set_keyboard_focus_handler(dialog->window,
unlock_dialog_keyboard_focus_handler); unlock_dialog_keyboard_focus_handler);
window_set_button_handler(dialog->window, unlock_dialog_button_handler); window_set_button_handler(dialog->window, unlock_dialog_button_handler);
window_set_item_focus_handler(dialog->window, window_set_widget_focus_handler(dialog->window,
unlock_dialog_item_focus_handler); unlock_dialog_widget_focus_handler);
dialog->button = window_add_item(dialog->window, NULL); dialog->button = window_add_widget(dialog->window, NULL);
desktop_shell_set_lock_surface(desktop->shell, desktop_shell_set_lock_surface(desktop->shell,
window_get_wl_shell_surface(dialog->window)); window_get_wl_shell_surface(dialog->window));
@ -588,7 +588,7 @@ launcher_section_done(void *data)
} }
wl_list_for_each(output, &desktop->outputs, link) wl_list_for_each(output, &desktop->outputs, link)
panel_add_item(output->panel, panel_add_widget(output->panel,
key_launcher_icon, key_launcher_path); key_launcher_icon, key_launcher_path);
free(key_launcher_icon); free(key_launcher_icon);

View File

@ -134,14 +134,14 @@ struct window {
window_motion_handler_t motion_handler; window_motion_handler_t motion_handler;
window_enter_handler_t enter_handler; window_enter_handler_t enter_handler;
window_leave_handler_t leave_handler; window_leave_handler_t leave_handler;
window_item_focus_handler_t item_focus_handler; window_widget_focus_handler_t widget_focus_handler;
window_data_handler_t data_handler; window_data_handler_t data_handler;
window_drop_handler_t drop_handler; window_drop_handler_t drop_handler;
window_close_handler_t close_handler; window_close_handler_t close_handler;
struct wl_list item_list; struct wl_list widget_list;
struct item *focus_item; struct widget *focus_widget;
uint32_t item_grab_button; uint32_t widget_grab_button;
struct window *menu; struct window *menu;
@ -149,7 +149,7 @@ struct window {
struct wl_list link; struct wl_list link;
}; };
struct item { struct widget {
struct wl_list link; struct wl_list link;
struct rectangle allocation; struct rectangle allocation;
void *user_data; void *user_data;
@ -1032,71 +1032,71 @@ window_destroy(struct window *window)
free(window); free(window);
} }
static struct item * static struct widget *
window_find_item(struct window *window, int32_t x, int32_t y) window_find_widget(struct window *window, int32_t x, int32_t y)
{ {
struct item *item; struct widget *widget;
wl_list_for_each(item, &window->item_list, link) { wl_list_for_each(widget, &window->widget_list, link) {
if (item->allocation.x <= x && if (widget->allocation.x <= x &&
x < item->allocation.x + item->allocation.width && x < widget->allocation.x + widget->allocation.width &&
item->allocation.y <= y && widget->allocation.y <= y &&
y < item->allocation.y + item->allocation.height) { y < widget->allocation.y + widget->allocation.height) {
return item; return widget;
} }
} }
return NULL; return NULL;
} }
struct item * struct widget *
window_add_item(struct window *window, void *data) window_add_widget(struct window *window, void *data)
{ {
struct item *item; struct widget *widget;
item = malloc(sizeof *item); widget = malloc(sizeof *widget);
memset(item, 0, sizeof *item); memset(widget, 0, sizeof *widget);
item->user_data = data; widget->user_data = data;
wl_list_insert(window->item_list.prev, &item->link); wl_list_insert(window->widget_list.prev, &widget->link);
return item; return widget;
} }
void void
window_for_each_item(struct window *window, item_func_t func, void *data) window_for_each_widget(struct window *window, widget_func_t func, void *data)
{ {
struct item *item; struct widget *widget;
wl_list_for_each(item, &window->item_list, link) wl_list_for_each(widget, &window->widget_list, link)
func(item, data); func(widget, data);
} }
struct item * struct widget *
window_get_focus_item(struct window *window) window_get_focus_widget(struct window *window)
{ {
return window->focus_item; return window->focus_widget;
} }
void void
item_get_allocation(struct item *item, struct rectangle *allocation) widget_get_allocation(struct widget *widget, struct rectangle *allocation)
{ {
*allocation = item->allocation; *allocation = widget->allocation;
} }
void void
item_set_allocation(struct item *item, widget_set_allocation(struct widget *widget,
int32_t x, int32_t y, int32_t width, int32_t height) int32_t x, int32_t y, int32_t width, int32_t height)
{ {
item->allocation.x = x; widget->allocation.x = x;
item->allocation.y = y; widget->allocation.y = y;
item->allocation.width = width; widget->allocation.width = width;
item->allocation.height = height; widget->allocation.height = height;
} }
void * void *
item_get_user_data(struct item *item) widget_get_user_data(struct widget *widget)
{ {
return item->user_data; return widget->user_data;
} }
void void
@ -1223,17 +1223,17 @@ input_set_pointer_image(struct input *input, uint32_t time, int pointer)
} }
static void static void
window_set_focus_item(struct window *window, struct item *focus) window_set_focus_widget(struct window *window, struct widget *focus)
{ {
void *data; void *data;
if (focus == window->focus_item) if (focus == window->focus_widget)
return; return;
window->focus_item = focus; window->focus_widget = focus;
data = focus ? focus->user_data : NULL; data = focus ? focus->user_data : NULL;
if (window->item_focus_handler) if (window->widget_focus_handler)
window->item_focus_handler(window, focus, data); window->widget_focus_handler(window, focus, data);
} }
static void static void
@ -1243,7 +1243,7 @@ input_handle_motion(void *data, struct wl_input_device *input_device,
{ {
struct input *input = data; struct input *input = data;
struct window *window = input->pointer_focus; struct window *window = input->pointer_focus;
struct item *item; struct widget *widget;
int pointer = POINTER_LEFT_PTR; int pointer = POINTER_LEFT_PTR;
input->x = x; input->x = x;
@ -1251,9 +1251,9 @@ input_handle_motion(void *data, struct wl_input_device *input_device,
input->sx = sx; input->sx = sx;
input->sy = sy; input->sy = sy;
if (!window->focus_item || !window->item_grab_button) { if (!window->focus_widget || !window->widget_grab_button) {
item = window_find_item(window, sx, sy); widget = window_find_widget(window, sx, sy);
window_set_focus_item(window, item); window_set_focus_widget(window, widget);
} }
if (window->motion_handler) if (window->motion_handler)
@ -1294,15 +1294,15 @@ input_handle_button(void *data,
{ {
struct input *input = data; struct input *input = data;
struct window *window = input->pointer_focus; struct window *window = input->pointer_focus;
struct item *item; struct widget *widget;
int location; int location;
int32_t x, y; int32_t x, y;
static const char *entries[] = { static const char *entries[] = {
"Close", "Fullscreen", "Rotate", "Scale" "Close", "Fullscreen", "Rotate", "Scale"
}; };
if (window->focus_item && window->item_grab_button == 0 && state) if (window->focus_widget && window->widget_grab_button == 0 && state)
window->item_grab_button = button; window->widget_grab_button = button;
location = get_pointer_location(window, input->sx, input->sy); location = get_pointer_location(window, input->sx, input->sy);
@ -1365,11 +1365,11 @@ input_handle_button(void *data,
window->user_data); window->user_data);
} }
if (window->focus_item && if (window->focus_widget &&
window->item_grab_button == button && !state) { window->widget_grab_button == button && !state) {
window->item_grab_button = 0; window->widget_grab_button = 0;
item = window_find_item(window, input->sx, input->sy); widget = window_find_widget(window, input->sx, input->sy);
window_set_focus_item(window, item); window_set_focus_widget(window, widget);
} }
} }
@ -1411,7 +1411,7 @@ input_remove_pointer_focus(struct input *input, uint32_t time)
if (!window) if (!window)
return; return;
window_set_focus_item(window, NULL); window_set_focus_widget(window, NULL);
if (window->leave_handler) if (window->leave_handler)
window->leave_handler(window, input, time, window->user_data); window->leave_handler(window, input, time, window->user_data);
@ -1427,7 +1427,7 @@ input_handle_pointer_focus(void *data,
{ {
struct input *input = data; struct input *input = data;
struct window *window; struct window *window;
struct item *item; struct widget *widget;
int pointer; int pointer;
window = input->pointer_focus; window = input->pointer_focus;
@ -1449,8 +1449,8 @@ input_handle_pointer_focus(void *data,
time, sx, sy, time, sx, sy,
window->user_data); window->user_data);
item = window_find_item(window, x, y); widget = window_find_widget(window, x, y);
window_set_focus_item(window, item); window_set_focus_widget(window, widget);
pointer = input_get_pointer_image_for_location(input, pointer); pointer = input_get_pointer_image_for_location(input, pointer);
input_set_pointer_image(input, time, pointer); input_set_pointer_image(input, time, pointer);
@ -2039,10 +2039,10 @@ window_set_keyboard_focus_handler(struct window *window,
} }
void void
window_set_item_focus_handler(struct window *window, window_set_widget_focus_handler(struct window *window,
window_item_focus_handler_t handler) window_widget_focus_handler_t handler)
{ {
window->item_focus_handler = handler; window->widget_focus_handler = handler;
} }
void void
@ -2128,7 +2128,7 @@ window_create_internal(struct display *display, struct window *parent,
window->margin = 16; window->margin = 16;
window->decoration = 1; window->decoration = 1;
window->transparent = 1; window->transparent = 1;
wl_list_init(&window->item_list); wl_list_init(&window->widget_list);
if (display->dpy) if (display->dpy)
#ifdef HAVE_CAIRO_EGL #ifdef HAVE_CAIRO_EGL
@ -2183,7 +2183,7 @@ window_create_transient(struct display *display, struct window *parent,
} }
static int static int
menu_set_item(struct window *window, struct menu *menu, int sy) menu_set_widget(struct window *window, struct menu *menu, int sy)
{ {
int next; int next;
@ -2202,7 +2202,7 @@ menu_motion_handler(struct window *window,
int32_t x, int32_t y, int32_t x, int32_t y,
int32_t sx, int32_t sy, void *data) int32_t sx, int32_t sy, void *data)
{ {
return menu_set_item(window, data, sy); return menu_set_widget(window, data, sy);
} }
static int static int
@ -2210,14 +2210,14 @@ menu_enter_handler(struct window *window,
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)
{ {
return menu_set_item(window, data, y); return menu_set_widget(window, data, y);
} }
static void static void
menu_leave_handler(struct window *window, menu_leave_handler(struct window *window,
struct input *input, uint32_t time, void *data) struct input *input, uint32_t time, void *data)
{ {
menu_set_item(window, data, -200); menu_set_widget(window, data, -200);
} }
static void static void

View File

@ -29,7 +29,7 @@
#include <cairo.h> #include <cairo.h>
struct window; struct window;
struct item; struct widget;
struct display; struct display;
struct input; struct input;
struct output; struct output;
@ -194,8 +194,8 @@ typedef void (*window_drop_handler_t)(struct window *window,
struct input *input, struct input *input,
int32_t x, int32_t y, void *data); int32_t x, int32_t y, void *data);
typedef void (*window_item_focus_handler_t)(struct window *window, typedef void (*window_widget_focus_handler_t)(struct window *window,
struct item *focus, void *data); struct widget *focus, void *data);
typedef void (*window_close_handler_t)(struct window *window, void *data); typedef void (*window_close_handler_t)(struct window *window, void *data);
@ -216,19 +216,19 @@ window_create_menu(struct display *display,
void void
window_destroy(struct window *window); window_destroy(struct window *window);
struct item * struct widget *
window_add_item(struct window *window, void *data); window_add_widget(struct window *window, void *data);
typedef void (*item_func_t)(struct item *item, void *data); typedef void (*widget_func_t)(struct widget *widget, void *data);
typedef void (*data_func_t)(void *data, size_t len, typedef void (*data_func_t)(void *data, size_t len,
int32_t x, int32_t y, void *user_data); int32_t x, int32_t y, void *user_data);
void void
window_for_each_item(struct window *window, item_func_t func, void *data); window_for_each_widget(struct window *window, widget_func_t func, void *data);
struct item * struct widget *
window_get_focus_item(struct window *window); window_get_focus_widget(struct window *window);
struct display * struct display *
window_get_display(struct window *window); window_get_display(struct window *window);
@ -335,8 +335,8 @@ window_set_keyboard_focus_handler(struct window *window,
window_keyboard_focus_handler_t handler); window_keyboard_focus_handler_t handler);
void void
window_set_item_focus_handler(struct window *window, window_set_widget_focus_handler(struct window *window,
window_item_focus_handler_t handler); window_widget_focus_handler_t handler);
void void
window_set_data_handler(struct window *window, window_set_data_handler(struct window *window,
@ -357,14 +357,14 @@ const char *
window_get_title(struct window *window); window_get_title(struct window *window);
void void
item_get_allocation(struct item *item, struct rectangle *allocation); widget_get_allocation(struct widget *widget, struct rectangle *allocation);
void void
item_set_allocation(struct item *item, widget_set_allocation(struct widget *widget,
int32_t x, int32_t y, int32_t width, int32_t height); int32_t x, int32_t y, int32_t width, int32_t height);
void * void *
item_get_user_data(struct item *item); widget_get_user_data(struct widget *widget);
void void
input_set_pointer_image(struct input *input, uint32_t time, int pointer); input_set_pointer_image(struct input *input, uint32_t time, int pointer);