Skip to content

Commit

Permalink
Reformat code (i3#3479)
Browse files Browse the repository at this point in the history
  • Loading branch information
buchankn committed Feb 23, 2023
1 parent 8f61a03 commit 4bb3caa
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 73 deletions.
33 changes: 16 additions & 17 deletions include/sparse_surface.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
*
* sparse_surface.c: A 'sparse surface' represents the pixmap borders around
* a window. We allocate four separate pixmaps, one for each side of the
* window, which means we don't allocate any memory for the contents of
* the window, which we don't draw to.
*
*/
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
*
* sparse_surface.c: A 'sparse surface' represents the pixmap borders around
* a window. We allocate four separate pixmaps, one for each side of the
* window, which means we don't allocate any memory for the contents of
* the window, which we don't draw to.
*
*/
#pragma once

#include <config.h>
Expand Down Expand Up @@ -56,10 +56,10 @@ bool sparse_surface_initialized(sparse_surface_t *sparse_surface);
*
*/
void sparse_surface_create_and_init(xcb_connection_t *conn, sparse_surface_t *sparse_surface,
xcb_drawable_t frame_id,
uint16_t win_depth,
xcb_visualtype_t *visual, int width, int height,
int top_height, int bottom_height, int left_width, int right_width);
xcb_drawable_t frame_id,
uint16_t win_depth,
xcb_visualtype_t *visual, int width, int height,
int top_height, int bottom_height, int left_width, int right_width);

/**
* Destroys the sparse surface.
Expand All @@ -73,13 +73,12 @@ void sparse_surface_free(xcb_connection_t *conn, sparse_surface_t *sparse_surfac
*/
void sparse_surface_clear(sparse_surface_t *sparse_surface, color_t color);


/**
* Copies a sparse surface onto another non-sparse surface.
*
*/
void sparse_surface_copy(sparse_surface_t *src_sparse, surface_t *dest, double src_x, double src_y,
double dest_x, double dest_y, double width, double height);
double dest_x, double dest_y, double width, double height);

/**
* Draw the given text using libi3.
Expand Down
57 changes: 28 additions & 29 deletions src/sparse_surface.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
*
* sparse_surface.c: A 'sparse surface' represents the pixmap borders around
* a window. We allocate four separate pixmaps, one for each side of the
* window, which means we don't allocate any memory for the contents of
* the window, which we don't draw to.
*/
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
*
* sparse_surface.c: A 'sparse surface' represents the pixmap borders around
* a window. We allocate four separate pixmaps, one for each side of the
* window, which means we don't allocate any memory for the contents of
* the window, which we don't draw to.
*/

