From 916e23861ac3fdce5adab8c386e4b0ba9b7f8a69 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 20 Jan 2019 16:53:39 +0000 Subject: [PATCH] Improve the header includes, cont'd Also check in the modulemap file, and add a option to build with clang's -fmodules. Signed-off-by: Yuxuan Shui --- meson.build | 11 +++ meson_options.txt | 2 + src/backend/backend.c | 4 ++ src/backend/backend.h | 1 + src/backend/backend_common.c | 8 ++- src/backend/gl/gl_common.c | 30 ++++---- src/backend/gl/gl_common.h | 1 + src/backend/gl/glx.c | 129 +++++++++++++++++------------------ src/backend/xrender.c | 79 ++++++++++----------- src/c2.c | 20 +++--- src/common.h | 33 ++------- src/compton.modulemap | 84 +++++++++++++++++++++++ src/config.c | 3 + src/config.h | 3 +- src/config_libconfig.c | 3 + src/dbus.c | 4 ++ src/kernel.c | 1 + src/log.c | 3 +- src/opengl.c | 6 ++ src/options.c | 3 + src/render.c | 13 +++- src/utils.h | 2 +- src/win.c | 4 ++ src/win.h | 1 + 24 files changed, 277 insertions(+), 171 deletions(-) create mode 100644 src/compton.modulemap diff --git a/meson.build b/meson.build index 6565a24..09c2037 100644 --- a/meson.build +++ b/meson.build @@ -33,6 +33,17 @@ if get_option('sanitize') add_global_link_arguments('-fsanitize='+','.join(sanitizers), language: 'c') endif +if get_option('modularize') + if not cc.has_argument('-fmodules') + error('option \'modularize\' requires clang') + endif + add_global_arguments(['-fmodules', + '-fmodule-map-file='+ + meson.current_source_dir()+ + '/src/compton.modulemap'], + language: 'c') +endif + add_global_arguments('-D_GNU_SOURCE', language: 'c') warns = [ 'all', 'extra', 'no-unused-parameter', 'nonnull', 'shadow', 'implicit-fallthrough' ] diff --git a/meson_options.txt b/meson_options.txt index 3e1bd07..1a15445 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -13,3 +13,5 @@ option('xrescheck', type: 'boolean', value: false, description: 'Enable X resour option('build_docs', type: 'boolean', value: false, description: 'Build documentation and man pages') option('new_backends', type: 'boolean', value: false, description: 'Does not really do anything right now') + +option('modularize', type: 'boolean', value: false, description: 'Build with clang\'s module system') diff --git a/src/backend/backend.c b/src/backend/backend.c index 1dbf2c7..0b0923e 100644 --- a/src/backend/backend.c +++ b/src/backend/backend.c @@ -1,5 +1,9 @@ #include "backend.h" +#include "config.h" +#include "win.h" +#include "region.h" #include "common.h" +#include "compiler.h" backend_info_t *backend_list[NUM_BKEND] = {[BKEND_XRENDER] = &xrender_backend}; diff --git a/src/backend/backend.h b/src/backend/backend.h index 554d199..a292e8d 100644 --- a/src/backend/backend.h +++ b/src/backend/backend.h @@ -4,6 +4,7 @@ #pragma once #include "region.h" +#include "compiler.h" typedef struct session session_t; typedef struct win win; diff --git a/src/backend/backend_common.c b/src/backend/backend_common.c index 968d7ed..6b5d9e7 100644 --- a/src/backend/backend_common.c +++ b/src/backend/backend_common.c @@ -1,9 +1,11 @@ #include +#include #include "backend.h" #include "backend_common.h" #include "kernel.h" #include "common.h" +#include "log.h" #include "x.h" /** @@ -178,9 +180,9 @@ bool build_shadow(session_t *ps, double opacity, const int width, const int heig xcb_render_picture_t shadow_pixel, xcb_pixmap_t *pixmap, xcb_render_picture_t *pict) { xcb_image_t *shadow_image = NULL; - xcb_pixmap_t shadow_pixmap = None, shadow_pixmap_argb = None; - xcb_render_picture_t shadow_picture = None, shadow_picture_argb = None; - xcb_gcontext_t gc = None; + xcb_pixmap_t shadow_pixmap = XCB_NONE, shadow_pixmap_argb = XCB_NONE; + xcb_render_picture_t shadow_picture = XCB_NONE, shadow_picture_argb = XCB_NONE; + xcb_gcontext_t gc = XCB_NONE; shadow_image = make_shadow(ps->c, ps->gaussian_map, opacity, width, height); diff --git a/src/backend/gl/gl_common.c b/src/backend/gl/gl_common.c index 3766033..ef5df84 100644 --- a/src/backend/gl/gl_common.c +++ b/src/backend/gl/gl_common.c @@ -1,11 +1,15 @@ #include #include -#include #include +#include #include "common.h" #include "log.h" +#include "region.h" #include "string_utils.h" +#include "utils.h" +#include "compiler.h" +#include "config.h" #include "backend/gl/gl_common.h" @@ -420,8 +424,7 @@ bool gl_blur_dst(session_t *ps, const gl_cap_t *cap, int dx, int dy, int width, GL_TEXTURE_2D, tex_scr2, 0); // XXX wrong, should use tex_tgt glDrawBuffers(1, (GLenum[]){GL_COLOR_ATTACHMENT0}); - if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != - GL_FRAMEBUFFER_COMPLETE) { + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { log_error("Framebuffer attachment failed."); goto end; } @@ -451,10 +454,8 @@ bool gl_blur_dst(session_t *ps, const gl_cap_t *cap, int dx, int dy, int width, // Texture coordinates const GLfloat texture_x1 = (crect.x1 - dx) * texfac_x; const GLfloat texture_y1 = (crect.y1 - dy) * texfac_y; - const GLfloat texture_x2 = - texture_x1 + (crect.x2 - crect.x1) * texfac_x; - const GLfloat texture_y2 = - texture_y1 + (crect.y2 - crect.y1) * texfac_y; + const GLfloat texture_x2 = texture_x1 + (crect.x2 - crect.x1) * texfac_x; + const GLfloat texture_y2 = texture_y1 + (crect.y2 - crect.y1) * texfac_y; // Vertex coordinates // For passes before the last one, we are drawing into a buffer, @@ -470,10 +471,8 @@ bool gl_blur_dst(session_t *ps, const gl_cap_t *cap, int dx, int dy, int width, GLfloat vx2 = vx1 + (crect.x2 - crect.x1); GLfloat vy2 = vy1 + (crect.y2 - crect.y1); - GLfloat texture_x[] = {texture_x1, texture_x2, texture_x2, - texture_x1}; - GLfloat texture_y[] = {texture_y1, texture_y1, texture_y2, - texture_y2}; + GLfloat texture_x[] = {texture_x1, texture_x2, texture_x2, texture_x1}; + GLfloat texture_y[] = {texture_y1, texture_y1, texture_y2, texture_y2}; GLint vx[] = {vx1, vx2, vx2, vx1}; GLint vy[] = {vy1, vy1, vy2, vy2}; @@ -595,7 +594,8 @@ static void attr_unused gl_destroy_win_shader(session_t *ps, gl_win_shader_t *sh /** * Initialize GL blur filters. * - * Fill `passes` with blur filters, won't create more than MAX_BLUR_FILTER number of filters + * Fill `passes` with blur filters, won't create more than MAX_BLUR_FILTER number of + * filters */ bool gl_create_blur_filters(session_t *ps, gl_blur_shader_t *passes, const gl_cap_t *cap) { assert(ps->o.blur_kerns[0]); @@ -663,8 +663,7 @@ bool gl_create_blur_filters(session_t *ps, gl_blur_shader_t *passes, const gl_ca int nele = wid * hei - 1; unsigned int len = strlen(FRAG_SHADER_BLUR_PREFIX) + strlen(sampler_type) + - strlen(extension) + - (strlen(shader_add) + strlen(texture_func) + 42) * nele + + strlen(extension) + (strlen(shader_add) + strlen(texture_func) + 42) * nele + strlen(FRAG_SHADER_BLUR_SUFFIX) + strlen(texture_func) + 12 + 1; char *shader_str = ccalloc(len, char); char *pc = shader_str; @@ -681,8 +680,7 @@ bool gl_create_blur_filters(session_t *ps, gl_blur_shader_t *passes, const gl_ca if (0.0 == val) continue; sum += val; - sprintf(pc, shader_add, val, texture_func, k - wid / 2, - j - hei / 2); + sprintf(pc, shader_add, val, texture_func, k - wid / 2, j - hei / 2); pc += strlen(pc); assert(strlen(shader_str) < len); } diff --git a/src/backend/gl/gl_common.h b/src/backend/gl/gl_common.h index 96e316b..63aff46 100644 --- a/src/backend/gl/gl_common.h +++ b/src/backend/gl/gl_common.h @@ -3,6 +3,7 @@ #include #include "common.h" +#include "log.h" // Program and uniforms for window shader typedef struct { diff --git a/src/backend/gl/glx.c b/src/backend/gl/glx.c index 49fe890..8956b88 100644 --- a/src/backend/gl/glx.c +++ b/src/backend/gl/glx.c @@ -10,9 +10,19 @@ */ #include +#include +#include + #include "backend/backend.h" #include "backend/gl/gl_common.h" +#include "common.h" +#include "compiler.h" +#include "log.h" +#include "region.h" #include "string_utils.h" +#include "utils.h" +#include "win.h" +#include "config.h" /// @brief Wrapper of a GLX FBConfig. typedef struct glx_fbconfig { @@ -87,8 +97,7 @@ static void glx_release_pixmap(struct _glx_data *gd, Display *dpy, struct _glx_w /** * Free a glx_texture_t. */ -static void attr_unused glx_release_win(struct _glx_data *gd, Display *dpy, - struct _glx_win_data *wd) { +static void attr_unused glx_release_win(struct _glx_data *gd, Display *dpy, struct _glx_win_data *wd) { glx_release_pixmap(gd, dpy, wd); glDeleteTextures(1, &wd->texture.texture); @@ -161,8 +170,8 @@ glx_cmp_fbconfig(session_t *ps, const glx_fbconfig_t *pfbc_a, const glx_fbconfig /** * @brief Update the FBConfig of given depth. */ -static inline void -glx_update_fbconfig_bydepth(session_t *ps, struct _glx_data *gd, int depth, glx_fbconfig_t *pfbcfg) { +static inline void glx_update_fbconfig_bydepth(session_t *ps, struct _glx_data *gd, + int depth, glx_fbconfig_t *pfbcfg) { // Make sure the depth is sane if (depth < 0 || depth > OPENGL_MAX_DEPTH) return; @@ -170,8 +179,7 @@ glx_update_fbconfig_bydepth(session_t *ps, struct _glx_data *gd, int depth, glx_ // Compare new FBConfig with current one if (glx_cmp_fbconfig(ps, gd->fbconfigs[depth], pfbcfg) < 0) { log_debug("(depth %d): %p overrides %p, target %#x.\n", depth, pfbcfg->cfg, - gd->fbconfigs[depth] ? gd->fbconfigs[depth]->cfg : 0, - pfbcfg->texture_tgts); + gd->fbconfigs[depth] ? gd->fbconfigs[depth]->cfg : 0, pfbcfg->texture_tgts); if (!gd->fbconfigs[depth]) { gd->fbconfigs[depth] = cmalloc(glx_fbconfig_t); } @@ -200,21 +208,18 @@ static bool glx_update_fbconfig(struct _glx_data *gd, session_t *ps) { // Skip over multi-sampled visuals // http://people.freedesktop.org/~glisse/0001-glx-do-not-use-multisample-visual-config-for-front-o.patch #ifdef GLX_SAMPLES - if (Success == glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_SAMPLES, &val) && - val > 1) + if (Success == glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_SAMPLES, &val) && val > 1) continue; #endif if (Success != glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_BUFFER_SIZE, &depth) || - Success != glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_ALPHA_SIZE, - &depth_alpha)) { + Success != glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_ALPHA_SIZE, &depth_alpha)) { log_error("Failed to retrieve buffer size and alpha size of " "FBConfig %d.", id); continue; } - if (Success != glXGetFBConfigAttrib(ps->dpy, *pcur, - GLX_BIND_TO_TEXTURE_TARGETS_EXT, + if (Success != glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_BIND_TO_TEXTURE_TARGETS_EXT, &fbinfo.texture_tgts)) { log_error("Failed to retrieve BIND_TO_TEXTURE_TARGETS_EXT of " "FBConfig %d.", @@ -238,14 +243,10 @@ static bool glx_update_fbconfig(struct _glx_data *gd, session_t *ps) { bool rgba = false; if (depth >= 32 && depth_alpha && - Success == glXGetFBConfigAttrib(ps->dpy, *pcur, - GLX_BIND_TO_TEXTURE_RGBA_EXT, &val) && - val) + Success == glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_BIND_TO_TEXTURE_RGBA_EXT, &val) && val) rgba = true; - if (Success == glXGetFBConfigAttrib(ps->dpy, *pcur, - GLX_BIND_TO_TEXTURE_RGB_EXT, &val) && - val) + if (Success == glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_BIND_TO_TEXTURE_RGB_EXT, &val) && val) rgb = true; if (Success == glXGetFBConfigAttrib(ps->dpy, *pcur, GLX_Y_INVERTED_EXT, &val)) @@ -282,14 +283,12 @@ static bool glx_update_fbconfig(struct _glx_data *gd, session_t *ps) { } #ifdef DEBUG_GLX_DEBUG_CONTEXT -static inline GLXFBConfig -get_fbconfig_from_visualinfo(session_t *ps, const XVisualInfo *visualinfo) { +static inline GLXFBConfig get_fbconfig_from_visualinfo(session_t *ps, const XVisualInfo *visualinfo) { int nelements = 0; GLXFBConfig *fbconfigs = glXGetFBConfigs(ps->dpy, visualinfo->screen, &nelements); for (int i = 0; i < nelements; ++i) { int visual_id = 0; - if (Success == glXGetFBConfigAttrib(ps->dpy, fbconfigs[i], GLX_VISUAL_ID, - &visual_id) && + if (Success == glXGetFBConfigAttrib(ps->dpy, fbconfigs[i], GLX_VISUAL_ID, &visual_id) && visual_id == visualinfo->visualid) return fbconfigs[i]; } @@ -521,8 +520,7 @@ void *glx_prepare_win(void *backend_data, session_t *ps, win *w) { }; auto wd = ccalloc(1, struct _glx_win_data); - wd->texture.target = - (GLX_TEXTURE_2D_EXT == tex_tgt ? GL_TEXTURE_2D : GL_TEXTURE_RECTANGLE); + wd->texture.target = (GLX_TEXTURE_2D_EXT == tex_tgt ? GL_TEXTURE_2D : GL_TEXTURE_RECTANGLE); wd->texture.y_inverted = pcfg->y_inverted; if (ps->has_name_pixmap) { @@ -575,8 +573,7 @@ err: /** * Bind a X pixmap to an OpenGL texture. */ -void glx_render_win(void *backend_data, session_t *ps, win *w, void *win_data, - const region_t *reg_paint) { +void glx_render_win(void *backend_data, session_t *ps, win *w, void *win_data, const region_t *reg_paint) { struct _glx_data *gd = backend_data; struct _glx_win_data *wd = win_data; @@ -594,60 +591,58 @@ void glx_render_win(void *backend_data, session_t *ps, win *w, void *win_data, /** * Preprocess function before start painting. */ -static void attr_unused -glx_paint_pre(session_t *ps, region_t *preg) { - // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +static void attr_unused glx_paint_pre(session_t *ps, region_t *preg) { + // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - // Get buffer age - bool trace_damage = (ps->o.glx_swap_method < 0 || ps->o.glx_swap_method > 1); + // Get buffer age + bool trace_damage = (ps->o.glx_swap_method < 0 || ps->o.glx_swap_method > 1); - // Trace raw damage regions - region_t newdamage; - pixman_region32_init(&newdamage); - if (trace_damage) - copy_region(&newdamage, preg); + // Trace raw damage regions + region_t newdamage; + pixman_region32_init(&newdamage); + if (trace_damage) + copy_region(&newdamage, preg); - // We use GLX buffer_age extension to decide which pixels in - // the back buffer is reusable, and limit our redrawing - int buffer_age = 0; + // We use GLX buffer_age extension to decide which pixels in + // the back buffer is reusable, and limit our redrawing + int buffer_age = 0; - // Query GLX_EXT_buffer_age for buffer age - if (ps->o.glx_swap_method == SWAPM_BUFFER_AGE) { - unsigned val = 0; - glXQueryDrawable(ps->dpy, get_tgt_window(ps), - GLX_BACK_BUFFER_AGE_EXT, &val); - buffer_age = val; - } + // Query GLX_EXT_buffer_age for buffer age + if (ps->o.glx_swap_method == SWAPM_BUFFER_AGE) { + unsigned val = 0; + glXQueryDrawable(ps->dpy, get_tgt_window(ps), GLX_BACK_BUFFER_AGE_EXT, &val); + buffer_age = val; + } - // Buffer age too high - if (buffer_age > CGLX_MAX_BUFFER_AGE + 1) - buffer_age = 0; + // Buffer age too high + if (buffer_age > CGLX_MAX_BUFFER_AGE + 1) + buffer_age = 0; - assert(buffer_age >= 0); + assert(buffer_age >= 0); - if (buffer_age) { - // Determine paint area - for (int i = 0; i < buffer_age - 1; ++i) - pixman_region32_union(preg, preg, &ps->all_damage_last[i]); - } else - // buffer_age == 0 means buffer age is not available, paint everything - copy_region(preg, &ps->screen_reg); + if (buffer_age) { + // Determine paint area + for (int i = 0; i < buffer_age - 1; ++i) + pixman_region32_union(preg, preg, &ps->all_damage_last[i]); + } else + // buffer_age == 0 means buffer age is not available, paint everything + copy_region(preg, &ps->screen_reg); - if (trace_damage) { - // XXX use a circular queue instead of memmove - pixman_region32_fini(&ps->all_damage_last[CGLX_MAX_BUFFER_AGE - 1]); - memmove(ps->all_damage_last + 1, ps->all_damage_last, - (CGLX_MAX_BUFFER_AGE - 1) * sizeof(region_t *)); - ps->all_damage_last[0] = newdamage; - } + if (trace_damage) { + // XXX use a circular queue instead of memmove + pixman_region32_fini(&ps->all_damage_last[CGLX_MAX_BUFFER_AGE - 1]); + memmove(ps->all_damage_last + 1, ps->all_damage_last, + (CGLX_MAX_BUFFER_AGE - 1) * sizeof(region_t *)); + ps->all_damage_last[0] = newdamage; + } - //gl_set_clip(ps, preg); + // gl_set_clip(ps, preg); #ifdef DEBUG_GLX_PAINTREG - glx_render_color(ps, 0, 0, ps->root_width, ps->root_height, 0, *preg, NULL); + glx_render_color(ps, 0, 0, ps->root_width, ps->root_height, 0, *preg, NULL); #endif - gl_check_err(); + gl_check_err(); } backend_info_t glx_backend = { diff --git a/src/backend/xrender.c b/src/backend/xrender.c index 4a49d5c..a57543e 100644 --- a/src/backend/xrender.c +++ b/src/backend/xrender.c @@ -7,8 +7,12 @@ #include "backend/backend.h" #include "backend_common.h" #include "common.h" +#include "config.h" +#include "log.h" +#include "region.h" #include "utils.h" #include "win.h" +#include "x.h" #define auto __auto_type @@ -108,8 +112,7 @@ static void compose(void *backend_data, session_t *ps, win *w, void *win_data, i pixman_region32_intersect(®_tmp, ®_tmp, (region_t *)reg_paint); #ifdef CONFIG_XINERAMA - if (ps->o.xinerama_shadow_crop && w->xinerama_scr >= 0 && - w->xinerama_scr < ps->xinerama_nscrs) + if (ps->o.xinerama_shadow_crop && w->xinerama_scr >= 0 && w->xinerama_scr < ps->xinerama_nscrs) // There can be a window where number of screens is updated, // but the screen number attached to the windows have not. // @@ -128,10 +131,10 @@ static void compose(void *backend_data, session_t *ps, win *w, void *win_data, i // Detect if the region is empty before painting if (pixman_region32_not_empty(®_tmp)) { x_set_picture_clip_region(ps, xd->back, 0, 0, ®_tmp); - xcb_render_composite( - ps->c, XCB_RENDER_PICT_OP_OVER, wd->shadow_pict, alpha_pict, - xd->back, 0, 0, 0, 0, dst_x + w->shadow_dx, - dst_y + w->shadow_dy, w->shadow_width, w->shadow_height); + xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_OVER, + wd->shadow_pict, alpha_pict, xd->back, 0, 0, 0, + 0, dst_x + w->shadow_dx, dst_y + w->shadow_dy, + w->shadow_width, w->shadow_height); } pixman_region32_fini(®_tmp); pixman_region32_fini(&shadow_reg); @@ -154,8 +157,7 @@ static inline void xrfilter_reset(session_t *ps, xcb_render_picture_t p) { xcb_render_set_picture_filter(ps->c, p, strlen(filter), filter, 0, NULL); } -static bool -blur(void *backend_data, session_t *ps, double opacity, const region_t *reg_paint) { +static bool blur(void *backend_data, session_t *ps, double opacity, const region_t *reg_paint) { struct _xrender_data *xd = backend_data; const pixman_box32_t *reg = pixman_region32_extents((region_t *)reg_paint); const int height = reg->y2 - reg->y1; @@ -203,14 +205,12 @@ blur(void *backend_data, session_t *ps, double opacity, const region_t *reg_pain // be applied on source picture, to get the nearby pixels outside the // window. xcb_render_set_picture_filter(ps->c, src_pict, strlen(XRFILTER_CONVOLUTION), - XRFILTER_CONVOLUTION, kwid * khei + 2, - convolution_blur); + XRFILTER_CONVOLUTION, kwid * khei + 2, convolution_blur); if (ps->o.blur_kerns[i + 1] || i == 0) { // This is not the last pass, or this is the first pass - xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, src_pict, - XCB_NONE, dst_pict, src_x, src_y, 0, 0, 0, 0, - width, height); + xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, src_pict, XCB_NONE, + dst_pict, src_x, src_y, 0, 0, 0, 0, width, height); } else { // This is the last pass, and this is also not the first xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_OVER, src_pict, @@ -238,8 +238,8 @@ blur(void *backend_data, session_t *ps, double opacity, const region_t *reg_pain return true; } -static void render_win(void *backend_data, session_t *ps, win *w, void *win_data, - const region_t *reg_paint) { +static void +render_win(void *backend_data, session_t *ps, win *w, void *win_data, const region_t *reg_paint) { struct _xrender_data *xd = backend_data; struct _xrender_win_data *wd = win_data; @@ -266,22 +266,21 @@ static void render_win(void *backend_data, session_t *ps, win *w, void *win_data // Copy the content of the window over to the buffer x_clear_picture_clip_region(ps, wd->buffer); wd->rendered_pict = wd->buffer; - xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, wd->pict, None, + xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, wd->pict, XCB_NONE, wd->rendered_pict, 0, 0, 0, 0, 0, 0, w->widthb, w->heightb); if (w->invert_color) { // Handle invert color x_set_picture_clip_region(ps, wd->rendered_pict, 0, 0, ®_paint_local); - xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_DIFFERENCE, - xd->white_pixel, None, wd->rendered_pict, 0, 0, 0, 0, - 0, 0, w->widthb, w->heightb); + xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_DIFFERENCE, xd->white_pixel, XCB_NONE, + wd->rendered_pict, 0, 0, 0, 0, 0, 0, w->widthb, w->heightb); // We use an extra PictOpInReverse operation to get correct pixel // alpha. There could be a better solution. if (win_has_alpha(w)) xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_IN_REVERSE, - wd->pict, None, wd->rendered_pict, 0, 0, 0, - 0, 0, 0, w->widthb, w->heightb); + wd->pict, XCB_NONE, wd->rendered_pict, 0, 0, + 0, 0, 0, 0, w->widthb, w->heightb); } const double dopacity = get_opacity_percent(w); @@ -302,9 +301,8 @@ static void render_win(void *backend_data, session_t *ps, win *w, void *win_data // Step 2: multiply alpha value // XXX test - xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, xd->white_pixel, - alpha_pict, wd->rendered_pict, 0, 0, 0, 0, 0, 0, - w->widthb, w->heightb); + xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, xd->white_pixel, alpha_pict, + wd->rendered_pict, 0, 0, 0, 0, 0, 0, w->widthb, w->heightb); } if (w->dim) { @@ -359,8 +357,7 @@ static void *prepare_win(void *backend_data, session_t *ps, win *w) { // leave this here until we have chance to re-think the backend API if (w->shadow) { xcb_pixmap_t pixmap; - build_shadow(ps, 1, w->widthb, w->heightb, xd->shadow_pixel, &pixmap, - &wd->shadow_pict); + build_shadow(ps, 1, w->widthb, w->heightb, xd->shadow_pixel, &pixmap, &wd->shadow_pict); xcb_free_pixmap(ps->c, pixmap); } return wd; @@ -383,17 +380,17 @@ static void *init(session_t *ps) { for (int i = 0; i < 256; ++i) { double o = (double)i / 255.0; xd->alpha_pict[i] = solid_picture(ps, false, o, 0, 0, 0); - assert(xd->alpha_pict[i] != None); + assert(xd->alpha_pict[i] != XCB_NONE); } xd->black_pixel = solid_picture(ps, true, 1, 0, 0, 0); xd->white_pixel = solid_picture(ps, true, 1, 1, 1, 1); - xd->shadow_pixel = solid_picture(ps, true, 1, ps->o.shadow_red, - ps->o.shadow_green, ps->o.shadow_blue); + xd->shadow_pixel = + solid_picture(ps, true, 1, ps->o.shadow_red, ps->o.shadow_green, ps->o.shadow_blue); if (ps->overlay != XCB_NONE) { - xd->target = x_create_picture_with_visual_and_pixmap( - ps, ps->vis, ps->overlay, 0, NULL); + xd->target = + x_create_picture_with_visual_and_pixmap(ps, ps->vis, ps->overlay, 0, NULL); xd->target_win = ps->overlay; } else { xcb_render_create_picture_value_list_t pa = { @@ -412,15 +409,14 @@ static void *init(session_t *ps) { xd->back_pixmap = x_create_pixmap(ps, pictfmt->depth, ps->root, ps->root_width, ps->root_height); - xd->back = - x_create_picture_with_pictfmt_and_pixmap(ps, pictfmt, xd->back_pixmap, 0, NULL); + xd->back = x_create_picture_with_pictfmt_and_pixmap(ps, pictfmt, xd->back_pixmap, 0, NULL); xcb_pixmap_t root_pixmap = x_get_root_back_pixmap(ps); if (root_pixmap == XCB_NONE) { xd->root_pict = solid_picture(ps, false, 1, 0.5, 0.5, 0.5); } else { - xd->root_pict = x_create_picture_with_visual_and_pixmap( - ps, ps->vis, root_pixmap, 0, NULL); + xd->root_pict = + x_create_picture_with_visual_and_pixmap(ps, ps->vis, root_pixmap, 0, NULL); } if (ps->present_exists) { @@ -472,11 +468,11 @@ static void present(void *backend_data, session_t *ps) { if (ps->o.vsync != VSYNC_NONE && ps->present_exists) { // Only reset the fence when we are sure we will trigger it again. - // To make sure rendering won't get stuck if user toggles vsync on the fly. + // To make sure rendering won't get stuck if user toggles vsync on the + // fly. xcb_sync_reset_fence(ps->c, xd->idle_fence); - xcb_present_pixmap(ps->c, xd->target_win, xd->back_pixmap, 0, XCB_NONE, - XCB_NONE, 0, 0, XCB_NONE, XCB_NONE, xd->idle_fence, 0, - 0, 1, 0, 0, NULL); + xcb_present_pixmap(ps->c, xd->target_win, xd->back_pixmap, 0, XCB_NONE, XCB_NONE, + 0, 0, XCB_NONE, XCB_NONE, xd->idle_fence, 0, 0, 1, 0, 0, NULL); } else { // compose() sets clip region, so clear it first to make // sure we update the whole screen. @@ -484,9 +480,8 @@ static void present(void *backend_data, session_t *ps) { // TODO buffer-age-like optimization might be possible here. // but that will require a different backend API - xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, xd->back, None, - xd->target, 0, 0, 0, 0, 0, 0, ps->root_width, - ps->root_height); + xcb_render_composite(ps->c, XCB_RENDER_PICT_OP_SRC, xd->back, XCB_NONE, xd->target, + 0, 0, 0, 0, 0, 0, ps->root_width, ps->root_height); } } diff --git a/src/c2.c b/src/c2.c index af63667..bbf6886 100644 --- a/src/c2.c +++ b/src/c2.c @@ -27,13 +27,19 @@ #endif +#include +#include + #include "common.h" #include "win.h" -#include "c2.h" #include "config.h" #include "string_utils.h" #include "utils.h" #include "log.h" +#include "x.h" +#include "compiler.h" + +#include "c2.h" #pragma GCC diagnostic error "-Wunused-parameter" @@ -103,7 +109,7 @@ struct _c2_l { } match : 3; bool match_ignorecase : 1; char *tgt; - Atom tgtatom; + xcb_atom_t tgtatom; bool tgt_onframe; int index; enum { @@ -341,7 +347,7 @@ c2h_dump_str_type(const c2_l_t *pleaf); static void attr_unused c2_dump(c2_ptr_t p); -static Atom +static xcb_atom_t c2_get_atom_type(const c2_l_t *pleaf); static bool @@ -1331,7 +1337,7 @@ c2_dump(c2_ptr_t p) { /** * Get the type atom of a condition. */ -static Atom +static xcb_atom_t c2_get_atom_type(const c2_l_t *pleaf) { switch (pleaf->type) { case C2_L_TCARDINAL: @@ -1348,9 +1354,7 @@ c2_get_atom_type(const c2_l_t *pleaf) { assert(0); break; } - - assert(0); - return AnyPropertyType; + unreachable; } /** @@ -1454,7 +1458,7 @@ c2_match_once_leaf(session_t *ps, win *w, const c2_l_t *pleaf, else if (C2_L_TATOM == pleaf->type) { winprop_t prop = wid_get_prop_adv(ps, wid, pleaf->tgtatom, idx, 1L, c2_get_atom_type(pleaf), pleaf->format); - Atom atom = winprop_get_int(prop); + xcb_atom_t atom = winprop_get_int(prop); if (atom) { xcb_get_atom_name_reply_t *reply = xcb_get_atom_name_reply(ps->c, xcb_get_atom_name(ps->c, atom), NULL); diff --git a/src/common.h b/src/common.h index f366c02..6f01f2b 100644 --- a/src/common.h +++ b/src/common.h @@ -93,6 +93,10 @@ #include "kernel.h" #include "render.h" #include "config.h" +#include "log.h" +#include "compiler.h" +#include "utils.h" +#include "x.h" // === Constants === @@ -206,35 +210,6 @@ typedef void (*f_BindTexImageEXT) (Display *display, GLXDrawable drawable, int b typedef void (*f_ReleaseTexImageEXT) (Display *display, GLXDrawable drawable, int buffer); #ifdef CONFIG_OPENGL -// Looks like duplicate typedef of the same type is safe? -typedef int64_t GLint64; -typedef uint64_t GLuint64; -typedef struct __GLsync *GLsync; - -#ifndef GL_SYNC_FLUSH_COMMANDS_BIT -#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 -#endif - -#ifndef GL_TIMEOUT_IGNORED -#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull -#endif - -#ifndef GL_ALREADY_SIGNALED -#define GL_ALREADY_SIGNALED 0x911A -#endif - -#ifndef GL_TIMEOUT_EXPIRED -#define GL_TIMEOUT_EXPIRED 0x911B -#endif - -#ifndef GL_CONDITION_SATISFIED -#define GL_CONDITION_SATISFIED 0x911C -#endif - -#ifndef GL_WAIT_FAILED -#define GL_WAIT_FAILED 0x911D -#endif - typedef GLsync (*f_FenceSync) (GLenum condition, GLbitfield flags); typedef GLboolean (*f_IsSync) (GLsync sync); typedef void (*f_DeleteSync) (GLsync sync); diff --git a/src/compton.modulemap b/src/compton.modulemap new file mode 100644 index 0000000..3e20f4b --- /dev/null +++ b/src/compton.modulemap @@ -0,0 +1,84 @@ +// modulemap +// Generated by: modularize -module-map-path=modulemap list -I. -I/usr/include/pixman-1 -x c -I/usr/include/dbus-1.0 -DCONFIG_XINERAMA -DCONFIG_LIBCONFIG -DCONFIG_REGEX_PCRE -DCONFIG_REGEX_PCRE_JIT -DCONFIG_OPENGL -DCONFIG_DBUS -DGL_GLEXT_PROTOTYPES -I/usr/lib/dbus-1.0/include + +module compiler { + header "compiler.h" +} +module string_utils { + header "string_utils.h" +} +module dbus { + header "dbus.h" +} +module kernel { + header "kernel.h" +} +module utils { + header "utils.h" +} +module region { + header "region.h" +} +module compton { + header "compton.h" + exclude header "/usr/include/X11/Xlib.h" +} +module types { + header "types.h" +} +module c2 { + header "c2.h" +} +module render { + header "render.h" +} +module options { + header "options.h" +} +module opengl { + header "opengl.h" +} +module diagnostic { + header "diagnostic.h" +} +module win { + header "win.h" + exclude header "/usr/include/GL/glx.h" +} +module log { + header "log.h" +} +module x { + header "x.h" +} +module vsync { + header "vsync.h" +} +module common { + header "common.h" + exclude header "/usr/include/X11/Xlib.h" + exclude header "/usr/include/GL/glx.h" +} +module config { + header "config.h" +} +module xrescheck { + header "xrescheck.h" +} +module backend { + module gl { + module gl_common { + header "backend/gl/gl_common.h" + } + } + module backend { + header "backend/backend.h" + } + module backend_common { + header "backend/backend_common.h" + } +} +module Xlib { + header "/usr/include/X11/Xlib.h" + export * +} diff --git a/src/config.c b/src/config.c index db9d237..26456e2 100644 --- a/src/config.c +++ b/src/config.c @@ -11,6 +11,9 @@ #include "c2.h" #include "string_utils.h" #include "log.h" +#include "region.h" +#include "types.h" +#include "win.h" #include "config.h" diff --git a/src/config.h b/src/config.h index 205c11c..1059c6b 100644 --- a/src/config.h +++ b/src/config.h @@ -7,9 +7,10 @@ /// Common functions and definitions for configuration parsing /// Used for command line arguments and config files +#include #include #include -#include +#include #include #ifdef CONFIG_LIBCONFIG diff --git a/src/config_libconfig.c b/src/config_libconfig.c index 9ba9b9a..d980fd2 100644 --- a/src/config_libconfig.c +++ b/src/config_libconfig.c @@ -10,10 +10,13 @@ #include #include "common.h" +#include "compiler.h" #include "config.h" #include "string_utils.h" #include "options.h" #include "log.h" +#include "utils.h" +#include "win.h" #pragma GCC diagnostic error "-Wunused-parameter" diff --git a/src/dbus.c b/src/dbus.c index d162ec9..0fe7918 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -12,10 +12,14 @@ #include #include #include +#include +#include #include "common.h" #include "config.h" #include "compiler.h" +#include "utils.h" +#include "types.h" #include "win.h" #include "string_utils.h" #include "log.h" diff --git a/src/kernel.c b/src/kernel.c index f4badbe..86eb4af 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -4,6 +4,7 @@ #include #include +#include "compiler.h" #include "kernel.h" #include "utils.h" diff --git a/src/log.c b/src/log.c index 5ff700f..0f93daf 100644 --- a/src/log.c +++ b/src/log.c @@ -8,7 +8,8 @@ #include #ifdef CONFIG_OPENGL -#include +#include +#include "opengl.h" #endif #include "compiler.h" diff --git a/src/opengl.c b/src/opengl.c index 52aea96..e6dc9ce 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -9,10 +9,16 @@ * */ +#include + #include "compiler.h" #include "string_utils.h" #include "log.h" #include "config.h" +#include "common.h" +#include "utils.h" +#include "win.h" +#include "region.h" #include "opengl.h" diff --git a/src/options.c b/src/options.c index f510f3f..7832b7f 100644 --- a/src/options.c +++ b/src/options.c @@ -7,6 +7,9 @@ #include #include "common.h" +#include "log.h" +#include "utils.h" +#include "win.h" #include "config.h" #include "options.h" diff --git a/src/render.c b/src/render.c index fa988cc..50211ec 100644 --- a/src/render.c +++ b/src/render.c @@ -13,6 +13,13 @@ #include "vsync.h" #include "win.h" #include "kernel.h" +#include "compiler.h" +#include "x.h" +#include "config.h" +#include "region.h" +#include "log.h" +#include "types.h" +#include "utils.h" #include "backend/backend_common.h" #include "render.h" @@ -175,7 +182,7 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) { // XRender: Build picture if (bkend_use_xrender(ps) && !w->paint.pict) { xcb_render_create_picture_value_list_t pa = { - .subwindowmode = IncludeInferiors, + .subwindowmode = XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS, }; w->paint.pict = x_create_picture_with_pictfmt_and_pixmap( @@ -394,7 +401,7 @@ static bool get_root_tile(session_t *ps) { // Create Picture xcb_render_create_picture_value_list_t pa = { - .repeat = True, + .repeat = true, }; ps->root_tile_paint.pict = x_create_picture_with_visual_and_pixmap( ps, ps->vis, pixmap, XCB_RENDER_CP_REPEAT, &pa); @@ -933,7 +940,7 @@ void paint_all(session_t *ps, region_t *region, const region_t *region_real, win if (ps->o.vsync_aggressive) vsync_wait(ps); - XFlush(ps->dpy); + xcb_flush(ps->c); #ifdef CONFIG_OPENGL if (glx_has_context(ps)) { diff --git a/src/utils.h b/src/utils.h index 54302d9..1684449 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright (c) 2018 Yuxuan Shui #pragma once +#include #include #include #include #include #include -#include #include #include diff --git a/src/win.c b/src/win.c index ac03c94..62424b5 100644 --- a/src/win.c +++ b/src/win.c @@ -2,6 +2,7 @@ // Copyright (c) 2011-2013, Christopher Jeffrey // Copyright (c) 2013 Richard Grenville +#include #include #include #include @@ -17,6 +18,9 @@ #include "string_utils.h" #include "utils.h" #include "log.h" +#include "types.h" +#include "region.h" +#include "render.h" #ifdef CONFIG_DBUS #include "dbus.h" diff --git a/src/win.h b/src/win.h index aa16cac..9c3ecfe 100644 --- a/src/win.h +++ b/src/win.h @@ -16,6 +16,7 @@ #include "types.h" #include "c2.h" #include "render.h" +#include "utils.h" typedef struct session session_t; typedef struct _glx_texture glx_texture_t;