rootston: view set position
This commit is contained in:
parent
0536ea3c47
commit
169bc216ed
|
@ -73,12 +73,14 @@ struct roots_view {
|
|||
void (*get_size)(struct roots_view *view, struct wlr_box *box);
|
||||
void (*activate)(struct roots_view *view, bool active);
|
||||
void (*resize)(struct roots_view *view, uint32_t width, uint32_t height);
|
||||
void (*set_position)(struct roots_view *view, double x, double y);
|
||||
void (*close)(struct roots_view *view);
|
||||
};
|
||||
|
||||
void view_get_size(struct roots_view *view, struct wlr_box *box);
|
||||
void view_activate(struct roots_view *view, bool active);
|
||||
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_close(struct roots_view *view);
|
||||
bool view_center(struct roots_view *view);
|
||||
void view_initialize(struct roots_view *view);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "rootston/config.h"
|
||||
#include "rootston/input.h"
|
||||
#include "rootston/desktop.h"
|
||||
#include "rootston/view.h"
|
||||
|
||||
const struct roots_input_event *get_input_event(struct roots_input *input,
|
||||
uint32_t serial) {
|
||||
|
@ -103,32 +104,40 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
|
|||
break;
|
||||
case ROOTS_CURSOR_MOVE:
|
||||
if (input->active_view) {
|
||||
int dx = input->cursor->x - input->offs_x,
|
||||
dy = input->cursor->y - input->offs_y;
|
||||
input->active_view->x = input->view_x + dx;
|
||||
input->active_view->y = input->view_y + dy;
|
||||
double dx = input->cursor->x - input->offs_x;
|
||||
double dy = input->cursor->y - input->offs_y;
|
||||
view_set_position(input->active_view,
|
||||
input->view_x + dx, input->view_y + dy);
|
||||
}
|
||||
break;
|
||||
case ROOTS_CURSOR_RESIZE:
|
||||
if (input->active_view) {
|
||||
int dx = input->cursor->x - input->offs_x,
|
||||
dy = input->cursor->y - input->offs_y;
|
||||
int width = input->view_width,
|
||||
height = input->view_height;
|
||||
double dx = input->cursor->x - input->offs_x;
|
||||
double dy = input->cursor->y - input->offs_y;
|
||||
double active_x = input->active_view->x;
|
||||
double active_y = input->active_view->y;
|
||||
int width = input->view_width;
|
||||
int height = input->view_height;
|
||||
if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
|
||||
input->active_view->y = input->view_y + dy;
|
||||
active_y = input->view_y + dy;
|
||||
height -= dy;
|
||||
}
|
||||
if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) {
|
||||
height += dy;
|
||||
}
|
||||
if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) {
|
||||
input->active_view->x = input->view_x + dx;
|
||||
active_x = input->view_x + dx;
|
||||
width -= dx;
|
||||
}
|
||||
if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
|
||||
width += dx;
|
||||
}
|
||||
|
||||
// TODO we might need one configure event for this
|
||||
if (active_x != input->active_view->x ||
|
||||
active_y != input->active_view->y) {
|
||||
view_set_position(input->active_view, active_x, active_y);
|
||||
}
|
||||
view_resize(input->active_view, width, height);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -46,6 +46,16 @@ void view_get_size(struct roots_view *view, struct wlr_box *box) {
|
|||
box->height = view->wlr_surface->current->height;
|
||||
}
|
||||
|
||||
void view_set_position(struct roots_view *view, double x, double y) {
|
||||
if (view->set_position) {
|
||||
view->set_position(view, x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
view->x = x;
|
||||
view->y = y;
|
||||
}
|
||||
|
||||
void view_activate(struct roots_view *view, bool activate) {
|
||||
if (view->activate) {
|
||||
view->activate(view, activate);
|
||||
|
|
|
@ -109,19 +109,6 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
|
|||
struct roots_view *view = calloc(1, sizeof(struct roots_view));
|
||||
view->type = ROOTS_WL_SHELL_VIEW;
|
||||
|
||||
if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) {
|
||||
// we need to map it relative to the parent
|
||||
int i =
|
||||
list_seq_find(desktop->views,
|
||||
shell_surface_compare_equals, surface->parent);
|
||||
if (i != -1) {
|
||||
struct roots_view *parent = desktop->views->items[i];
|
||||
view->x = parent->x + surface->transient_state->x;
|
||||
view->y = parent->y + surface->transient_state->y;
|
||||
}
|
||||
} else {
|
||||
view->x = view->y = 200;
|
||||
}
|
||||
view->wl_shell_surface = surface;
|
||||
view->roots_wl_shell_surface = roots_surface;
|
||||
view->wlr_surface = surface->surface;
|
||||
|
@ -131,4 +118,17 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
|
|||
roots_surface->view = view;
|
||||
list_add(desktop->views, view);
|
||||
view_initialize(view);
|
||||
|
||||
if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) {
|
||||
// we need to map it relative to the parent
|
||||
int i =
|
||||
list_seq_find(desktop->views,
|
||||
shell_surface_compare_equals, surface->parent);
|
||||
if (i != -1) {
|
||||
struct roots_view *parent = desktop->views->items[i];
|
||||
view_set_position(view,
|
||||
parent->x + surface->transient_state->x,
|
||||
parent->y + surface->transient_state->y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,15 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
|||
xwayland_surface->x, xwayland_surface->y, width, height);
|
||||
}
|
||||
|
||||
static void set_position(struct roots_view *view, double x, double y) {
|
||||
assert(view->type == ROOTS_XWAYLAND_VIEW);
|
||||
struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface;
|
||||
view->x = x;
|
||||
view->y = y;
|
||||
wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface,
|
||||
x, y, xwayland_surface->width, xwayland_surface->height);
|
||||
}
|
||||
|
||||
static void close(struct roots_view *view) {
|
||||
assert(view->type == ROOTS_XWAYLAND_VIEW);
|
||||
wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface);
|
||||
|
@ -88,7 +97,12 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
|
|||
view->desktop = desktop;
|
||||
view->activate = activate;
|
||||
view->resize = resize;
|
||||
view->set_position = set_position;
|
||||
view->close = close;
|
||||
roots_surface->view = view;
|
||||
list_add(desktop->views, view);
|
||||
|
||||
if (!surface->override_redirect) {
|
||||
view_initialize(view);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue