diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-10-19 13:12:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-19 13:12:37 -0400 |
commit | 8c86ddfd64f4e0a6c02dc21940d905b2427d1b29 (patch) | |
tree | 87b1d253480a5a2ef64cc99e5874e363aed21a40 | |
parent | 0536ea3c47fbfcc68fc28e09d745872564b30343 (diff) | |
parent | 169bc216ed1b4909b1635faea1239863416b679e (diff) |
Merge pull request #296 from acrisci/feature/view-set-position
rootston: view set position
-rw-r--r-- | include/rootston/view.h | 2 | ||||
-rw-r--r-- | rootston/cursor.c | 29 | ||||
-rw-r--r-- | rootston/desktop.c | 10 | ||||
-rw-r--r-- | rootston/wl_shell.c | 26 | ||||
-rw-r--r-- | rootston/xwayland.c | 14 |
5 files changed, 58 insertions, 23 deletions
diff --git a/include/rootston/view.h b/include/rootston/view.h index a4fb6f01..ad722225 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -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); diff --git a/rootston/cursor.c b/rootston/cursor.c index 65109534..b312392d 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -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; diff --git a/rootston/desktop.c b/rootston/desktop.c index a7137255..641315a8 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -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); diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 33f54a32..2c6047b1 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -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); + } + } } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index c32ee15b..d7885e94 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -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); + } } |