aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rootston/cursor.h2
-rw-r--r--include/rootston/input.h2
-rw-r--r--include/rootston/seat.h8
-rw-r--r--include/rootston/view.h8
-rw-r--r--include/wlr/types/wlr_output.h7
-rw-r--r--render/gles2/renderer.c2
-rw-r--r--rootston/cursor.c94
-rw-r--r--rootston/desktop.c20
-rw-r--r--rootston/output.c66
-rw-r--r--rootston/seat.c44
-rw-r--r--rootston/xwayland.c5
-rw-r--r--types/wlr_output.c43
12 files changed, 240 insertions, 61 deletions
diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h
index 19ac4034..90d54c12 100644
--- a/include/rootston/cursor.h
+++ b/include/rootston/cursor.h
@@ -27,6 +27,8 @@ struct roots_cursor {
float view_rotation;
uint32_t resize_edges;
+ struct roots_seat_view *pointer_view;
+
struct wl_listener motion;
struct wl_listener motion_absolute;
struct wl_listener button;
diff --git a/include/rootston/input.h b/include/rootston/input.h
index 726dda24..2270ea0c 100644
--- a/include/rootston/input.h
+++ b/include/rootston/input.h
@@ -9,6 +9,8 @@
#include "rootston/view.h"
#include "rootston/server.h"
+struct roots_view;
+
struct roots_input {
struct roots_config *config;
struct roots_server *server;
diff --git a/include/rootston/seat.h b/include/rootston/seat.h
index cf5dd3b2..6ae7c3fa 100644
--- a/include/rootston/seat.h
+++ b/include/rootston/seat.h
@@ -28,6 +28,11 @@ struct roots_seat {
struct roots_seat_view {
struct roots_seat *seat;
struct roots_view *view;
+
+ bool has_button_grab;
+ double grab_vx;
+ double grab_vy;
+
struct wl_list link; // roots_seat::views
struct wl_listener view_destroy;
@@ -84,4 +89,7 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view);
+struct roots_seat_view *roots_seat_view_from_view( struct roots_seat *seat,
+ struct roots_view *view);
+
#endif
diff --git a/include/rootston/view.h b/include/rootston/view.h
index 579b148a..68ccbef8 100644
--- a/include/rootston/view.h
+++ b/include/rootston/view.h
@@ -6,6 +6,9 @@
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_xdg_shell_v6.h>
+#include "rootston/seat.h"
+
+struct roots_seat;
struct roots_wl_shell_surface {
struct roots_view *view;
@@ -61,6 +64,10 @@ struct roots_view {
double x, y;
float rotation;
+ bool decorated;
+ int border_width;
+ int titlebar_height;
+
bool maximized;
struct roots_output *fullscreen_output;
struct {
@@ -113,6 +120,7 @@ struct roots_view {
};
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_move(struct roots_view *view, double x, double y);
void view_resize(struct roots_view *view, uint32_t width, uint32_t height);
diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h
index 71463cb5..4c59d98b 100644
--- a/include/wlr/types/wlr_output.h
+++ b/include/wlr/types/wlr_output.h
@@ -136,4 +136,11 @@ enum wl_output_transform wlr_output_transform_invert(
enum wl_output_transform wlr_output_transform_compose(
enum wl_output_transform tr_a, enum wl_output_transform tr_b);
+/**
+ * Get a matrix suitable for rendering a box on the output.
+ */
+void wlr_output_get_box_matrix(struct wlr_output *output, int ox, int oy,
+ int width, int height, enum wl_output_transform transform,
+ float rotation, float (*mat)[16]);
+
#endif
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index 89cc4ffb..30247af0 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -177,7 +177,7 @@ static bool wlr_gles2_render_texture(struct wlr_renderer *_renderer,
static void wlr_gles2_render_quad(struct wlr_renderer *renderer,
const float (*color)[4], const float (*matrix)[16]) {
GL_CALL(glUseProgram(shaders.quad));
- GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, *matrix));
+ GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix));
GL_CALL(glUniform4f(1, (*color)[0], (*color)[1], (*color)[2], (*color)[3]));
draw_quad();
}
diff --git a/rootston/cursor.c b/rootston/cursor.c
index 8bd514cc..8a34cd13 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -30,19 +30,81 @@ void roots_cursor_destroy(struct roots_cursor *cursor) {
// TODO
}
+static void seat_view_deco_motion(struct roots_seat_view *view, double deco_vx, double deco_vy) {
+ struct roots_cursor *cursor = view->seat->cursor;
+
+ double vx = deco_vx;
+ double vy = deco_vy;
+ if (view->has_button_grab) {
+ vx = view->grab_vx;
+ vy = view->grab_vy;
+ }
+
+ bool is_titlebar = vy < 0 && -vy < view->view->titlebar_height;
+ uint32_t edges = 0;
+ if (vx < 0) {
+ edges |= WLR_EDGE_LEFT;
+ } else if (vx > view->view->wlr_surface->current->width) {
+ edges |= WLR_EDGE_RIGHT;
+ } else if (vy > view->view->wlr_surface->current->height) {
+ edges |= WLR_EDGE_BOTTOM;
+ } else if (-vy > view->view->titlebar_height) {
+ edges |= WLR_EDGE_TOP;
+ }
+
+ if (view->has_button_grab) {
+ if (is_titlebar) {
+ roots_seat_begin_move(view->seat, view->view);
+ } else if (edges) {
+ roots_seat_begin_resize(view->seat, view->view, edges);
+ }
+ view->has_button_grab = false;
+ } else {
+ if (is_titlebar) {
+ wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
+ cursor->default_xcursor, cursor->cursor);
+ } else if (edges) {
+ const char *resize_name = wlr_xcursor_get_resize_name(edges);
+ wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
+ resize_name, cursor->cursor);
+ }
+ }
+}
+
+static void seat_view_deco_leave(struct roots_seat_view *view) {
+ view->has_button_grab = false;
+}
+
+static void seat_view_deco_button(struct roots_seat_view *view, double vx,
+ double vy, uint32_t button, uint32_t state) {
+ if (button == BTN_LEFT && state == WLR_BUTTON_PRESSED) {
+ view->has_button_grab = true;
+ view->grab_vx = vx;
+ view->grab_vy = vy;
+ } else {
+ view->has_button_grab = false;
+ }
+}
+
static void roots_cursor_update_position(struct roots_cursor *cursor,
uint32_t time) {
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
struct roots_seat *seat = cursor->seat;
struct roots_view *view;
- struct wlr_surface *surface;
+ struct wlr_surface *surface = NULL;
double sx, sy;
switch (cursor->mode) {
case ROOTS_CURSOR_PASSTHROUGH:
view = desktop_view_at(desktop, cursor->cursor->x, cursor->cursor->y,
&surface, &sx, &sy);
+ struct roots_seat_view *seat_view =
+ roots_seat_view_from_view(seat, view);
+ if (cursor->pointer_view && (surface || seat_view != cursor->pointer_view)) {
+ seat_view_deco_leave(cursor->pointer_view);
+ cursor->pointer_view = NULL;
+ }
bool set_compositor_cursor = !view && cursor->cursor_client;
- if (view) {
+ if (view && surface) {
struct wl_client *view_client =
wl_resource_get_client(view->wlr_surface->resource);
set_compositor_cursor = view_client != cursor->cursor_client;
@@ -52,7 +114,15 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
cursor->default_xcursor, cursor->cursor);
cursor->cursor_client = NULL;
}
- if (view) {
+ if (view && !surface) {
+ if (seat_view) {
+ cursor->pointer_view = seat_view;
+ seat_view_deco_motion(seat_view,
+ cursor->cursor->x - seat_view->view->x,
+ cursor->cursor->y - seat_view->view->y);
+ }
+ } if (view && surface) {
+ // motion over a view surface
wlr_seat_pointer_notify_enter(seat->seat, surface, sx, sy);
wlr_seat_pointer_notify_motion(seat->seat, time, sx, sy);
} else {
@@ -166,16 +236,30 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
}
return;
}
+
+ if (view && !surface) {
+ if (cursor->pointer_view) {
+ seat_view_deco_button(cursor->pointer_view,
+ cursor->cursor->x - cursor->pointer_view->view->x,
+ cursor->cursor->y - cursor->pointer_view->view->y,
+ button, state);
+ }
+ }
+
if (state == WLR_BUTTON_RELEASED &&
cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
+ wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
+ cursor->default_xcursor, cursor->cursor);
if (seat->seat->pointer_state.button_count == 0) {
return;
}
}
- if (!is_touch) {
- wlr_seat_pointer_notify_button(seat->seat, time, button, state);
+ if (view && surface) {
+ if (!is_touch) {
+ wlr_seat_pointer_notify_button(seat->seat, time, button, state);
+ }
}
switch (state) {
diff --git a/rootston/desktop.c b/rootston/desktop.c
index d7da1600..1ec1d552 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -31,6 +31,18 @@ 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) {
+ view_get_box(view, box);
+ if (!view->decorated) {
+ return;
+ }
+
+ box->x -= view->border_width;
+ box->y -= (view->border_width + view->titlebar_height);
+ box->width += view->border_width * 2;
+ box->height += (view->border_width * 2 + view->titlebar_height);
+}
+
static void view_update_output(const struct roots_view *view,
const struct wlr_box *before) {
struct roots_desktop *desktop = view->desktop;
@@ -380,6 +392,14 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx,
if (view_at(view, lx, ly, surface, sx, sy)) {
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;
}
diff --git a/rootston/output.c b/rootston/output.c
index c26ea36e..502e72d2 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -53,46 +53,8 @@ static void render_surface(struct wlr_surface *surface,
};
if (wlr_output_layout_intersects(desktop->layout, wlr_output, &render_box)) {
float matrix[16];
-
- float translate_center[16];
- wlr_matrix_translate(&translate_center,
- (int)ox + render_width / 2, (int)oy + render_height / 2, 0);
-
- float rotate[16];
- wlr_matrix_rotate(&rotate, rotation);
-
- float translate_origin[16];
- wlr_matrix_translate(&translate_origin, -render_width / 2,
- -render_height / 2, 0);
-
- float scale[16];
- wlr_matrix_scale(&scale, render_width, render_height, 1);
-
- float transform[16];
- wlr_matrix_mul(&translate_center, &rotate, &transform);
- wlr_matrix_mul(&transform, &translate_origin, &transform);
- wlr_matrix_mul(&transform, &scale, &transform);
-
- if (surface->current->transform != WL_OUTPUT_TRANSFORM_NORMAL) {
- float surface_translate_center[16];
- wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0);
-
- float surface_transform[16];
- wlr_matrix_transform(surface_transform,
- wlr_output_transform_invert(surface->current->transform));
-
- float surface_translate_origin[16];
- wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0);
-
- wlr_matrix_mul(&transform, &surface_translate_center,
- &transform);
- wlr_matrix_mul(&transform, &surface_transform, &transform);
- wlr_matrix_mul(&transform, &surface_translate_origin,
- &transform);
- }
-
- wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix);
-
+ wlr_output_get_box_matrix(wlr_output, ox, oy, render_width,
+ render_height, surface->current->transform, rotation, &matrix);
wlr_render_with_matrix(desktop->server->renderer, surface->texture,
&matrix);
@@ -182,8 +144,32 @@ static void render_xwayland_children(struct wlr_xwayland_surface *surface,
}
}
+static void render_decorations(struct roots_view *view,
+ struct roots_desktop *desktop, struct wlr_output *output) {
+ if (!view->decorated) {
+ return;
+ }
+ struct wlr_box deco_box;
+ view_get_deco_box(view, &deco_box);
+ double ox = deco_box.x;
+ double oy = deco_box.y;
+ wlr_output_layout_output_coords(desktop->layout, output, &ox, &oy);
+ ox *= output->scale;
+ oy *= output->scale;
+
+ float matrix[16];
+ wlr_output_get_box_matrix(output, ox, oy, deco_box.width,
+ deco_box.height, WL_OUTPUT_TRANSFORM_NORMAL, view->rotation,
+ &matrix);
+
+ float color[4] = { 0.2, 0.2, 0.2, 1 };
+ wlr_render_colored_quad(desktop->server->renderer, &color, &matrix);
+}
+
static void render_view(struct roots_view *view, struct roots_desktop *desktop,
struct wlr_output *wlr_output, struct timespec *when) {
+ render_decorations(view, desktop, wlr_output);
+
switch (view->type) {
case ROOTS_XDG_SHELL_V6_VIEW:
render_surface(view->wlr_surface, desktop, wlr_output, when,
diff --git a/rootston/seat.c b/rootston/seat.c
index 1a0e6253..41ae6c9f 100644
--- a/rootston/seat.c
+++ b/rootston/seat.c
@@ -601,7 +601,7 @@ static struct roots_seat_view *seat_add_view(struct roots_seat *seat,
seat_view->seat = seat;
seat_view->view = view;
- wl_list_insert(&seat->views, &seat_view->link);
+ wl_list_insert(seat->views.prev, &seat_view->link);
seat_view->view_destroy.notify = seat_view_handle_destroy;
wl_signal_add(&view->events.destroy, &seat_view->view_destroy);
@@ -609,6 +609,31 @@ static struct roots_seat_view *seat_add_view(struct roots_seat *seat,
return seat_view;
}
+struct roots_seat_view *roots_seat_view_from_view(
+ struct roots_seat *seat, struct roots_view *view) {
+ if (view == NULL) {
+ return NULL;
+ }
+
+ bool found = false;
+ struct roots_seat_view *seat_view = NULL;
+ wl_list_for_each(seat_view, &seat->views, link) {
+ if (seat_view->view == view) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ seat_view = seat_add_view(seat, view);
+ if (seat_view == NULL) {
+ wlr_log(L_ERROR, "Allocation failed");
+ return NULL;
+ }
+ }
+
+ return seat_view;
+}
+
void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
// Make sure the view will be rendered on top of others, even if it's
// already focused in this seat
@@ -626,22 +651,11 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
view->xwayland_surface->override_redirect) {
return;
}
-
struct roots_seat_view *seat_view = NULL;
if (view != NULL) {
- bool found = false;
- wl_list_for_each(seat_view, &seat->views, link) {
- if (seat_view->view == view) {
- found = true;
- break;
- }
- }
- if (!found) {
- seat_view = seat_add_view(seat, view);
- if (seat_view == NULL) {
- wlr_log(L_ERROR, "Allocation failed");
- return;
- }
+ seat_view = roots_seat_view_from_view(seat, view);
+ if (seat_view == NULL) {
+ return;
}
}
diff --git a/rootston/xwayland.c b/rootston/xwayland.c
index 3d84dc19..eb84eba0 100644
--- a/rootston/xwayland.c
+++ b/rootston/xwayland.c
@@ -296,6 +296,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->type = ROOTS_XWAYLAND_VIEW;
view->x = (double)surface->x;
view->y = (double)surface->y;
+
view->xwayland_surface = surface;
view->roots_xwayland_surface = roots_surface;
view->wlr_surface = surface->surface;
@@ -311,6 +312,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
wl_list_insert(&desktop->views, &view->link);
if (!surface->override_redirect) {
+ view->decorated = true;
+ view->border_width = 4;
+ view->titlebar_height = 12;
+
view_setup(view);
}
}
diff --git a/types/wlr_output.c b/types/wlr_output.c
index b47fb3a0..178306a8 100644
--- a/types/wlr_output.c
+++ b/types/wlr_output.c
@@ -751,3 +751,46 @@ enum wl_output_transform wlr_output_transform_compose(
}
return flipped | rotated;
}
+
+void wlr_output_get_box_matrix(struct wlr_output *output, int ox, int oy,
+ int width, int height, enum wl_output_transform transform,
+ float rotation, float (*mat)[16]) {
+ float translate_center[16];
+ wlr_matrix_translate(&translate_center,
+ (int)ox + width / 2, (int)oy + height / 2, 0);
+
+ float rotate[16];
+ wlr_matrix_rotate(&rotate, rotation);
+
+ float translate_origin[16];
+ wlr_matrix_translate(&translate_origin, -width / 2,
+ -height / 2, 0);
+
+ float scale[16];
+ wlr_matrix_scale(&scale, width, height, 1);
+
+ float transform_matrix[16];
+ wlr_matrix_mul(&translate_center, &rotate, &transform_matrix);
+ wlr_matrix_mul(&transform_matrix, &translate_origin, &transform_matrix);
+ wlr_matrix_mul(&transform_matrix, &scale, &transform_matrix);
+
+ if (transform != WL_OUTPUT_TRANSFORM_NORMAL) {
+ float surface_translate_center[16];
+ wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0);
+
+ float surface_transform[16];
+ wlr_matrix_transform(surface_transform,
+ wlr_output_transform_invert(transform));
+
+ float surface_translate_origin[16];
+ wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0);
+
+ wlr_matrix_mul(&transform_matrix, &surface_translate_center,
+ &transform_matrix);
+ wlr_matrix_mul(&transform_matrix, &surface_transform, &transform_matrix);
+ wlr_matrix_mul(&transform_matrix, &surface_translate_origin,
+ &transform_matrix);
+ }
+
+ wlr_matrix_mul(&output->transform_matrix, &transform_matrix, mat);
+}