It's a widget.
struct background *background;
};
-struct panel_item {
- struct item *item;
+struct panel_widget {
+ struct widget *widget;
struct panel *panel;
cairo_surface_t *icon;
int pressed;
struct unlock_dialog {
struct window *window;
- struct item *button;
+ struct widget *button;
int closing;
struct desktop *desktop;
}
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;
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;
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);
}
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);
}
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);
}
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);
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
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;
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);
{
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);
}
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);
}
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));
}
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);
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;
struct wl_list link;
};
-struct item {
+struct widget {
struct wl_list link;
struct rectangle allocation;
void *user_data;
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
}
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
{
struct input *input = data;
struct window *window = input->pointer_focus;
- struct item *item;
+ struct widget *widget;
int pointer = POINTER_LEFT_PTR;
input->x = x;
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)
{
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);
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);
}
}
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);
{
struct input *input = data;
struct window *window;
- struct item *item;
+ struct widget *widget;
int pointer;
window = input->pointer_focus;
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);
}
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
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
}
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;
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
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
#include <cairo.h>
struct window;
-struct item;
+struct widget;
struct display;
struct input;
struct output;
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);
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);
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,
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);