2020-06-29 19:27:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								/*
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * Helpers for handling window decorations
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * Copyright Johan Malm 2020
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 */
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-28 20:53:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <assert.h>
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-28 21:35:18 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-28 20:41:41 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "config/rcxml.h"
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "labwc.h"
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-03 20:56:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "theme/theme.h"
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 21:58:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-15 20:41:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#define BORDER_WIDTH (2)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-28 20:41:41 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								struct border
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								deco_thickness(struct view *view)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-15 20:41:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct border border = {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										.top = rc.title_height + BORDER_WIDTH,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										.bottom = BORDER_WIDTH,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										.left = BORDER_WIDTH,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										.right = BORDER_WIDTH,
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									};
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-15 20:41:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									return border;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-28 20:41:41 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								struct wlr_box
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								deco_max_extents(struct view *view)
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-17 21:11:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct border border = deco_thickness(view);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct wlr_box box = {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										.x = view->x - border.left,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										.y = view->y - border.top,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										.width = view->w + border.left + border.right,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										.height = view->h + border.top + border.bottom,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return box;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-28 20:41:41 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								struct wlr_box
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								deco_box(struct view *view, enum deco_part deco_part)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct wlr_box box = { .x = 0, .y = 0, .width = 0, .height = 0 };
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-28 20:53:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									assert(view);
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									switch (deco_part) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 21:58:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									case LAB_DECO_BUTTON_CLOSE:
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-21 19:24:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.width = rc.title_height;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										box.height = rc.title_height;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										box.x = view->x + view->w - rc.title_height;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										box.y = view->y - rc.title_height;
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 21:58:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									case LAB_DECO_BUTTON_MAXIMIZE:
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-21 19:24:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.width = rc.title_height;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										box.height = rc.title_height;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										box.x = view->x + view->w - rc.title_height * 2;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										box.y = view->y - rc.title_height;
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 21:58:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									case LAB_DECO_BUTTON_ICONIFY:
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-21 19:24:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.width = rc.title_height;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										box.height = rc.title_height;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										box.x = view->x + view->w - rc.title_height * 3;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										box.y = view->y - rc.title_height;
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-29 19:27:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										break;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-30 21:28:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									case LAB_DECO_PART_TITLE:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										box.x = view->x;
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-05 20:14:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.y = view->y - rc.title_height;
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-31 08:12:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.width = view->w;
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-05 20:14:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.height = rc.title_height;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-30 21:28:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										break;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									case LAB_DECO_PART_TOP:
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 21:58:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.x = view->x - BORDER_WIDTH;
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-05 20:14:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.y = view->y - rc.title_height - BORDER_WIDTH;
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-31 08:12:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.width = view->w + 2 * BORDER_WIDTH;
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 21:58:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.height = BORDER_WIDTH;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-30 21:28:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									case LAB_DECO_PART_RIGHT:
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-31 08:12:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.x = view->x + view->w;
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-05 20:14:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.y = view->y - rc.title_height;
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 21:58:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.width = BORDER_WIDTH;
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-31 08:12:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.height = view->h + rc.title_height;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-30 21:28:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									case LAB_DECO_PART_BOTTOM:
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 21:58:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.x = view->x - BORDER_WIDTH;
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-31 08:12:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.y = view->y + view->h;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										box.width = view->w + 2 * BORDER_WIDTH;
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 21:58:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.height = +BORDER_WIDTH;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										break;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-12 22:24:18 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									case LAB_DECO_PART_LEFT:
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 21:58:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.x = view->x - BORDER_WIDTH;
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-05 20:14:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.y = view->y - rc.title_height;
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-06 21:58:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.width = BORDER_WIDTH;
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-31 08:12:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										box.height = view->h + rc.title_height;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-12 22:24:18 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										break;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-12 21:00:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									default:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										break;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return box;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-28 20:41:41 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								enum deco_part
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								deco_at(struct view *view, double lx, double ly)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-25 13:42:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									enum deco_part deco_part;
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-02 21:04:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									for (deco_part = 0; deco_part < LAB_DECO_END_MARKER; ++deco_part) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-25 13:42:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										struct wlr_box box = deco_box(view, deco_part);
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-28 20:41:41 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										if (wlr_box_contains_point(&box, lx, ly)) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-25 13:42:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											return deco_part;
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-28 20:41:41 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-25 13:42:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-04 22:21:30 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return LAB_DECO_NONE;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |