aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/border.h8
-rw-r--r--sway/border.c26
-rw-r--r--sway/layout.c1
3 files changed, 23 insertions, 12 deletions
diff --git a/include/border.h b/include/border.h
index c99c02ea..eb7fc656 100644
--- a/include/border.h
+++ b/include/border.h
@@ -3,11 +3,19 @@
3#include <wlc/wlc.h> 3#include <wlc/wlc.h>
4#include "container.h" 4#include "container.h"
5 5
6/**
7 * Border pixel buffer and corresponding geometry.
8 */
6struct border { 9struct border {
7 unsigned char *buffer; 10 unsigned char *buffer;
8 struct wlc_geometry geometry; 11 struct wlc_geometry geometry;
9}; 12};
10 13
14/**
15 * Clear border buffer.
16 */
17void border_clear(struct border *border);
18
11void render_view_borders(wlc_handle view); 19void render_view_borders(wlc_handle view);
12void update_view_border(swayc_t *view); 20void update_view_border(swayc_t *view);
13void map_update_view_border(swayc_t *view, void *data); 21void map_update_view_border(swayc_t *view, void *data);
diff --git a/sway/border.c b/sway/border.c
index cec443f4..d261d006 100644
--- a/sway/border.c
+++ b/sway/border.c
@@ -4,12 +4,11 @@
4#include <pango/pangocairo.h> 4#include <pango/pangocairo.h>
5#include <stdlib.h> 5#include <stdlib.h>
6#include <stdio.h> 6#include <stdio.h>
7#include <arpa/inet.h>
7#include "container.h" 8#include "container.h"
8#include "config.h" 9#include "config.h"
9#include "client/pango.h" 10#include "client/pango.h"
10 11
11#include <arpa/inet.h>
12
13void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { 12void cairo_set_source_u32(cairo_t *cairo, uint32_t color) {
14 color = htonl(color); 13 color = htonl(color);
15 14
@@ -20,6 +19,13 @@ void cairo_set_source_u32(cairo_t *cairo, uint32_t color) {
20 (color >> (3*8) & 0xFF) / 255.0); 19 (color >> (3*8) & 0xFF) / 255.0);
21} 20}
22 21
22void border_clear(struct border *border) {
23 if (border && border->buffer) {
24 free(border->buffer);
25 border->buffer = NULL;
26 }
27}
28
23static cairo_t *create_border_buffer(swayc_t *view, struct wlc_geometry g, cairo_surface_t **surface) { 29static cairo_t *create_border_buffer(swayc_t *view, struct wlc_geometry g, cairo_surface_t **surface) {
24 if (view->border == NULL) { 30 if (view->border == NULL) {
25 view->border = malloc(sizeof(struct border)); 31 view->border = malloc(sizeof(struct border));
@@ -35,16 +41,14 @@ static cairo_t *create_border_buffer(swayc_t *view, struct wlc_geometry g, cairo
35 *surface = cairo_image_surface_create_for_data(view->border->buffer, 41 *surface = cairo_image_surface_create_for_data(view->border->buffer,
36 CAIRO_FORMAT_ARGB32, g.size.w, g.size.h, stride); 42 CAIRO_FORMAT_ARGB32, g.size.w, g.size.h, stride);
37 if (cairo_surface_status(*surface) != CAIRO_STATUS_SUCCESS) { 43 if (cairo_surface_status(*surface) != CAIRO_STATUS_SUCCESS) {
38 free(view->border); 44 border_clear(view->border);
39 view->border->buffer = NULL;
40 sway_log(L_DEBUG, "Unable to allocate surface"); 45 sway_log(L_DEBUG, "Unable to allocate surface");
41 return NULL; 46 return NULL;
42 } 47 }
43 cr = cairo_create(*surface); 48 cr = cairo_create(*surface);
44 if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) { 49 if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) {
45 cairo_surface_destroy(*surface); 50 cairo_surface_destroy(*surface);
46 free(view->border->buffer); 51 border_clear(view->border);
47 view->border->buffer = NULL;
48 sway_log(L_DEBUG, "Unable to create cairo context"); 52 sway_log(L_DEBUG, "Unable to create cairo context");
49 return NULL; 53 return NULL;
50 } 54 }
@@ -295,10 +299,8 @@ void update_view_border(swayc_t *view) {
295 cairo_t *cr = NULL; 299 cairo_t *cr = NULL;
296 cairo_surface_t *surface = NULL; 300 cairo_surface_t *surface = NULL;
297 301
298 if (view->border && view->border->buffer) { 302 // clear previous border buffer.
299 free(view->border->buffer); 303 border_clear(view->border);
300 view->border->buffer = NULL;
301 }
302 304
303 // get focused and focused_inactive views 305 // get focused and focused_inactive views
304 swayc_t *focused = get_focused_view(&root_container); 306 swayc_t *focused = get_focused_view(&root_container);
@@ -315,8 +317,8 @@ void update_view_border(swayc_t *view) {
315 317
316 // for tabbed/stacked layouts the focused view has to draw all the 318 // for tabbed/stacked layouts the focused view has to draw all the
317 // titlebars of the hidden views. 319 // titlebars of the hidden views.
318 swayc_t *p = swayc_tabbed_stacked_parent(view); 320 swayc_t *p = NULL;
319 if (p && view->parent->focused == view) { 321 if (view->parent->focused == view && (p = swayc_tabbed_stacked_parent(view))) {
320 struct wlc_geometry g = { 322 struct wlc_geometry g = {
321 .origin = { 323 .origin = {
322 .x = p->x, 324 .x = p->x,
diff --git a/sway/layout.c b/sway/layout.c
index 3e550927..902a521b 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -555,6 +555,7 @@ void update_geometry(swayc_t *container) {
555 555
556 container->border_geometry = wlc_geometry_zero; 556 container->border_geometry = wlc_geometry_zero;
557 container->title_bar_geometry = wlc_geometry_zero; 557 container->title_bar_geometry = wlc_geometry_zero;
558 border_clear(container->border);
558 } else if (container->is_floating) { // allocate border for floating window 559 } else if (container->is_floating) { // allocate border for floating window
559 update_border_geometry_floating(container, &geometry); 560 update_border_geometry_floating(container, &geometry);
560 } else if (!container->is_floating) { // allocate border for titled window 561 } else if (!container->is_floating) { // allocate border for titled window