mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	rootston: rotate views!
This commit is contained in:
		
							parent
							
								
									a40d38798c
								
							
						
					
					
						commit
						9b88f25208
					
				
					 3 changed files with 52 additions and 14 deletions
				
			
		| 
						 | 
					@ -83,6 +83,7 @@ struct roots_input {
 | 
				
			||||||
	struct roots_view *active_view;
 | 
						struct roots_view *active_view;
 | 
				
			||||||
	int offs_x, offs_y;
 | 
						int offs_x, offs_y;
 | 
				
			||||||
	int view_x, view_y, view_width, view_height;
 | 
						int view_x, view_y, view_width, view_height;
 | 
				
			||||||
 | 
						float view_rotation;
 | 
				
			||||||
	uint32_t resize_edges;
 | 
						uint32_t resize_edges;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Ring buffer of input events that could trigger move/resize/rotate
 | 
						// Ring buffer of input events that could trigger move/resize/rotate
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
#include <stdbool.h>
 | 
					#include <stdbool.h>
 | 
				
			||||||
#include <stdint.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <math.h>
 | 
				
			||||||
// TODO: BSD et al
 | 
					// TODO: BSD et al
 | 
				
			||||||
#include <linux/input-event-codes.h>
 | 
					#include <linux/input-event-codes.h>
 | 
				
			||||||
#include <wayland-server.h>
 | 
					#include <wayland-server.h>
 | 
				
			||||||
| 
						 | 
					@ -25,15 +26,16 @@ const struct roots_input_event *get_input_event(struct roots_input *input,
 | 
				
			||||||
void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
 | 
					void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
 | 
				
			||||||
		struct roots_view *view) {
 | 
							struct roots_view *view) {
 | 
				
			||||||
	input->mode = ROOTS_CURSOR_MOVE;
 | 
						input->mode = ROOTS_CURSOR_MOVE;
 | 
				
			||||||
	input->offs_x = cursor->x - view->x;
 | 
						input->offs_x = cursor->x;
 | 
				
			||||||
	input->offs_y = cursor->y - view->y;
 | 
						input->offs_y = cursor->y;
 | 
				
			||||||
 | 
						input->view_x = view->x;
 | 
				
			||||||
 | 
						input->view_y = view->y;
 | 
				
			||||||
	wlr_seat_pointer_clear_focus(input->wl_seat);
 | 
						wlr_seat_pointer_clear_focus(input->wl_seat);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
 | 
					void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
 | 
				
			||||||
		struct roots_view *view, uint32_t edges) {
 | 
							struct roots_view *view, uint32_t edges) {
 | 
				
			||||||
	input->mode = ROOTS_CURSOR_RESIZE;
 | 
						input->mode = ROOTS_CURSOR_RESIZE;
 | 
				
			||||||
	wlr_log(L_DEBUG, "begin resize");
 | 
					 | 
				
			||||||
	input->offs_x = cursor->x;
 | 
						input->offs_x = cursor->x;
 | 
				
			||||||
	input->offs_y = cursor->y;
 | 
						input->offs_y = cursor->y;
 | 
				
			||||||
	input->view_x = view->x;
 | 
						input->view_x = view->x;
 | 
				
			||||||
| 
						 | 
					@ -46,6 +48,15 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
 | 
				
			||||||
	wlr_seat_pointer_clear_focus(input->wl_seat);
 | 
						wlr_seat_pointer_clear_focus(input->wl_seat);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor,
 | 
				
			||||||
 | 
							struct roots_view *view) {
 | 
				
			||||||
 | 
						input->mode = ROOTS_CURSOR_ROTATE;
 | 
				
			||||||
 | 
						input->offs_x = cursor->x;
 | 
				
			||||||
 | 
						input->offs_y = cursor->y;
 | 
				
			||||||
 | 
						input->view_rotation = view->rotation;
 | 
				
			||||||
 | 
						wlr_seat_pointer_clear_focus(input->wl_seat);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void cursor_update_position(struct roots_input *input, uint32_t time) {
 | 
					void cursor_update_position(struct roots_input *input, uint32_t time) {
 | 
				
			||||||
	struct roots_desktop *desktop = input->server->desktop;
 | 
						struct roots_desktop *desktop = input->server->desktop;
 | 
				
			||||||
	struct roots_view *view;
 | 
						struct roots_view *view;
 | 
				
			||||||
| 
						 | 
					@ -64,16 +75,18 @@ 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) {
 | 
				
			||||||
			input->active_view->x = input->cursor->x - input->offs_x;
 | 
								int dx = input->cursor->x - input->offs_x,
 | 
				
			||||||
			input->active_view->y = input->cursor->y - input->offs_y;
 | 
									dy = input->cursor->y - input->offs_y;
 | 
				
			||||||
 | 
								input->active_view->x = input->view_x + dx;
 | 
				
			||||||
 | 
								input->active_view->y = 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;
 | 
								int dx = input->cursor->x - input->offs_x,
 | 
				
			||||||
			int dy = input->cursor->y - input->offs_y;
 | 
									dy = input->cursor->y - input->offs_y;
 | 
				
			||||||
			int width = input->view_width;
 | 
								int width = input->view_width,
 | 
				
			||||||
			int height = input->view_height;
 | 
									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;
 | 
									input->active_view->y = input->view_y + dy;
 | 
				
			||||||
				height -= dy;
 | 
									height -= dy;
 | 
				
			||||||
| 
						 | 
					@ -92,6 +105,17 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case ROOTS_CURSOR_ROTATE:
 | 
						case ROOTS_CURSOR_ROTATE:
 | 
				
			||||||
 | 
							if (input->active_view) {
 | 
				
			||||||
 | 
								struct roots_view *view = input->active_view;
 | 
				
			||||||
 | 
								int ox = view->x + view->wlr_surface->current->width/2,
 | 
				
			||||||
 | 
									oy = view->y + view->wlr_surface->current->height/2;
 | 
				
			||||||
 | 
								int ux = input->offs_x - ox,
 | 
				
			||||||
 | 
									uy = input->offs_y - oy;
 | 
				
			||||||
 | 
								int vx = input->cursor->x - ox,
 | 
				
			||||||
 | 
									vy = input->cursor->y - oy;
 | 
				
			||||||
 | 
								float angle = atan2(vx*uy - vy*ux, vx*ux + vy*uy);
 | 
				
			||||||
 | 
								view->rotation = input->view_rotation + angle;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -175,6 +199,8 @@ static void do_cursor_button_press(struct roots_input *input,
 | 
				
			||||||
				ROOTS_CURSOR_RESIZE_EDGE_RIGHT |
 | 
									ROOTS_CURSOR_RESIZE_EDGE_RIGHT |
 | 
				
			||||||
				ROOTS_CURSOR_RESIZE_EDGE_BOTTOM);
 | 
									ROOTS_CURSOR_RESIZE_EDGE_BOTTOM);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
							case BTN_MIDDLE:
 | 
				
			||||||
 | 
								view_begin_rotate(input, cursor, view);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,7 @@ static inline int64_t timespec_to_msec(const struct timespec *a) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void render_surface(struct wlr_surface *surface,
 | 
					static void render_surface(struct wlr_surface *surface,
 | 
				
			||||||
		struct roots_desktop *desktop, struct wlr_output *wlr_output,
 | 
							struct roots_desktop *desktop, struct wlr_output *wlr_output,
 | 
				
			||||||
		struct timespec *when, double lx, double ly) {
 | 
							struct timespec *when, double lx, double ly, float rotation) {
 | 
				
			||||||
	wlr_surface_flush_damage(surface);
 | 
						wlr_surface_flush_damage(surface);
 | 
				
			||||||
	if (surface->texture->valid) {
 | 
						if (surface->texture->valid) {
 | 
				
			||||||
		int width = surface->current->buffer_width;
 | 
							int width = surface->current->buffer_width;
 | 
				
			||||||
| 
						 | 
					@ -27,10 +27,20 @@ static void render_surface(struct wlr_surface *surface,
 | 
				
			||||||
		wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy);
 | 
							wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (wlr_output_layout_intersects(desktop->layout, wlr_output,
 | 
							if (wlr_output_layout_intersects(desktop->layout, wlr_output,
 | 
				
			||||||
					lx, ly, lx + width, ly + height)) {
 | 
									lx, ly, lx + width, ly + height)) {
 | 
				
			||||||
			float matrix[16];
 | 
								float matrix[16];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								float translate_origin[16];
 | 
				
			||||||
 | 
								wlr_matrix_translate(&translate_origin,
 | 
				
			||||||
 | 
									ox + width/2, oy + height/2, 0);
 | 
				
			||||||
 | 
								float rotate[16];
 | 
				
			||||||
 | 
								wlr_matrix_rotate(&rotate, rotation);
 | 
				
			||||||
 | 
								float translate_center[16];
 | 
				
			||||||
 | 
								wlr_matrix_translate(&translate_center, -width/2, -height/2, 0);
 | 
				
			||||||
			float transform[16];
 | 
								float transform[16];
 | 
				
			||||||
			wlr_matrix_translate(&transform, ox, oy, 0);
 | 
								wlr_matrix_mul(&translate_origin, &rotate, &transform);
 | 
				
			||||||
 | 
								wlr_matrix_mul(&transform, &translate_center, &transform);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			wlr_surface_get_matrix(surface, &matrix,
 | 
								wlr_surface_get_matrix(surface, &matrix,
 | 
				
			||||||
					&wlr_output->transform_matrix, &transform);
 | 
										&wlr_output->transform_matrix, &transform);
 | 
				
			||||||
			wlr_render_with_matrix(desktop->server->renderer,
 | 
								wlr_render_with_matrix(desktop->server->renderer,
 | 
				
			||||||
| 
						 | 
					@ -48,7 +58,8 @@ static void render_surface(struct wlr_surface *surface,
 | 
				
			||||||
		wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
 | 
							wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
 | 
				
			||||||
			render_surface(subsurface->surface, desktop, wlr_output, when,
 | 
								render_surface(subsurface->surface, desktop, wlr_output, when,
 | 
				
			||||||
				lx + subsurface->surface->current->subsurface_position.x,
 | 
									lx + subsurface->surface->current->subsurface_position.x,
 | 
				
			||||||
				ly + subsurface->surface->current->subsurface_position.y);
 | 
									ly + subsurface->surface->current->subsurface_position.y,
 | 
				
			||||||
 | 
									rotation);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -56,7 +67,7 @@ static void render_surface(struct wlr_surface *surface,
 | 
				
			||||||
static void render_view(struct roots_view *view, struct roots_desktop *desktop,
 | 
					static void render_view(struct roots_view *view, struct roots_desktop *desktop,
 | 
				
			||||||
		struct wlr_output *wlr_output, struct timespec *when) {
 | 
							struct wlr_output *wlr_output, struct timespec *when) {
 | 
				
			||||||
	render_surface(view->wlr_surface, desktop, wlr_output, when,
 | 
						render_surface(view->wlr_surface, desktop, wlr_output, when,
 | 
				
			||||||
		view->x, view->y);
 | 
							view->x, view->y, view->rotation);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void output_frame_notify(struct wl_listener *listener, void *data) {
 | 
					static void output_frame_notify(struct wl_listener *listener, void *data) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue