Merge branch 'master' into feature/data-device-selection

This commit is contained in:
Tony Crisci 2017-10-17 16:01:17 -04:00
commit b7c622a319
16 changed files with 170 additions and 85 deletions

View file

@ -86,10 +86,16 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
case ROOTS_CURSOR_PASSTHROUGH:
view = view_at(desktop, input->cursor->x, input->cursor->y, &surface,
&sx, &sy);
if (view != input->client_cursor_view) {
bool set_compositor_cursor = !view && input->cursor_client;
if (view) {
struct wl_client *view_client =
wl_resource_get_client(view->wlr_surface->resource);
set_compositor_cursor = view_client != input->cursor_client;
}
if (set_compositor_cursor) {
wlr_log(L_DEBUG, "Switching to compositor cursor");
cursor_set_xcursor_image(input, input->xcursor->images[0]);
input->client_cursor_view = NULL;
input->cursor_client = NULL;
}
if (view) {
wlr_seat_pointer_notify_enter(input->wl_seat, surface, sx, sy);
@ -355,18 +361,16 @@ static void handle_request_set_cursor(struct wl_listener *listener,
request_set_cursor);
struct wlr_seat_pointer_request_set_cursor_event *event = data;
struct wlr_surface *focused_surface = NULL;
double sx, sy;
struct roots_view *focused_view = view_at(input->server->desktop,
input->cursor->x, input->cursor->y, &focused_surface, &sx, &sy);
bool ok = focused_surface != NULL;
if (focused_surface != NULL) {
struct wlr_surface *focused_surface =
event->seat_handle->wlr_seat->pointer_state.focused_surface;
bool ok = focused_surface != NULL && focused_surface->resource != NULL;
if (ok) {
struct wl_client *focused_client =
wl_resource_get_client(focused_surface->resource);
ok = event->client == focused_client;
}
if (!ok) {
wlr_log(L_DEBUG, "Denying request to set cursor outside view");
wlr_log(L_DEBUG, "Denying request to set cursor from unfocused client");
return;
}
@ -378,7 +382,7 @@ static void handle_request_set_cursor(struct wl_listener *listener,
event->hotspot_x, event->hotspot_y);
}
input->client_cursor_view = focused_view;
input->cursor_client = event->client;
}
void cursor_initialize(struct roots_input *input) {

View file

@ -67,35 +67,42 @@ void view_close(struct roots_view *view) {
bool view_center(struct roots_view *view) {
struct wlr_box size;
view_get_size(view, &size);
if (size.width == 0 && size.height == 0) {
return false;
}
struct roots_desktop *desktop = view->desktop;
struct wlr_cursor *cursor = desktop->server->input->cursor;
struct wlr_output *output = wlr_output_layout_output_at(desktop->layout,
cursor->x, cursor->y);
const struct wlr_output_layout_output *output_layout =
wlr_output_layout_get(desktop->layout, output);
struct wlr_output *output =
wlr_output_layout_output_at(desktop->layout, cursor->x, cursor->y);
if (!output) {
output = wlr_output_layout_get_center_output(desktop->layout);
}
if (!output) {
// empty layout
return false;
}
view->x = (double)(output->width - size.width) / 2
+ output_layout->x;
view->y = (double)(output->height - size.height) / 2
+ output_layout->y;
const struct wlr_output_layout_output *l_output =
wlr_output_layout_get(desktop->layout, output);
int width, height;
wlr_output_effective_resolution(output, &width, &height);
view->x = (double)(width - size.width) / 2
+ l_output->x;
view->y = (double)(height - size.height) / 2
+ l_output->y;
return true;
}
bool view_initialize(struct roots_view *view) {
bool centered = view_center(view);
if (centered) {
struct roots_input *input = view->desktop->server->input;
set_view_focus(input, view->desktop, view);
wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface);
}
return centered;
void view_initialize(struct roots_view *view) {
view_center(view);
struct roots_input *input = view->desktop->server->input;
set_view_focus(input, view->desktop, view);
wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface);
}
struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,

View file

@ -50,14 +50,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
}
static void handle_surface_commit(struct wl_listener *listener, void *data) {
struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, surface_commit);
struct roots_view *view = roots_surface->view;
if (view->wl_shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL &&
!roots_surface->initialized) {
roots_surface->initialized = view_initialize(view);
}
// TODO do we need to do anything here?
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@ -137,4 +130,5 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
view->desktop = desktop;
roots_surface->view = view;
list_add(desktop->views, view);
view_initialize(view);
}

View file

@ -68,14 +68,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
}
static void handle_commit(struct wl_listener *listener, void *data) {
struct roots_xdg_surface_v6 *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, commit);
struct roots_view *view = roots_xdg_surface->view;
if (view->xdg_surface_v6->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL &&
!roots_xdg_surface->initialized) {
roots_xdg_surface->initialized = view_initialize(view);
}
// TODO is there anything we need to do here?
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@ -141,4 +134,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->desktop = desktop;
roots_surface->view = view;
list_add(desktop->views, view);
view_initialize(view);
}