Merge pull request #296 from acrisci/feature/view-set-position

rootston: view set position
master
Drew DeVault 7 years ago committed by GitHub
commit 8c86ddfd64

@ -73,12 +73,14 @@ struct roots_view {
void (*get_size)(struct roots_view *view, struct wlr_box *box); void (*get_size)(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 (*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(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_close(struct roots_view *view); void view_close(struct roots_view *view);
bool view_center(struct roots_view *view); bool view_center(struct roots_view *view);
void view_initialize(struct roots_view *view); void view_initialize(struct roots_view *view);

@ -14,6 +14,7 @@
#include "rootston/config.h" #include "rootston/config.h"
#include "rootston/input.h" #include "rootston/input.h"
#include "rootston/desktop.h" #include "rootston/desktop.h"
#include "rootston/view.h"
const struct roots_input_event *get_input_event(struct roots_input *input, const struct roots_input_event *get_input_event(struct roots_input *input,
uint32_t serial) { uint32_t serial) {
@ -103,32 +104,40 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
break; break;
case ROOTS_CURSOR_MOVE: case ROOTS_CURSOR_MOVE:
if (input->active_view) { if (input->active_view) {
int dx = input->cursor->x - input->offs_x, double dx = input->cursor->x - input->offs_x;
dy = input->cursor->y - input->offs_y; double dy = input->cursor->y - input->offs_y;
input->active_view->x = input->view_x + dx; view_set_position(input->active_view,
input->active_view->y = input->view_y + dy; input->view_x + dx, input->view_y + dy);
} }
break; break;
case ROOTS_CURSOR_RESIZE: case ROOTS_CURSOR_RESIZE:
if (input->active_view) { if (input->active_view) {
int dx = input->cursor->x - input->offs_x, double dx = input->cursor->x - input->offs_x;
dy = input->cursor->y - input->offs_y; double dy = input->cursor->y - input->offs_y;
int width = input->view_width, double active_x = input->active_view->x;
height = input->view_height; 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) { 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; height -= dy;
} }
if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) {
height += dy; height += dy;
} }
if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { 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; width -= dx;
} }
if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { if (input->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
width += dx; 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); view_resize(input->active_view, width, height);
} }
break; break;

@ -46,6 +46,16 @@ void view_get_size(struct roots_view *view, struct wlr_box *box) {
box->height = view->wlr_surface->current->height; 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) { void view_activate(struct roots_view *view, bool activate) {
if (view->activate) { if (view->activate) {
view->activate(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)); struct roots_view *view = calloc(1, sizeof(struct roots_view));
view->type = ROOTS_WL_SHELL_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->wl_shell_surface = surface;
view->roots_wl_shell_surface = roots_surface; view->roots_wl_shell_surface = roots_surface;
view->wlr_surface = surface->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; roots_surface->view = view;
list_add(desktop->views, view); list_add(desktop->views, view);
view_initialize(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); 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) { static void close(struct roots_view *view) {
assert(view->type == ROOTS_XWAYLAND_VIEW); assert(view->type == ROOTS_XWAYLAND_VIEW);
wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface); 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->desktop = desktop;
view->activate = activate; view->activate = activate;
view->resize = resize; view->resize = resize;
view->set_position = set_position;
view->close = close; view->close = close;
roots_surface->view = view; roots_surface->view = view;
list_add(desktop->views, view); list_add(desktop->views, view);
if (!surface->override_redirect) {
view_initialize(view);
}
} }

Loading…
Cancel
Save