labwc/src/ssd.c

113 lines
2.5 KiB
C
Raw Normal View History

2020-06-29 19:27:59 +01:00
/*
2021-03-21 20:54:55 +00:00
* Helpers for view server side decorations
2020-06-29 19:27:59 +01:00
*
2021-03-21 20:54:55 +00:00
* Copyright (C) 2020 Johan Malm
2020-06-29 19:27:59 +01:00
*/
2020-09-28 20:53:59 +01:00
#include <assert.h>
#include "config/rcxml.h"
#include "labwc.h"
2021-03-21 20:54:55 +00:00
#include "ssd.h"
#define BORDER_WIDTH (2)
struct border
2021-03-20 14:41:39 +00:00
ssd_thickness(struct view *view)
{
struct border border = {
.top = rc.title_height + BORDER_WIDTH,
.bottom = BORDER_WIDTH,
.left = BORDER_WIDTH,
.right = BORDER_WIDTH,
};
return border;
}
struct wlr_box
2021-03-20 14:41:39 +00:00
ssd_max_extents(struct view *view)
{
2021-03-20 14:41:39 +00:00
struct border border = ssd_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;
}
struct wlr_box
2021-03-20 14:41:39 +00:00
ssd_box(struct view *view, enum ssd_part ssd_part)
{
2021-02-15 17:58:04 +00:00
struct wlr_box box = { 0 };
2020-09-28 20:53:59 +01:00
assert(view);
2021-03-20 14:41:39 +00:00
switch (ssd_part) {
case LAB_SSD_BUTTON_CLOSE:
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;
break;
2021-03-20 14:41:39 +00:00
case LAB_SSD_BUTTON_MAXIMIZE:
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;
break;
2021-03-20 14:41:39 +00:00
case LAB_SSD_BUTTON_ICONIFY:
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;
2021-03-20 14:41:39 +00:00
case LAB_SSD_PART_TITLE:
2020-05-30 21:28:17 +01:00
box.x = view->x;
box.y = view->y - rc.title_height;
box.width = view->w;
box.height = rc.title_height;
2020-05-30 21:28:17 +01:00
break;
2021-03-20 14:41:39 +00:00
case LAB_SSD_PART_TOP:
box.x = view->x - BORDER_WIDTH;
box.y = view->y - rc.title_height - BORDER_WIDTH;
box.width = view->w + 2 * BORDER_WIDTH;
box.height = BORDER_WIDTH;
2020-05-30 21:28:17 +01:00
break;
2021-03-20 14:41:39 +00:00
case LAB_SSD_PART_RIGHT:
box.x = view->x + view->w;
box.y = view->y - rc.title_height;
box.width = BORDER_WIDTH;
box.height = view->h + rc.title_height;
2020-05-30 21:28:17 +01:00
break;
2021-03-20 14:41:39 +00:00
case LAB_SSD_PART_BOTTOM:
box.x = view->x - BORDER_WIDTH;
box.y = view->y + view->h;
box.width = view->w + 2 * BORDER_WIDTH;
box.height = +BORDER_WIDTH;
break;
2021-03-20 14:41:39 +00:00
case LAB_SSD_PART_LEFT:
box.x = view->x - BORDER_WIDTH;
box.y = view->y - rc.title_height;
box.width = BORDER_WIDTH;
box.height = view->h + rc.title_height;
break;
2020-05-12 21:00:33 +01:00
default:
break;
}
return box;
}
2021-03-20 14:41:39 +00:00
enum ssd_part
ssd_at(struct view *view, double lx, double ly)
{
2021-03-20 14:41:39 +00:00
enum ssd_part ssd_part;
for (ssd_part = 0; ssd_part < LAB_SSD_END_MARKER; ++ssd_part) {
struct wlr_box box = ssd_box(view, ssd_part);
if (wlr_box_contains_point(&box, lx, ly)) {
2021-03-20 14:41:39 +00:00
return ssd_part;
}
}
2021-03-20 14:41:39 +00:00
return LAB_SSD_NONE;
}
2021-03-21 20:54:55 +00:00