window: Rename item to widget

It's a widget.
dev
Kristian Høgsberg 13 years ago
parent 4f7dcd6eb1
commit c51f79954b
  1. 76
      clients/desktop-shell.c
  2. 136
      clients/window.c
  3. 30
      clients/window.h

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

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

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

Loading…
Cancel
Save