mirror of
https://github.com/swaywm/sway.git
synced 2024-12-30 17:06:40 +01:00
Implement some more on borders
Note that this segfaults ALL THE TIME in wlc code. Paging @Cloudef for help, I'm at a loss.
This commit is contained in:
parent
a8e084433d
commit
b903f7f655
6 changed files with 110 additions and 25 deletions
|
@ -36,6 +36,12 @@ enum swayc_layouts {
|
||||||
L_LAYOUTS,
|
L_LAYOUTS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum swayc_border_types {
|
||||||
|
B_NONE, /**< No border */
|
||||||
|
B_PIXEL, /**< 1px border */
|
||||||
|
B_NORMAL /**< Normal border with title bar */
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores information about a container.
|
* Stores information about a container.
|
||||||
*
|
*
|
||||||
|
@ -109,6 +115,15 @@ struct sway_container {
|
||||||
* If this container's children include a fullscreen view, this is that view.
|
* If this container's children include a fullscreen view, this is that view.
|
||||||
*/
|
*/
|
||||||
struct sway_container *fullscreen;
|
struct sway_container *fullscreen;
|
||||||
|
/**
|
||||||
|
* If this container is a view, this may be set to the window's decoration
|
||||||
|
* buffer (or NULL).
|
||||||
|
*/
|
||||||
|
unsigned char *border;
|
||||||
|
enum swayc_border_types border_type;
|
||||||
|
struct wlc_geometry border_geometry;
|
||||||
|
struct wlc_geometry presumed_geometry;
|
||||||
|
int border_thickness;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum visibility_mask {
|
enum visibility_mask {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef _SWAY_RENDER_H
|
#ifndef _SWAY_RENDER_H
|
||||||
#define _SWAY_RENDER_H
|
#define _SWAY_RENDER_H
|
||||||
#include <wlc/wlc.h>
|
#include <wlc/wlc.h>
|
||||||
|
#include "container.h"
|
||||||
|
|
||||||
void render_view_borders(wlc_handle view);
|
void render_view_borders(wlc_handle view);
|
||||||
|
void update_view_border(swayc_t *view);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,8 +22,11 @@ static swayc_t *new_swayc(enum swayc_types type) {
|
||||||
c->gaps = -1;
|
c->gaps = -1;
|
||||||
c->layout = L_NONE;
|
c->layout = L_NONE;
|
||||||
c->type = type;
|
c->type = type;
|
||||||
|
c->border_type = B_PIXEL; // TODO: Load default from config
|
||||||
|
c->border_thickness = 2;
|
||||||
if (type != C_VIEW) {
|
if (type != C_VIEW) {
|
||||||
c->children = create_list();
|
c->children = create_list();
|
||||||
|
c->border_type = B_NONE;
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,6 +357,7 @@ static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geo
|
||||||
arrange_windows(view->parent, -1, -1);
|
arrange_windows(view->parent, -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
update_view_border(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) {
|
static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) {
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "focus.h"
|
#include "focus.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "ipc-server.h"
|
#include "ipc-server.h"
|
||||||
|
#include "render.h"
|
||||||
|
|
||||||
swayc_t root_container;
|
swayc_t root_container;
|
||||||
list_t *scratchpad;
|
list_t *scratchpad;
|
||||||
|
|
109
sway/render.c
109
sway/render.c
|
@ -2,6 +2,8 @@
|
||||||
#include <wlc/wlc-render.h>
|
#include <wlc/wlc-render.h>
|
||||||
#include <cairo/cairo.h>
|
#include <cairo/cairo.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "container.h"
|
||||||
|
|
||||||
void cairo_set_source_u32(cairo_t *cairo, uint32_t color) {
|
void cairo_set_source_u32(cairo_t *cairo, uint32_t color) {
|
||||||
cairo_set_source_rgba(cairo,
|
cairo_set_source_rgba(cairo,
|
||||||
|
@ -11,40 +13,101 @@ void cairo_set_source_u32(cairo_t *cairo, uint32_t color) {
|
||||||
(color >> (0*8) & 0xFF) / 255.0);
|
(color >> (0*8) & 0xFF) / 255.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_t *create_cairo_context(int width, int height, int channels,
|
cairo_t *create_border_buffer(swayc_t *view, struct wlc_geometry geo,
|
||||||
cairo_surface_t **surf, unsigned char **buf) {
|
cairo_surface_t **surface) {
|
||||||
|
const int channels = 4;
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
*buf = calloc(channels * width * height, sizeof(unsigned char));
|
view->border_geometry = geo;
|
||||||
if (!*buf) {
|
view->border = calloc(channels * geo.size.w * geo.size.h,
|
||||||
|
sizeof(unsigned char));
|
||||||
|
if (!view->border) {
|
||||||
|
sway_log(L_DEBUG, "Unable to allocate buffer");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
*surf = cairo_image_surface_create_for_data(*buf, CAIRO_FORMAT_ARGB32,
|
*surface = cairo_image_surface_create_for_data(view->border,
|
||||||
width, height, channels * width);
|
CAIRO_FORMAT_ARGB32, geo.size.w, geo.size.h, channels * geo.size.w);
|
||||||
if (cairo_surface_status(*surf) != CAIRO_STATUS_SUCCESS) {
|
if (cairo_surface_status(*surface) != CAIRO_STATUS_SUCCESS) {
|
||||||
free(*buf);
|
free(view->border);
|
||||||
|
view->border = NULL;
|
||||||
|
sway_log(L_DEBUG, "Unable to allocate surface");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
cr = cairo_create(*surf);
|
cr = cairo_create(*surface);
|
||||||
if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) {
|
if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) {
|
||||||
free(*buf);
|
cairo_surface_destroy(*surface);
|
||||||
|
free(view->border);
|
||||||
|
view->border = NULL;
|
||||||
|
sway_log(L_DEBUG, "Unable to create cairo context");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return cr;
|
return cr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_view_borders(wlc_handle view) {
|
void update_view_border(swayc_t *view) {
|
||||||
const int bw = 2;
|
struct wlc_geometry geo;
|
||||||
unsigned char *surf_data;
|
wlc_view_get_visible_geometry(view->handle, &geo);
|
||||||
cairo_surface_t *surf;
|
cairo_t *cr = NULL;
|
||||||
struct wlc_geometry geo = *wlc_view_get_geometry(view);
|
cairo_surface_t *surface = NULL;
|
||||||
cairo_t *cr = create_cairo_context(geo.size.w + bw * 2, geo.size.h + bw * 2, 4, &surf, &surf_data);
|
|
||||||
|
if (view->border) {
|
||||||
|
free(view->border);
|
||||||
|
view->border = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (view->border_type) {
|
||||||
|
case B_NONE:
|
||||||
|
view->border_geometry = geo;
|
||||||
|
break;
|
||||||
|
case B_PIXEL:
|
||||||
|
geo.origin.x -= view->border_thickness;
|
||||||
|
geo.origin.y -= view->border_thickness;
|
||||||
|
geo.size.w += view->border_thickness * 2;
|
||||||
|
geo.size.h += view->border_thickness * 2;
|
||||||
|
if (geo.size.w <= 0 || geo.size.h <= 0) {
|
||||||
|
view->border = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cr = create_border_buffer(view, geo, &surface);
|
||||||
|
if (!cr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
cairo_set_source_u32(cr, 0x0000FFFF);
|
cairo_set_source_u32(cr, 0x0000FFFF);
|
||||||
cairo_paint(cr);
|
cairo_paint(cr);
|
||||||
geo.origin.x -= bw;
|
break;
|
||||||
geo.origin.y -= bw;
|
case B_NORMAL:
|
||||||
geo.size.w += bw * 2;
|
// TODO
|
||||||
geo.size.h += bw * 2;
|
break;
|
||||||
wlc_pixels_write(WLC_RGBA8888, &geo, surf_data);
|
}
|
||||||
cairo_destroy(cr);
|
if (surface) {
|
||||||
free(surf_data);
|
cairo_surface_flush(surface);
|
||||||
|
cairo_surface_destroy(surface);
|
||||||
|
}
|
||||||
|
if (cr) {
|
||||||
|
cairo_destroy(cr);
|
||||||
|
sway_log(L_DEBUG, "Created border for %p (%dx%d+%d,%d)", view,
|
||||||
|
geo.size.w, geo.size.h, geo.origin.x, geo.origin.y);
|
||||||
|
}
|
||||||
|
view->border_geometry = geo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void render_view_borders(wlc_handle view) {
|
||||||
|
swayc_t *c = swayc_by_handle(view);
|
||||||
|
if (!c || c->border_type == B_NONE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
struct wlc_geometry geo;
|
||||||
|
wlc_view_get_visible_geometry(view, &geo);
|
||||||
|
if (geo.size.w != c->presumed_geometry.size.w
|
||||||
|
|| geo.size.h != c->presumed_geometry.size.h
|
||||||
|
|| geo.origin.x != c->presumed_geometry.origin.x
|
||||||
|
|| geo.origin.y != c->presumed_geometry.origin.y) {
|
||||||
|
update_view_border(c);
|
||||||
|
c->presumed_geometry = geo;
|
||||||
|
}
|
||||||
|
if (c->border) {
|
||||||
|
geo = c->border_geometry;
|
||||||
|
sway_log(L_DEBUG, "Rendering border for %p (%dx%d+%d,%d)", c,
|
||||||
|
geo.size.w, geo.size.h, geo.origin.x, geo.origin.y);
|
||||||
|
wlc_pixels_write(WLC_RGBA8888, &c->border_geometry, c->border);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue