window: Move focus widget to struct input

dev
Kristian Høgsberg 13 years ago
parent 831dd52aa0
commit b63235142d
  1. 20
      clients/desktop-shell.c
  2. 49
      clients/window.c
  3. 5
      clients/window.h

@ -81,7 +81,7 @@ struct panel_launcher {
struct widget *widget; struct widget *widget;
struct panel *panel; struct panel *panel;
cairo_surface_t *icon; cairo_surface_t *icon;
int pressed; int focused, pressed;
const char *path; const char *path;
struct wl_list link; struct wl_list link;
}; };
@ -90,6 +90,7 @@ struct unlock_dialog {
struct window *window; struct window *window;
struct widget *widget; struct widget *widget;
struct widget *button; struct widget *button;
int button_focused;
int closing; int closing;
struct desktop *desktop; struct desktop *desktop;
@ -188,8 +189,7 @@ panel_launcher_redraw_handler(struct widget *widget, void *data)
allocation.x, allocation.y); allocation.x, allocation.y);
cairo_paint(cr); cairo_paint(cr);
if (window_get_focus_widget(launcher->panel->window) == if (launcher->focused) {
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, launcher->icon, cairo_mask_surface(cr, launcher->icon,
allocation.x, allocation.y); allocation.x, allocation.y);
@ -229,6 +229,9 @@ static int
panel_launcher_enter_handler(struct widget *widget, struct input *input, panel_launcher_enter_handler(struct widget *widget, struct input *input,
uint32_t time, int32_t x, int32_t y, void *data) uint32_t time, int32_t x, int32_t y, void *data)
{ {
struct panel_launcher *launcher = data;
launcher->focused = 1;
widget_schedule_redraw(widget); widget_schedule_redraw(widget);
return POINTER_LEFT_PTR; return POINTER_LEFT_PTR;
@ -238,6 +241,9 @@ static void
panel_launcher_leave_handler(struct widget *widget, panel_launcher_leave_handler(struct widget *widget,
struct input *input, void *data) struct input *input, void *data)
{ {
struct panel_launcher *launcher = data;
launcher->focused = 0;
widget_schedule_redraw(widget); widget_schedule_redraw(widget);
} }
@ -418,7 +424,7 @@ unlock_dialog_redraw_handler(struct widget *widget, void *data)
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_widget(dialog->window) == dialog->button) if (dialog->button_focused)
f = 1.0; f = 1.0;
else else
f = 0.7; f = 0.7;
@ -474,6 +480,9 @@ unlock_dialog_widget_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 unlock_dialog *dialog = data;
dialog->button_focused = 1;
widget_schedule_redraw(widget); widget_schedule_redraw(widget);
return POINTER_LEFT_PTR; return POINTER_LEFT_PTR;
@ -483,6 +492,9 @@ static void
unlock_dialog_widget_leave_handler(struct widget *widget, unlock_dialog_widget_leave_handler(struct widget *widget,
struct input *input, void *data) struct input *input, void *data)
{ {
struct unlock_dialog *dialog = data;
dialog->button_focused = 0;
widget_schedule_redraw(widget); widget_schedule_redraw(widget);
} }

@ -133,7 +133,6 @@ struct window {
window_close_handler_t close_handler; window_close_handler_t close_handler;
struct widget *widget; struct widget *widget;
struct widget *focus_widget;
struct window *menu; struct window *menu;
void *user_data; void *user_data;
@ -164,6 +163,7 @@ struct input {
int32_t x, y, sx, sy; int32_t x, y, sx, sy;
struct wl_list link; struct wl_list link;
struct widget *focus_widget;
struct widget *grab; struct widget *grab;
uint32_t grab_button; uint32_t grab_button;
@ -980,6 +980,8 @@ window_destroy(struct window *window)
wl_list_for_each(input, &display->input_list, link) { wl_list_for_each(input, &display->input_list, link) {
if (input->pointer_focus == window) if (input->pointer_focus == window)
input->pointer_focus = NULL; input->pointer_focus = NULL;
if (input->focus_widget->window == window)
input->focus_widget = NULL;
if (input->keyboard_focus == window) if (input->keyboard_focus == window)
input->keyboard_focus = NULL; input->keyboard_focus = NULL;
} }
@ -1061,12 +1063,6 @@ widget_destroy(struct widget *widget)
free(widget); free(widget);
} }
struct widget *
window_get_focus_widget(struct window *window)
{
return window->focus_widget;
}
void void
widget_get_allocation(struct widget *widget, struct rectangle *allocation) widget_get_allocation(struct widget *widget, struct rectangle *allocation)
{ {
@ -1428,23 +1424,23 @@ frame_create(struct window *window, void *data)
} }
static void static void
window_set_focus_widget(struct window *window, struct widget *focus, input_set_focus_widget(struct input *input, struct widget *focus,
struct input *input, uint32_t time, int32_t x, int32_t y) uint32_t time, int32_t x, int32_t y)
{ {
struct widget *old, *widget; struct widget *old, *widget;
int pointer = POINTER_LEFT_PTR; int pointer = POINTER_LEFT_PTR;
if (focus == window->focus_widget) if (focus == input->focus_widget)
return; return;
old = window->focus_widget; old = input->focus_widget;
if (old) { if (old) {
widget = old; widget = old;
if (input->grab) if (input->grab)
widget = input->grab; widget = input->grab;
if (widget->leave_handler) if (widget->leave_handler)
widget->leave_handler(old, input, widget->user_data); widget->leave_handler(old, input, widget->user_data);
window->focus_widget = NULL; input->focus_widget = NULL;
} }
if (focus) { if (focus) {
@ -1455,7 +1451,7 @@ window_set_focus_widget(struct window *window, struct widget *focus,
pointer = widget->enter_handler(focus, input, time, pointer = widget->enter_handler(focus, input, time,
x, y, x, y,
widget->user_data); widget->user_data);
window->focus_widget = focus; input->focus_widget = focus;
input_set_pointer_image(input, time, pointer); input_set_pointer_image(input, time, pointer);
} }
@ -1478,15 +1474,15 @@ input_handle_motion(void *data, struct wl_input_device *input_device,
if (!(input->grab && input->grab_button)) { if (!(input->grab && input->grab_button)) {
widget = widget_find_widget(window->widget, sx, sy); widget = widget_find_widget(window->widget, sx, sy);
window_set_focus_widget(window, widget, input, time, sx, sy); input_set_focus_widget(input, widget, time, sx, sy);
} }
if (input->grab) if (input->grab)
widget = input->grab; widget = input->grab;
else else
widget = window->focus_widget; widget = input->focus_widget;
if (widget && widget->motion_handler) if (widget && widget->motion_handler)
pointer = widget->motion_handler(window->focus_widget, pointer = widget->motion_handler(input->focus_widget,
input, time, sx, sy, input, time, sx, sy,
widget->user_data); widget->user_data);
@ -1509,8 +1505,8 @@ input_ungrab(struct input *input, uint32_t time)
if (input->pointer_focus) { if (input->pointer_focus) {
widget = widget_find_widget(input->pointer_focus->widget, widget = widget_find_widget(input->pointer_focus->widget,
input->sx, input->sy); input->sx, input->sy);
window_set_focus_widget(input->pointer_focus, widget, input_set_focus_widget(input, widget,
input, time, input->sx, input->sy); time, input->sx, input->sy);
} }
} }
@ -1520,13 +1516,12 @@ input_handle_button(void *data,
uint32_t time, uint32_t button, uint32_t state) uint32_t time, uint32_t button, uint32_t state)
{ {
struct input *input = data; struct input *input = data;
struct window *window = input->pointer_focus;
struct widget *widget; struct widget *widget;
if (window->focus_widget && input->grab == NULL && state) if (input->focus_widget && input->grab == NULL && state)
input_grab(input, window->focus_widget, button); input_grab(input, input->focus_widget, button);
widget = window->focus_widget; widget = input->focus_widget;
if (widget && widget->button_handler) if (widget && widget->button_handler)
(*input->grab->button_handler)(widget, (*input->grab->button_handler)(widget,
input, time, input, time,
@ -1575,7 +1570,7 @@ input_remove_pointer_focus(struct input *input, uint32_t time)
if (!window) if (!window)
return; return;
window_set_focus_widget(window, NULL, input, 0, 0, 0); input_set_focus_widget(input, NULL, 0, 0, 0);
input->pointer_focus = NULL; input->pointer_focus = NULL;
input->current_pointer_image = POINTER_UNSET; input->current_pointer_image = POINTER_UNSET;
@ -1605,7 +1600,7 @@ input_handle_pointer_focus(void *data,
input->sy = sy; input->sy = sy;
widget = widget_find_widget(window->widget, sx, sy); widget = widget_find_widget(window->widget, sx, sy);
window_set_focus_widget(window, widget, input, time, sx, sy); input_set_focus_widget(input, widget, time, sx, sy);
} }
} }
@ -1723,6 +1718,12 @@ input_get_modifiers(struct input *input)
return input->modifiers; return input->modifiers;
} }
struct widget *
input_get_focus_widget(struct input *input)
{
return input->focus_widget;
}
struct data_offer { struct data_offer {
struct wl_data_offer *offer; struct wl_data_offer *offer;
struct input *input; struct input *input;

@ -218,8 +218,6 @@ window_add_widget(struct window *window, 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);
struct widget *
window_get_focus_widget(struct window *window);
struct display * struct display *
window_get_display(struct window *window); window_get_display(struct window *window);
void void
@ -364,6 +362,9 @@ input_grab(struct input *input, struct widget *widget, uint32_t button);
void void
input_ungrab(struct input *input, uint32_t time); input_ungrab(struct input *input, uint32_t time);
struct widget *
input_get_focus_widget(struct input *input);
struct wl_input_device * struct wl_input_device *
input_get_input_device(struct input *input); input_get_input_device(struct input *input);

Loading…
Cancel
Save