Use cairo for all drawing operations in i3bar.

fixes #1878
This commit is contained in:
Ingo Bürk
2015-09-05 23:38:15 +02:00
parent 2248085c5c
commit 410c5da7cf
8 changed files with 288 additions and 243 deletions

View File

@ -0,0 +1,65 @@
/*
* vim:ts=4:sw=4:expandtab
*
* © 2015 Ingo Bürk and contributors (see also: LICENSE)
*
* cairo_util.h: Utility for operations using cairo.
*
*/
#pragma once
#include <cairo/cairo-xcb.h>
/* Represents a color split by color channel. */
typedef struct color_t {
double red;
double green;
double blue;
/* For compatibility, we also store the colorpixel for now. */
uint32_t colorpixel;
} color_t;
/* A wrapper grouping an XCB drawable and both a graphics context
* and the corresponding cairo objects representing it. */
typedef struct surface_t {
/* The drawable which is being represented. */
xcb_drawable_t id;
// TODO remove this once i3 uses solely cairo for drawing operations
/* A classic XCB graphics context. This should not be used for
* drawing operations. */
xcb_gcontext_t gc;
/* A cairo surface representing the drawable. */
cairo_surface_t *surface;
/* The cairo object representing the drawale. In general,
* this is what one should use for any drawing operation. */
cairo_t *cr;
} surface_t;
/**
* Initialize the cairo surface to represent the given drawable.
*
*/
void cairo_surface_init(surface_t *surface, xcb_drawable_t drawable, int width, int height);
/**
* Destroys the surface.
*
*/
void cairo_surface_free(surface_t *surface);
/**
* Parses the given color in hex format to an internal color representation.
* Note that the input must begin with a hash sign, e.g., "#3fbc59".
*
*/
color_t cairo_hex_to_color(const char *color);
/**
* Set the given color as the source color on the surface.
*
*/
void cairo_set_source_color(surface_t *surface, color_t color);

View File

@ -80,3 +80,4 @@ TAILQ_HEAD(statusline_head, status_block) statusline_head;
#include "config.h"
#include "libi3.h"
#include "parse_json_header.h"
#include "cairo_util.h"

View File

@ -10,8 +10,10 @@
#pragma once
#include <xcb/xcb.h>
#include <cairo/cairo-xcb.h>
#include "common.h"
#include "cairo_util.h"
typedef struct i3_output i3_output;
@ -44,9 +46,10 @@ struct i3_output {
int ws; /* The number of the currently visible ws */
rect rect; /* The rect (relative to the root window) */
xcb_window_t bar; /* The id of the bar of the output */
xcb_pixmap_t buffer; /* An extra pixmap for double-buffering */
xcb_gcontext_t bargc; /* The graphical context of the bar */
/* Off-screen buffer for preliminary rendering. */
surface_t buffer;
/* The actual window on which we draw. */
surface_t bar;
struct ws_head* workspaces; /* The workspaces on this output */
struct tc_head* trayclients; /* The tray clients on this output */

View File

@ -24,6 +24,12 @@
#define XEMBED_MAPPED (1 << 0)
#define XEMBED_EMBEDDED_NOTIFY 0
xcb_connection_t *xcb_connection;
/* We define xcb_request_failed as a macro to include the relevant line number */
#define xcb_request_failed(cookie, err_msg) _xcb_request_failed(cookie, err_msg, __LINE__)
int _xcb_request_failed(xcb_void_cookie_t cookie, char *err_msg, int line);
struct xcb_color_strings_t {
char *bar_fg;
char *bar_bg;