summaryrefslogtreecommitdiffstats
path: root/sway/border.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/border.c')
-rw-r--r--sway/border.c26
1 files changed, 14 insertions, 12 deletions
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,