mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-23 18:39:48 +01:00
Handle output enter/leave correctly
This commit is contained in:
parent
9861add146
commit
a6930cd8ea
6 changed files with 51 additions and 32 deletions
|
@ -48,7 +48,6 @@ enum roots_view_type {
|
||||||
|
|
||||||
struct roots_view {
|
struct roots_view {
|
||||||
struct roots_desktop *desktop;
|
struct roots_desktop *desktop;
|
||||||
struct roots_output *output;
|
|
||||||
double x, y;
|
double x, y;
|
||||||
float rotation;
|
float rotation;
|
||||||
// TODO: Something for roots-enforced width/height
|
// TODO: Something for roots-enforced width/height
|
||||||
|
@ -72,14 +71,14 @@ struct roots_view {
|
||||||
// configure event from the xdg_shell
|
// configure event from the xdg_shell
|
||||||
// If not then this should follow the typical type/impl pattern we use
|
// If not then this should follow the typical type/impl pattern we use
|
||||||
// elsewhere
|
// elsewhere
|
||||||
void (*get_size)(struct roots_view *view, struct wlr_box *box);
|
void (*get_size)(const struct roots_view *view, struct wlr_box *box);
|
||||||
void (*activate)(struct roots_view *view, bool active);
|
void (*activate)(struct roots_view *view, bool active);
|
||||||
void (*resize)(struct roots_view *view, uint32_t width, uint32_t height);
|
void (*resize)(struct roots_view *view, uint32_t width, uint32_t height);
|
||||||
void (*set_position)(struct roots_view *view, double x, double y);
|
void (*set_position)(struct roots_view *view, double x, double y);
|
||||||
void (*close)(struct roots_view *view);
|
void (*close)(struct roots_view *view);
|
||||||
};
|
};
|
||||||
|
|
||||||
void view_get_size(struct roots_view *view, struct wlr_box *box);
|
void view_get_size(const struct roots_view *view, struct wlr_box *box);
|
||||||
void view_activate(struct roots_view *view, bool active);
|
void view_activate(struct roots_view *view, bool active);
|
||||||
void view_resize(struct roots_view *view, uint32_t width, uint32_t height);
|
void view_resize(struct roots_view *view, uint32_t width, uint32_t height);
|
||||||
void view_set_position(struct roots_view *view, double x, double y);
|
void view_set_position(struct roots_view *view, double x, double y);
|
||||||
|
|
|
@ -139,4 +139,7 @@ struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface,
|
||||||
void wlr_surface_send_enter(struct wlr_surface *surface,
|
void wlr_surface_send_enter(struct wlr_surface *surface,
|
||||||
struct wlr_output *output);
|
struct wlr_output *output);
|
||||||
|
|
||||||
|
void wlr_surface_send_leave(struct wlr_surface *surface,
|
||||||
|
struct wlr_output *output);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,45 +35,52 @@ void view_destroy(struct roots_view *view) {
|
||||||
free(view);
|
free(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
void view_get_size(struct roots_view *view, struct wlr_box *box) {
|
void view_get_size(const struct roots_view *view, struct wlr_box *box) {
|
||||||
if (view->get_size) {
|
if (view->get_size) {
|
||||||
view->get_size(view, box);
|
view->get_size(view, box);
|
||||||
return;
|
} else {
|
||||||
|
box->width = view->wlr_surface->current->width;
|
||||||
|
box->height = view->wlr_surface->current->height;
|
||||||
}
|
}
|
||||||
box->x = box->y = 0;
|
box->x = view->x;
|
||||||
box->width = view->wlr_surface->current->width;
|
box->y = view->y;
|
||||||
box->height = view->wlr_surface->current->height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void view_update_output(struct roots_view *view) {
|
static void view_update_output(const struct roots_view *view,
|
||||||
|
const struct wlr_box *before) {
|
||||||
struct roots_desktop *desktop = view->desktop;
|
struct roots_desktop *desktop = view->desktop;
|
||||||
struct roots_output *output = NULL, *_output;
|
struct roots_output *output;
|
||||||
struct wlr_box box;
|
struct wlr_box box;
|
||||||
view_get_size(view, &box);
|
view_get_size(view, &box);
|
||||||
wl_list_for_each(_output, &desktop->outputs, link) {
|
wl_list_for_each(output, &desktop->outputs, link) {
|
||||||
if (!wlr_output_layout_intersects(desktop->layout, _output->wlr_output,
|
bool intersected = before->x != -1 && wlr_output_layout_intersects(
|
||||||
view->x, view->y, view->x + box.width, view->x + box.height)) {
|
desktop->layout, output->wlr_output,
|
||||||
continue;
|
before->x, before->y, before->x + before->width,
|
||||||
|
before->y + before->height);
|
||||||
|
bool intersects = wlr_output_layout_intersects(
|
||||||
|
desktop->layout, output->wlr_output,
|
||||||
|
view->x, view->y, view->x + box.width, view->y + box.height);
|
||||||
|
if (intersected && !intersects) {
|
||||||
|
wlr_log(L_DEBUG, "Leaving output %s", output->wlr_output->name);
|
||||||
|
wlr_surface_send_leave(view->wlr_surface, output->wlr_output);
|
||||||
}
|
}
|
||||||
if (output == NULL
|
if (!intersected && intersects) {
|
||||||
|| output->wlr_output->scale < _output->wlr_output->scale) {
|
wlr_log(L_DEBUG, "Entering output %s", output->wlr_output->name);
|
||||||
output = _output;
|
wlr_surface_send_enter(view->wlr_surface, output->wlr_output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (output && output != view->output) {
|
|
||||||
view->output = output;
|
|
||||||
wlr_surface_send_enter(view->wlr_surface, output->wlr_output);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void view_set_position(struct roots_view *view, double x, double y) {
|
void view_set_position(struct roots_view *view, double x, double y) {
|
||||||
|
struct wlr_box before;
|
||||||
|
view_get_size(view, &before);
|
||||||
if (view->set_position) {
|
if (view->set_position) {
|
||||||
view->set_position(view, x, y);
|
view->set_position(view, x, y);
|
||||||
} else {
|
} else {
|
||||||
view->x = x;
|
view->x = x;
|
||||||
view->y = y;
|
view->y = y;
|
||||||
}
|
}
|
||||||
view_update_output(view);
|
view_update_output(view, &before);
|
||||||
}
|
}
|
||||||
|
|
||||||
void view_activate(struct roots_view *view, bool activate) {
|
void view_activate(struct roots_view *view, bool activate) {
|
||||||
|
@ -83,10 +90,12 @@ void view_activate(struct roots_view *view, bool activate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void view_resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
void view_resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
||||||
|
struct wlr_box before;
|
||||||
|
view_get_size(view, &before);
|
||||||
if (view->resize) {
|
if (view->resize) {
|
||||||
view->resize(view, width, height);
|
view->resize(view, width, height);
|
||||||
}
|
}
|
||||||
view_update_output(view);
|
view_update_output(view, &before);
|
||||||
}
|
}
|
||||||
|
|
||||||
void view_close(struct roots_view *view) {
|
void view_close(struct roots_view *view) {
|
||||||
|
@ -96,8 +105,8 @@ void view_close(struct roots_view *view) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool view_center(struct roots_view *view) {
|
bool view_center(struct roots_view *view) {
|
||||||
struct wlr_box size;
|
struct wlr_box box;
|
||||||
view_get_size(view, &size);
|
view_get_size(view, &box);
|
||||||
|
|
||||||
struct roots_desktop *desktop = view->desktop;
|
struct roots_desktop *desktop = view->desktop;
|
||||||
struct wlr_cursor *cursor = desktop->server->input->cursor;
|
struct wlr_cursor *cursor = desktop->server->input->cursor;
|
||||||
|
@ -122,16 +131,14 @@ bool view_center(struct roots_view *view) {
|
||||||
|
|
||||||
double view_x = (double)(width - size.width) / 2 + l_output->x;
|
double view_x = (double)(width - size.width) / 2 + l_output->x;
|
||||||
double view_y = (double)(height - size.height) / 2 + l_output->y;
|
double view_y = (double)(height - size.height) / 2 + l_output->y;
|
||||||
|
|
||||||
view_set_position(view, view_x, view_y);
|
view_set_position(view, view_x, view_y);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void view_setup(struct roots_view *view) {
|
void view_initialize(struct roots_view *view) {
|
||||||
view_center(view);
|
|
||||||
|
|
||||||
struct roots_input *input = view->desktop->server->input;
|
struct roots_input *input = view->desktop->server->input;
|
||||||
|
view_center(view);
|
||||||
set_view_focus(input, view->desktop, view);
|
set_view_focus(input, view->desktop, view);
|
||||||
wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface);
|
wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface);
|
||||||
view_update_output(view);
|
view_update_output(view);
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "rootston/server.h"
|
#include "rootston/server.h"
|
||||||
#include "rootston/input.h"
|
#include "rootston/input.h"
|
||||||
|
|
||||||
static void get_size(struct roots_view *view, struct wlr_box *box) {
|
static void get_size(const struct roots_view *view, struct wlr_box *box) {
|
||||||
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
|
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
|
||||||
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
|
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
|
||||||
// TODO: surf->geometry can be NULL
|
// TODO: surf->geometry can be NULL
|
||||||
|
|
|
@ -43,7 +43,6 @@ static void wl_output_send_to_resource(struct wl_resource *resource) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) {
|
if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) {
|
||||||
wlr_log(L_DEBUG, "Sending scale");
|
|
||||||
wl_output_send_scale(resource, output->scale);
|
wl_output_send_scale(resource, output->scale);
|
||||||
}
|
}
|
||||||
if (version >= WL_OUTPUT_DONE_SINCE_VERSION) {
|
if (version >= WL_OUTPUT_DONE_SINCE_VERSION) {
|
||||||
|
|
|
@ -901,9 +901,20 @@ void wlr_surface_send_enter(struct wlr_surface *surface,
|
||||||
struct wl_resource *resource;
|
struct wl_resource *resource;
|
||||||
wl_resource_for_each(resource, &output->wl_resources) {
|
wl_resource_for_each(resource, &output->wl_resources) {
|
||||||
if (client == wl_resource_get_client(resource)) {
|
if (client == wl_resource_get_client(resource)) {
|
||||||
wlr_log(L_DEBUG, "sending output enter");
|
|
||||||
wl_surface_send_enter(surface->resource, resource);
|
wl_surface_send_enter(surface->resource, resource);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wlr_surface_send_leave(struct wlr_surface *surface,
|
||||||
|
struct wlr_output *output) {
|
||||||
|
struct wl_client *client = wl_resource_get_client(surface->resource);
|
||||||
|
struct wl_resource *resource;
|
||||||
|
wl_resource_for_each(resource, &output->wl_resources) {
|
||||||
|
if (client == wl_resource_get_client(resource)) {
|
||||||
|
wl_surface_send_leave(surface->resource, resource);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue