Remove roots_seat_{add,remove}_view
This commit is contained in:
parent
76e8e1a6ad
commit
a8b31da52c
|
@ -15,7 +15,7 @@ struct roots_seat {
|
||||||
double touch_x, touch_y;
|
double touch_x, touch_y;
|
||||||
|
|
||||||
struct wl_list views; // roots_seat_view::link
|
struct wl_list views; // roots_seat_view::link
|
||||||
struct roots_seat_view *focus;
|
bool has_focus;
|
||||||
|
|
||||||
struct wl_list keyboards;
|
struct wl_list keyboards;
|
||||||
struct wl_list pointers;
|
struct wl_list pointers;
|
||||||
|
@ -63,16 +63,14 @@ void roots_seat_add_device(struct roots_seat *seat,
|
||||||
void roots_seat_remove_device(struct roots_seat *seat,
|
void roots_seat_remove_device(struct roots_seat *seat,
|
||||||
struct wlr_input_device *device);
|
struct wlr_input_device *device);
|
||||||
|
|
||||||
void roots_seat_add_view(struct roots_seat *seat, struct roots_view *view);
|
|
||||||
|
|
||||||
void roots_seat_remove_view(struct roots_seat *seat, struct roots_view *view);
|
|
||||||
|
|
||||||
void roots_seat_configure_cursor(struct roots_seat *seat);
|
void roots_seat_configure_cursor(struct roots_seat *seat);
|
||||||
|
|
||||||
void roots_seat_configure_xcursor(struct roots_seat *seat);
|
void roots_seat_configure_xcursor(struct roots_seat *seat);
|
||||||
|
|
||||||
bool roots_seat_has_meta_pressed(struct roots_seat *seat);
|
bool roots_seat_has_meta_pressed(struct roots_seat *seat);
|
||||||
|
|
||||||
|
struct roots_view *roots_seat_get_focused_view(struct roots_seat *seat);
|
||||||
|
|
||||||
void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view);
|
void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view);
|
||||||
|
|
||||||
void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view);
|
void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view);
|
||||||
|
|
|
@ -58,19 +58,21 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ROOTS_CURSOR_MOVE:
|
case ROOTS_CURSOR_MOVE:
|
||||||
if (seat->focus) {
|
view = roots_seat_get_focused_view(seat);
|
||||||
|
if (view != NULL) {
|
||||||
double dx = cursor->cursor->x - cursor->offs_x;
|
double dx = cursor->cursor->x - cursor->offs_x;
|
||||||
double dy = cursor->cursor->y - cursor->offs_y;
|
double dy = cursor->cursor->y - cursor->offs_y;
|
||||||
view_move(seat->focus->view, cursor->view_x + dx,
|
view_move(view, cursor->view_x + dx,
|
||||||
cursor->view_y + dy);
|
cursor->view_y + dy);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ROOTS_CURSOR_RESIZE:
|
case ROOTS_CURSOR_RESIZE:
|
||||||
if (seat->focus) {
|
view = roots_seat_get_focused_view(seat);
|
||||||
|
if (view != NULL) {
|
||||||
double dx = cursor->cursor->x - cursor->offs_x;
|
double dx = cursor->cursor->x - cursor->offs_x;
|
||||||
double dy = cursor->cursor->y - cursor->offs_y;
|
double dy = cursor->cursor->y - cursor->offs_y;
|
||||||
double active_x = seat->focus->view->x;
|
double active_x = view->x;
|
||||||
double active_y = seat->focus->view->y;
|
double active_y = view->y;
|
||||||
int width = cursor->view_width;
|
int width = cursor->view_width;
|
||||||
int height = cursor->view_height;
|
int height = cursor->view_height;
|
||||||
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
|
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
|
||||||
|
@ -99,18 +101,18 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
|
||||||
height = 0;
|
height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (active_x != seat->focus->view->x ||
|
if (active_x != view->x ||
|
||||||
active_y != seat->focus->view->y) {
|
active_y != view->y) {
|
||||||
view_move_resize(seat->focus->view, active_x, active_y,
|
view_move_resize(view, active_x, active_y,
|
||||||
width, height);
|
width, height);
|
||||||
} else {
|
} else {
|
||||||
view_resize(seat->focus->view, width, height);
|
view_resize(view, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ROOTS_CURSOR_ROTATE:
|
case ROOTS_CURSOR_ROTATE:
|
||||||
if (seat->focus) {
|
view = roots_seat_get_focused_view(seat);
|
||||||
struct roots_view *view = seat->focus->view;
|
if (view != NULL) {
|
||||||
int ox = view->x + view->wlr_surface->current->width/2,
|
int ox = view->x + view->wlr_surface->current->width/2,
|
||||||
oy = view->y + view->wlr_surface->current->height/2;
|
oy = view->y + view->wlr_surface->current->height/2;
|
||||||
int ux = cursor->offs_x - ox,
|
int ux = cursor->offs_x - ox,
|
||||||
|
@ -124,7 +126,6 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void roots_cursor_press_button(struct roots_cursor *cursor,
|
static void roots_cursor_press_button(struct roots_cursor *cursor,
|
||||||
|
|
|
@ -190,11 +190,6 @@ void view_init(struct roots_view *view, struct roots_desktop *desktop) {
|
||||||
wl_signal_init(&view->events.destroy);
|
wl_signal_init(&view->events.destroy);
|
||||||
|
|
||||||
wl_list_insert(&desktop->views, &view->link);
|
wl_list_insert(&desktop->views, &view->link);
|
||||||
|
|
||||||
struct roots_seat *seat;
|
|
||||||
wl_list_for_each(seat, &desktop->server->input->seats, link) {
|
|
||||||
roots_seat_add_view(seat, view);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void view_setup(struct roots_view *view) {
|
void view_setup(struct roots_view *view) {
|
||||||
|
|
|
@ -116,7 +116,7 @@ bool input_view_has_focus(struct roots_input *input, struct roots_view *view) {
|
||||||
}
|
}
|
||||||
struct roots_seat *seat;
|
struct roots_seat *seat;
|
||||||
wl_list_for_each(seat, &input->seats, link) {
|
wl_list_for_each(seat, &input->seats, link) {
|
||||||
if (seat->focus != NULL && seat->focus->view == view) {
|
if (view == roots_seat_get_focused_view(seat)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
113
rootston/seat.c
113
rootston/seat.c
|
@ -485,56 +485,20 @@ bool roots_seat_has_meta_pressed(struct roots_seat *seat) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view) {
|
struct roots_view *roots_seat_get_focused_view(struct roots_seat *seat) {
|
||||||
if (seat->focus != NULL && seat->focus->view == view) {
|
if (!seat->has_focus || wl_list_empty(&seat->views)) {
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
struct roots_seat_view *seat_view =
|
||||||
if (view && view->type == ROOTS_XWAYLAND_VIEW &&
|
wl_container_of(seat->views.next, seat_view, link);
|
||||||
view->xwayland_surface->override_redirect) {
|
return seat_view->view;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool found = false;
|
|
||||||
struct roots_seat_view *seat_view;
|
|
||||||
wl_list_for_each(seat_view, &seat->views, link) {
|
|
||||||
if (seat_view->view == view) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct roots_seat_view *prev_focus = seat->focus;
|
|
||||||
seat->focus = seat_view;
|
|
||||||
|
|
||||||
// unfocus the old view if it is not focused by some other seat
|
|
||||||
if (prev_focus && !input_view_has_focus(seat->input, prev_focus->view)) {
|
|
||||||
view_activate(prev_focus->view, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!seat->focus) {
|
|
||||||
seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
view_activate(view, true);
|
|
||||||
wl_list_remove(&seat_view->view->link);
|
|
||||||
wl_list_insert(&seat->input->server->desktop->views,
|
|
||||||
&seat_view->view->link);
|
|
||||||
|
|
||||||
wl_list_remove(&seat_view->link);
|
|
||||||
wl_list_insert(&seat->views, &seat_view->link);
|
|
||||||
wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void seat_view_destroy(struct roots_seat_view *seat_view) {
|
static void seat_view_destroy(struct roots_seat_view *seat_view) {
|
||||||
struct roots_seat *seat = seat_view->seat;
|
struct roots_seat *seat = seat_view->seat;
|
||||||
|
|
||||||
if (seat->focus == seat_view) {
|
if (seat_view->view == roots_seat_get_focused_view(seat)) {
|
||||||
seat->focus = NULL;
|
seat->has_focus = false;
|
||||||
seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
|
seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,11 +520,12 @@ static void seat_view_handle_destroy(struct wl_listener *listener, void *data) {
|
||||||
seat_view_destroy(seat_view);
|
seat_view_destroy(seat_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
void roots_seat_add_view(struct roots_seat *seat, struct roots_view *view) {
|
static struct roots_seat_view *seat_add_view(struct roots_seat *seat,
|
||||||
|
struct roots_view *view) {
|
||||||
struct roots_seat_view *seat_view =
|
struct roots_seat_view *seat_view =
|
||||||
calloc(1, sizeof(struct roots_seat_view));
|
calloc(1, sizeof(struct roots_seat_view));
|
||||||
if (seat_view == NULL) {
|
if (seat_view == NULL) {
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
seat_view->seat = seat;
|
seat_view->seat = seat;
|
||||||
seat_view->view = view;
|
seat_view->view = view;
|
||||||
|
@ -569,16 +534,60 @@ void roots_seat_add_view(struct roots_seat *seat, struct roots_view *view) {
|
||||||
|
|
||||||
seat_view->destroy.notify = seat_view_handle_destroy;
|
seat_view->destroy.notify = seat_view_handle_destroy;
|
||||||
wl_signal_add(&view->events.destroy, &seat_view->destroy);
|
wl_signal_add(&view->events.destroy, &seat_view->destroy);
|
||||||
|
|
||||||
|
return seat_view;
|
||||||
}
|
}
|
||||||
|
|
||||||
void roots_seat_remove_view(struct roots_seat *seat, struct roots_view *view) {
|
void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view) {
|
||||||
struct roots_seat_view *seat_view;
|
struct roots_view *prev_focus = roots_seat_get_focused_view(seat);
|
||||||
wl_list_for_each(seat_view, &seat->views, link) {
|
if (view == prev_focus) {
|
||||||
if (seat_view->view == view) {
|
return;
|
||||||
seat_view_destroy(seat_view);
|
}
|
||||||
break;
|
|
||||||
|
if (view && view->type == ROOTS_XWAYLAND_VIEW &&
|
||||||
|
view->xwayland_surface->override_redirect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct roots_seat_view *seat_view = NULL;
|
||||||
|
if (view != NULL) {
|
||||||
|
bool found = false;
|
||||||
|
wl_list_for_each(seat_view, &seat->views, link) {
|
||||||
|
if (seat_view->view == view) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
seat_view = seat_add_view(seat, view);
|
||||||
|
if (seat_view == NULL) {
|
||||||
|
wlr_log(L_ERROR, "Allocation failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
seat->has_focus = false;
|
||||||
|
|
||||||
|
// unfocus the old view if it is not focused by some other seat
|
||||||
|
if (prev_focus != NULL && !input_view_has_focus(seat->input, prev_focus)) {
|
||||||
|
view_activate(prev_focus, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (view == NULL) {
|
||||||
|
seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
view_activate(view, true);
|
||||||
|
wl_list_remove(&seat_view->view->link);
|
||||||
|
wl_list_insert(&seat->input->server->desktop->views,
|
||||||
|
&seat_view->view->link);
|
||||||
|
|
||||||
|
seat->has_focus = true;
|
||||||
|
wl_list_remove(&seat_view->link);
|
||||||
|
wl_list_insert(&seat->views, &seat_view->link);
|
||||||
|
wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) {
|
void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) {
|
||||||
|
|
Loading…
Reference in New Issue