#include "sparse_surface.h"
#include "all.h"
Expand All @@ -22,7 +22,7 @@ bool sparse_surface_initialized(sparse_surface_t *sparse_surface) {
if (sparse_surface->side_surface[SPARSE_SURFACE_TOP].id == XCB_NONE &&
sparse_surface->side_surface[SPARSE_SURFACE_BOTTOM].id == XCB_NONE &&
sparse_surface->side_surface[SPARSE_SURFACE_LEFT].id == XCB_NONE &&
sparse_surface->side_surface[SPARSE_SURFACE_RIGHT].id == XCB_NONE ) {
sparse_surface->side_surface[SPARSE_SURFACE_RIGHT].id == XCB_NONE) {
ELOG("Surface %p is not initialized, skipping drawing.\n", sparse_surface);
return false;
}
Expand Down Expand Up @@ -78,9 +78,9 @@ void sparse_surface_create_and_init(xcb_connection_t *conn, sparse_surface_t *sp
if (visual == NULL)
visual = visual_type;

if(top_height == 0 && bottom_height == 0 && left_width == 0 && right_width == 0) {
if (top_height == 0 && bottom_height == 0 && left_width == 0 && right_width == 0) {
/* There is only one pixmap for the top of the window, of size width, height */
for(i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
for (i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
sparse_surface->x_offset[i] = 0;
sparse_surface->y_offset[i] = 0;
sparse_surface->side_surface[i].width = 0;
Expand Down Expand Up @@ -115,8 +115,8 @@ void sparse_surface_create_and_init(xcb_connection_t *conn, sparse_surface_t *sp
}

/* Create each of the four pixmaps */
for(i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if(sparse_surface->side_surface[i].width == 0 || sparse_surface->side_surface[i].height == 0) {
for (i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if (sparse_surface->side_surface[i].width == 0 || sparse_surface->side_surface[i].height == 0) {
if (sparse_surface->side_surface[i].id != XCB_NONE) {
sparse_surface_free_one_side(conn, sparse_surface, i, true);
}
Expand Down Expand Up @@ -161,13 +161,12 @@ void sparse_surface_create_and_init(xcb_connection_t *conn, sparse_surface_t *sp
}
}


/*
* Destroys the sparse surface.
*
*/
void sparse_surface_free(xcb_connection_t *conn, sparse_surface_t *sparse_surface) {
for(int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
for (int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
sparse_surface_free_one_side(conn, sparse_surface, i, true);
}
}
Expand All @@ -185,7 +184,7 @@ void sparse_surface_free_one_side(xcb_connection_t *conn, sparse_surface_t *spar

xcb_free_pixmap(conn, sparse_surface->side_surface[side].id);

if(clear_id) {
if (clear_id) {
sparse_surface->side_surface[side].id = XCB_NONE;
}
}
Expand All @@ -196,7 +195,7 @@ void sparse_surface_free_one_side(xcb_connection_t *conn, sparse_surface_t *spar
*
*/
void sparse_surface_clear(sparse_surface_t *sparse_surface, color_t color) {
for(int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
for (int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if (sparse_surface->side_surface[i].id != XCB_NONE) {
draw_util_clear_surface(&(sparse_surface->side_surface[i]), color);
}
Expand All @@ -208,7 +207,7 @@ void sparse_surface_clear(sparse_surface_t *sparse_surface, color_t color) {
*
*/
void sparse_surface_copy(sparse_surface_t *src_sparse, surface_t *dest, double src_x, double src_y,
double dest_x, double dest_y, double width, double height) {
double dest_x, double dest_y, double width, double height) {
if (!sparse_surface_initialized(src_sparse) ||
dest->id == XCB_NONE) {
return;
Expand All @@ -217,7 +216,7 @@ void sparse_surface_copy(sparse_surface_t *src_sparse, surface_t *dest, double s
double src_x_adjusted;
double src_y_adjusted;

for(int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
for (int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if (src_sparse->side_surface[i].id != XCB_NONE) {
cairo_save(dest->cr);

Expand Down Expand Up @@ -255,8 +254,8 @@ void sparse_surface_copy(sparse_surface_t *src_sparse, surface_t *dest, double s
void sparse_surface_text(i3String *text, sparse_surface_t *surface, color_t fg_color, color_t bg_color, int x, int y, int max_width) {
/* Draw to each of the four border pixmaps. This ensures that any draws that cross pixmap boundaries are
* drawn correctly. */
for(int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if(surface->side_surface[i].id != XCB_NONE) {
for (int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if (surface->side_surface[i].id != XCB_NONE) {
draw_util_text(text, &(surface->side_surface[i]), fg_color, bg_color, x, y, max_width);
}
}
Expand All @@ -269,8 +268,8 @@ void sparse_surface_text(i3String *text, sparse_surface_t *surface, color_t fg_c
void sparse_surface_rectangle(sparse_surface_t *surface, color_t color, double x, double y, double w, double h) {
/* Draw to each of the four border pixmaps. This ensures that any draws that cross pixmap boundaries are
* drawn correctly. */
for(int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if(surface->side_surface[i].id != XCB_NONE) {
for (int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if (surface->side_surface[i].id != XCB_NONE) {
draw_util_rectangle(&(surface->side_surface[i]), color, x, y, w, h);
}
}
Expand All @@ -285,8 +284,8 @@ void sparse_surface_rectangle(sparse_surface_t *surface, color_t color, double x
void sparse_surface_image(cairo_surface_t *image, sparse_surface_t *surface, int x, int y, int width, int height) {
/* Draw to each of the four border pixmaps. This ensures that any draws that cross pixmap boundaries are
* drawn correctly. */
for(int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if(surface->side_surface[i].id != XCB_NONE) {
for (int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if (surface->side_surface[i].id != XCB_NONE) {
draw_util_image(image, &(surface->side_surface[i]), x, y, width, height);
}
}
Expand All @@ -296,8 +295,8 @@ void sparse_surface_image(cairo_surface_t *image, sparse_surface_t *surface, int
* Disable GraphicsExposure events
*/
void sparse_surface_disable_graphics_exposure_events(xcb_connection_t *conn, sparse_surface_t *surface) {
for(int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if(surface->side_surface[i].id != XCB_NONE) {
for (int i = 0; i < SPARSE_SURFACE_SIDE_COUNT; i++) {
if (surface->side_surface[i].id != XCB_NONE) {
xcb_change_gc(conn, surface->side_surface[i].gc, XCB_GC_GRAPHICS_EXPOSURES, (uint32_t[]){0});
}
}
Expand Down
54 changes: 27 additions & 27 deletions src/x.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,19 +358,19 @@ static void x_draw_title_border(Con *con, struct deco_render_params *p, sparse_s

/* Left */
sparse_surface_rectangle(dest_surface, p->color->border,
dr->x, dr->y, 1, dr->height);
dr->x, dr->y, 1, dr->height);

/* Right */
sparse_surface_rectangle(dest_surface, p->color->border,
dr->x + dr->width - 1, dr->y, 1, dr->height);
dr->x + dr->width - 1, dr->y, 1, dr->height);

/* Top */
sparse_surface_rectangle(dest_surface, p->color->border,
dr->x, dr->y, dr->width, 1);
dr->x, dr->y, dr->width, 1);

/* Bottom */
sparse_surface_rectangle(dest_surface, p->color->border,
dr->x, dr->y + dr->height - 1, dr->width, 1);
dr->x, dr->y + dr->height - 1, dr->width, 1);
}

static void x_draw_decoration_after_title(Con *con, struct deco_render_params *p, sparse_surface_t *dest_surface) {
Expand All @@ -386,10 +386,10 @@ static void x_draw_decoration_after_title(Con *con, struct deco_render_params *p
* distance we keep from the edge (not the entire border width).
* Redrawing the entire border would cause text to be cut off. */
sparse_surface_rectangle(dest_surface, p->color->background,
dr->x + dr->width - 2 * logical_px(1),
dr->y,
2 * logical_px(1),
dr->height);
dr->x + dr->width - 2 * logical_px(1),
dr->y,
2 * logical_px(1),
dr->height);
}

/* Redraw the border. */
Expand Down Expand Up @@ -544,16 +544,16 @@ void x_draw_decoration(Con *con) {

/* top area */
sparse_surface_rectangle(&(con->frame_buffer), config.client.background,
0, 0, r->width, w->y);
0, 0, r->width, w->y);
/* bottom area */
sparse_surface_rectangle(&(con->frame_buffer), config.client.background,
0, w->y + w->height, r->width, r->height - (w->y + w->height));
0, w->y + w->height, r->width, r->height - (w->y + w->height));
/* left area */
sparse_surface_rectangle(&(con->frame_buffer), config.client.background,
0, 0, w->x, r->height);
0, 0, w->x, r->height);
/* right area */
sparse_surface_rectangle(&(con->frame_buffer), config.client.background,
w->x + w->width, 0, r->width - (w->x + w->width), r->height);
w->x + w->width, 0, r->width - (w->x + w->width), r->height);
}

/* 3: draw a rectangle in border color around the client */
Expand All @@ -565,10 +565,10 @@ void x_draw_decoration(Con *con) {
size_t rectangles_count = x_get_border_rectangles(con, rectangles);
for (size_t i = 0; i < rectangles_count; i++) {
sparse_surface_rectangle(&(con->frame_buffer), p->color->child_border,
rectangles[i].x,
rectangles[i].y,
rectangles[i].width,
rectangles[i].height);
rectangles[i].x,
rectangles[i].y,
rectangles[i].width,
rectangles[i].height);
}

/* Highlight the side of the border at which the next window will be
Expand All @@ -581,10 +581,10 @@ void x_draw_decoration(Con *con) {
con->parent->type != CT_FLOATING_CON) {
if (p->parent_layout == L_SPLITH) {
sparse_surface_rectangle(&(con->frame_buffer), p->color->indicator,
r->width + (br.width + br.x), br.y, -(br.width + br.x), r->height + br.height);
r->width + (br.width + br.x), br.y, -(br.width + br.x), r->height + br.height);
} else if (p->parent_layout == L_SPLITV) {
sparse_surface_rectangle(&(con->frame_buffer), p->color->indicator,
br.x, r->height + (br.height + br.y), r->width + br.width, -(br.height + br.y));
br.x, r->height + (br.height + br.y), r->width + br.width, -(br.height + br.y));
}
}
}
Expand Down Expand Up @@ -619,7 +619,7 @@ void x_draw_decoration(Con *con) {
DLOG("con->deco_rect = (x=%d, y=%d, w=%d, h=%d) for con->name=%s\n",
con->deco_rect.x, con->deco_rect.y, con->deco_rect.width, con->deco_rect.height, con->name);
sparse_surface_rectangle(dest_surface, p->color->background,
con->deco_rect.x, con->deco_rect.y, con->deco_rect.width, con->deco_rect.height);
con->deco_rect.x, con->deco_rect.y, con->deco_rect.width, con->deco_rect.height);

/* 5: draw title border */
x_draw_title_border(con, p, dest_surface);
Expand Down Expand Up @@ -658,9 +658,9 @@ void x_draw_decoration(Con *con) {
: deco_width - mark_width - title_padding;

sparse_surface_text(mark, dest_surface,
p->color->text, p->color->background,
con->deco_rect.x + mark_offset_x,
con->deco_rect.y + text_offset_y, mark_width);
p->color->text, p->color->background,
con->deco_rect.x + mark_offset_x,
con->deco_rect.y + text_offset_y, mark_width);
I3STRING_FREE(mark);

mark_width += title_padding;
Expand Down Expand Up @@ -735,10 +735,10 @@ void x_draw_decoration(Con *con) {
}

sparse_surface_text(title, dest_surface,
p->color->text, p->color->background,
con->deco_rect.x + title_offset_x,
con->deco_rect.y + text_offset_y,
deco_width - mark_width - 2 * title_padding - total_icon_space);
p->color->text, p->color->background,
con->deco_rect.x + title_offset_x,
con->deco_rect.y + text_offset_y,
deco_width - mark_width - 2 * title_padding - total_icon_space);
if (has_icon) {
sparse_surface_image(
win->icon,
Expand Down Expand Up @@ -977,7 +977,7 @@ void x_push_node(Con *con) {
/* Set new position if rect changed (and if height > 0) or if the pixmap
* needs to be recreated */
if ((is_pixmap_needed && !sparse_surface_initialized(&(con->frame_buffer))) || (!rect_equals(state->rect, rect) &&
rect.height > 0)) {
rect.height > 0)) {
/* We first create the new pixmap, then render to it, set it as the
* background and only afterwards change the window size. This reduces
* flickering. */
Expand Down

0 comments on commit 4bb3caa

Please sign in to comment.