mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-23 10:29:49 +01:00
make it work with rotation
This commit is contained in:
parent
d13114520a
commit
4183271475
5 changed files with 85 additions and 34 deletions
|
@ -30,8 +30,8 @@ struct roots_seat_view {
|
||||||
struct roots_view *view;
|
struct roots_view *view;
|
||||||
|
|
||||||
bool has_button_grab;
|
bool has_button_grab;
|
||||||
double grab_vx;
|
double grab_sx;
|
||||||
double grab_vy;
|
double grab_sy;
|
||||||
|
|
||||||
struct wl_list link; // roots_seat::views
|
struct wl_list link; // roots_seat::views
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,6 @@ struct roots_view {
|
||||||
};
|
};
|
||||||
|
|
||||||
void view_get_box(const struct roots_view *view, struct wlr_box *box);
|
void view_get_box(const struct roots_view *view, struct wlr_box *box);
|
||||||
void view_get_deco_box(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_move(struct roots_view *view, double x, double y);
|
void view_move(struct roots_view *view, double x, double y);
|
||||||
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);
|
||||||
|
@ -134,4 +133,17 @@ bool view_center(struct roots_view *view);
|
||||||
void view_setup(struct roots_view *view);
|
void view_setup(struct roots_view *view);
|
||||||
void view_teardown(struct roots_view *view);
|
void view_teardown(struct roots_view *view);
|
||||||
|
|
||||||
|
void view_get_deco_box(const struct roots_view *view, struct wlr_box *box);
|
||||||
|
|
||||||
|
enum wlr_deco_part {
|
||||||
|
WLR_DECO_PART_NONE = 0,
|
||||||
|
WLR_DECO_PART_TOP_BORDER = (1 << 0),
|
||||||
|
WLR_DECO_PART_BOTTOM_BORDER = (1 << 1),
|
||||||
|
WLR_DECO_PART_LEFT_BORDER = (1 << 2),
|
||||||
|
WLR_DECO_PART_RIGHT_BORDER = (1 << 3),
|
||||||
|
WLR_DECO_PART_TITLEBAR = (1 << 4),
|
||||||
|
};
|
||||||
|
|
||||||
|
enum wlr_deco_part view_get_deco_part(struct roots_view *view, double sx, double sy);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,25 +30,27 @@ void roots_cursor_destroy(struct roots_cursor *cursor) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
static void seat_view_deco_motion(struct roots_seat_view *view, double deco_vx, double deco_vy) {
|
static void seat_view_deco_motion(struct roots_seat_view *view, double deco_sx, double deco_sy) {
|
||||||
struct roots_cursor *cursor = view->seat->cursor;
|
struct roots_cursor *cursor = view->seat->cursor;
|
||||||
|
|
||||||
double vx = deco_vx;
|
double sx = deco_sx;
|
||||||
double vy = deco_vy;
|
double sy = deco_sy;
|
||||||
if (view->has_button_grab) {
|
if (view->has_button_grab) {
|
||||||
vx = view->grab_vx;
|
sx = view->grab_sx;
|
||||||
vy = view->grab_vy;
|
sy = view->grab_sy;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_titlebar = vy < 0 && -vy < view->view->titlebar_height;
|
enum wlr_deco_part parts = view_get_deco_part(view->view, sx, sy);
|
||||||
|
|
||||||
|
bool is_titlebar = (parts & WLR_DECO_PART_TITLEBAR);
|
||||||
uint32_t edges = 0;
|
uint32_t edges = 0;
|
||||||
if (vx < 0) {
|
if (parts & WLR_DECO_PART_LEFT_BORDER) {
|
||||||
edges |= WLR_EDGE_LEFT;
|
edges |= WLR_EDGE_LEFT;
|
||||||
} else if (vx > view->view->wlr_surface->current->width) {
|
} else if (parts & WLR_DECO_PART_RIGHT_BORDER) {
|
||||||
edges |= WLR_EDGE_RIGHT;
|
edges |= WLR_EDGE_RIGHT;
|
||||||
} else if (vy > view->view->wlr_surface->current->height) {
|
} else if (parts & WLR_DECO_PART_BOTTOM_BORDER) {
|
||||||
edges |= WLR_EDGE_BOTTOM;
|
edges |= WLR_EDGE_BOTTOM;
|
||||||
} else if (-vy > view->view->titlebar_height) {
|
} else if (parts & WLR_DECO_PART_TOP_BORDER) {
|
||||||
edges |= WLR_EDGE_TOP;
|
edges |= WLR_EDGE_TOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,12 +77,12 @@ static void seat_view_deco_leave(struct roots_seat_view *view) {
|
||||||
view->has_button_grab = false;
|
view->has_button_grab = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void seat_view_deco_button(struct roots_seat_view *view, double vx,
|
static void seat_view_deco_button(struct roots_seat_view *view, double sx,
|
||||||
double vy, uint32_t button, uint32_t state) {
|
double sy, uint32_t button, uint32_t state) {
|
||||||
if (button == BTN_LEFT && state == WLR_BUTTON_PRESSED) {
|
if (button == BTN_LEFT && state == WLR_BUTTON_PRESSED) {
|
||||||
view->has_button_grab = true;
|
view->has_button_grab = true;
|
||||||
view->grab_vx = vx;
|
view->grab_sx = sx;
|
||||||
view->grab_vy = vy;
|
view->grab_sy = sy;
|
||||||
} else {
|
} else {
|
||||||
view->has_button_grab = false;
|
view->has_button_grab = false;
|
||||||
}
|
}
|
||||||
|
@ -117,9 +119,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
|
||||||
if (view && !surface) {
|
if (view && !surface) {
|
||||||
if (seat_view) {
|
if (seat_view) {
|
||||||
cursor->pointer_view = seat_view;
|
cursor->pointer_view = seat_view;
|
||||||
seat_view_deco_motion(seat_view,
|
seat_view_deco_motion(seat_view, sx, sy);
|
||||||
cursor->cursor->x - seat_view->view->x,
|
|
||||||
cursor->cursor->y - seat_view->view->y);
|
|
||||||
}
|
}
|
||||||
} if (view && surface) {
|
} if (view && surface) {
|
||||||
// motion over a view surface
|
// motion over a view surface
|
||||||
|
@ -239,10 +239,7 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
|
||||||
|
|
||||||
if (view && !surface) {
|
if (view && !surface) {
|
||||||
if (cursor->pointer_view) {
|
if (cursor->pointer_view) {
|
||||||
seat_view_deco_button(cursor->pointer_view,
|
seat_view_deco_button(cursor->pointer_view, sx, sy, button, state);
|
||||||
cursor->cursor->x - cursor->pointer_view->view->x,
|
|
||||||
cursor->cursor->y - cursor->pointer_view->view->y,
|
|
||||||
button, state);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "rootston/server.h"
|
#include "rootston/server.h"
|
||||||
#include "rootston/seat.h"
|
#include "rootston/seat.h"
|
||||||
#include "rootston/xcursor.h"
|
#include "rootston/xcursor.h"
|
||||||
|
#include "rootston/view.h"
|
||||||
|
|
||||||
void view_get_box(const struct roots_view *view, struct wlr_box *box) {
|
void view_get_box(const struct roots_view *view, struct wlr_box *box) {
|
||||||
box->x = view->x;
|
box->x = view->x;
|
||||||
|
@ -43,6 +44,43 @@ void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) {
|
||||||
box->height += (view->border_width * 2 + view->titlebar_height);
|
box->height += (view->border_width * 2 + view->titlebar_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum wlr_deco_part view_get_deco_part(struct roots_view *view, double sx, double sy) {
|
||||||
|
if (!view->decorated) {
|
||||||
|
return WLR_DECO_PART_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sw = view->wlr_surface->current->width;
|
||||||
|
int sh = view->wlr_surface->current->height;
|
||||||
|
int bw = view->border_width;
|
||||||
|
int titlebar_h = view->titlebar_height;
|
||||||
|
|
||||||
|
if (sx > 0 && sx < sw && sy < 0 && sy > -view->titlebar_height) {
|
||||||
|
return WLR_DECO_PART_TITLEBAR;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum wlr_deco_part parts = 0;
|
||||||
|
if (sy >= -(titlebar_h + bw) &&
|
||||||
|
sy <= sh + bw) {
|
||||||
|
if (sx < 0 && sx > -bw) {
|
||||||
|
parts |= WLR_DECO_PART_LEFT_BORDER;
|
||||||
|
} else if (sx > sw && sx < sw + bw) {
|
||||||
|
parts |= WLR_DECO_PART_RIGHT_BORDER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sx >= -bw && sx <= sw + bw) {
|
||||||
|
if (sy > sh && sy <= sh + bw) {
|
||||||
|
parts |= WLR_DECO_PART_BOTTOM_BORDER;
|
||||||
|
} else if (sy >= -(titlebar_h + bw) && sy < 0) {
|
||||||
|
parts |= WLR_DECO_PART_TOP_BORDER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO corners
|
||||||
|
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
static void view_update_output(const struct roots_view *view,
|
static void view_update_output(const struct roots_view *view,
|
||||||
const struct wlr_box *before) {
|
const struct wlr_box *before) {
|
||||||
struct roots_desktop *desktop = view->desktop;
|
struct roots_desktop *desktop = view->desktop;
|
||||||
|
@ -359,6 +397,12 @@ static bool view_at(struct roots_view *view, double lx, double ly,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (view_get_deco_part(view, view_sx, view_sy)) {
|
||||||
|
*sx = view_sx;
|
||||||
|
*sy = view_sy;
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
if (wlr_box_contains_point(&box, view_sx, view_sy) &&
|
if (wlr_box_contains_point(&box, view_sx, view_sy) &&
|
||||||
pixman_region32_contains_point(&view->wlr_surface->current->input,
|
pixman_region32_contains_point(&view->wlr_surface->current->input,
|
||||||
view_sx, view_sy, NULL)) {
|
view_sx, view_sy, NULL)) {
|
||||||
|
@ -392,14 +436,6 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx,
|
||||||
if (view_at(view, lx, ly, surface, sx, sy)) {
|
if (view_at(view, lx, ly, surface, sx, sy)) {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view->decorated) {
|
|
||||||
struct wlr_box deco_box;
|
|
||||||
view_get_deco_box(view, &deco_box);
|
|
||||||
if (wlr_box_contains_point(&deco_box, lx, ly)) {
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,8 +158,14 @@ static void render_decorations(struct roots_view *view,
|
||||||
}
|
}
|
||||||
struct wlr_box deco_box;
|
struct wlr_box deco_box;
|
||||||
view_get_deco_box(view, &deco_box);
|
view_get_deco_box(view, &deco_box);
|
||||||
double ox = deco_box.x;
|
double sx = deco_box.x - view->x;
|
||||||
double oy = deco_box.y;
|
double sy = deco_box.y - view->y;
|
||||||
|
rotate_child_position(&sx, &sy, deco_box.width, deco_box.height,
|
||||||
|
view->wlr_surface->current->width,
|
||||||
|
view->wlr_surface->current->height, view->rotation);
|
||||||
|
double ox = sx + view->x;
|
||||||
|
double oy = sy + view->y;
|
||||||
|
|
||||||
wlr_output_layout_output_coords(desktop->layout, output, &ox, &oy);
|
wlr_output_layout_output_coords(desktop->layout, output, &ox, &oy);
|
||||||
ox *= output->scale;
|
ox *= output->scale;
|
||||||
oy *= output->scale;
|
oy *= output->scale;
|
||||||
|
|
Loading…
Reference in a new issue