mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 21:05:58 +01:00
Add view_resize
This commit is contained in:
parent
97679b8e12
commit
33a97576ca
5 changed files with 30 additions and 8 deletions
|
@ -71,6 +71,7 @@ struct roots_input {
|
|||
enum roots_cursor_mode mode;
|
||||
struct roots_view *active_view;
|
||||
int offs_x, offs_y;
|
||||
uint32_t resize_edges;
|
||||
|
||||
// Ring buffer of input events that could trigger move/resize/rotate
|
||||
int input_events_idx;
|
||||
|
@ -111,6 +112,6 @@ const struct roots_input_event *get_input_event(struct roots_input *input,
|
|||
void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
|
||||
struct roots_view *view);
|
||||
void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
|
||||
struct roots_view *view);
|
||||
struct roots_view *view, uint32_t edges);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -63,9 +63,11 @@ struct roots_view {
|
|||
// elsewhere
|
||||
void (*get_input_bounds)(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 view_get_input_bounds(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);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,10 +30,12 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
|
|||
}
|
||||
|
||||
void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
|
||||
struct roots_view *view) {
|
||||
struct roots_view *view, uint32_t edges) {
|
||||
input->mode = ROOTS_CURSOR_RESIZE;
|
||||
input->offs_x = cursor->x - view->x;
|
||||
input->offs_y = cursor->y - view->y;
|
||||
wlr_log(L_DEBUG, "begin resize");
|
||||
input->offs_x = cursor->x - (double)view->wlr_surface->current.width - view->x;
|
||||
input->offs_y = cursor->y - (double)view->wlr_surface->current.height - view->y;
|
||||
input->resize_edges = edges;
|
||||
wlr_seat_pointer_clear_focus(input->wl_seat);
|
||||
}
|
||||
|
||||
|
@ -61,9 +63,11 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
|
|||
}
|
||||
break;
|
||||
case ROOTS_CURSOR_RESIZE:
|
||||
// TODO: this is just for testing
|
||||
if (input->active_view && input->active_view->type == ROOTS_XDG_SHELL_V6_VIEW) {
|
||||
wlr_xdg_toplevel_v6_set_size(input->active_view->xdg_surface_v6, input->cursor->x - input->offs_x, input->cursor->y - input->offs_y);
|
||||
if (input->active_view) {
|
||||
// TODO: edges
|
||||
uint32_t width = input->cursor->x - input->offs_x;
|
||||
uint32_t height = input->cursor->y - input->offs_y;
|
||||
view_resize(input->active_view, width, height);
|
||||
}
|
||||
break;
|
||||
case ROOTS_CURSOR_ROTATE:
|
||||
|
|
|
@ -41,6 +41,12 @@ void view_activate(struct roots_view *view, bool activate) {
|
|||
}
|
||||
}
|
||||
|
||||
void view_resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
||||
if (view->resize) {
|
||||
view->resize(view, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
struct roots_view *view_at(struct roots_desktop *desktop, int x, int y) {
|
||||
for (size_t i = 0; i < desktop->views->length; ++i) {
|
||||
struct roots_view *view = desktop->views->items[i];
|
||||
|
|
|
@ -29,6 +29,14 @@ static void activate(struct roots_view *view, bool active) {
|
|||
}
|
||||
}
|
||||
|
||||
static void resize(struct roots_view *view, uint32_t width, uint32_t height) {
|
||||
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
|
||||
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
|
||||
if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
||||
wlr_xdg_toplevel_v6_set_size(surf, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_request_move(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
||||
wl_container_of(listener, roots_xdg_surface, request_move);
|
||||
|
@ -52,7 +60,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
|
|||
if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
|
||||
return;
|
||||
}
|
||||
view_begin_resize(input, event->cursor, view);
|
||||
view_begin_resize(input, event->cursor, view, e->edges);
|
||||
}
|
||||
|
||||
static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||
|
@ -102,6 +110,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
|
|||
view->wlr_surface = surface->surface;
|
||||
view->get_input_bounds = get_input_bounds;
|
||||
view->activate = activate;
|
||||
view->resize = resize;
|
||||
view->desktop = desktop;
|
||||
roots_surface->view = view;
|
||||
list_add(desktop->views, view);
|
||||
|
|
Loading…
Reference in a new issue