From 16ea51bbc1ef4604abdeb1c638d6379b930a1610 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Mon, 6 May 2019 02:03:07 +0100 Subject: [PATCH] common.h: more clean up Remove more unused stuff. Also removed session::xinerama_scrs, since all the information we need is covered by xinerama_scr_regs. Convert uses of xinerama_scrs to use xinerama_scr_regs. Signed-off-by: Yuxuan Shui --- src/common.h | 76 +++------------------------------------------------ src/compton.c | 15 ++++++---- src/event.c | 1 + src/opengl.h | 15 ++++++++++ src/win.c | 23 +++++++--------- 5 files changed, 39 insertions(+), 91 deletions(-) diff --git a/src/common.h b/src/common.h index 8269f104..ea066242 100644 --- a/src/common.h +++ b/src/common.h @@ -29,24 +29,12 @@ // For some special functions #include -#include -#include #include -#include -#include -#include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include #include "uthash_extra.h" #ifdef CONFIG_OPENGL @@ -77,12 +65,7 @@ #include "win.h" #include "x.h" -// === Constants === - -#define ROUNDED_PERCENT 0.05 -#define ROUNDED_PIXELS 10 - -#define SWOPTI_TOLERANCE 3000 +// === Constants ===0 #define NS_PER_SEC 1000000000L #define US_PER_SEC 1000000L @@ -98,6 +81,7 @@ // === Types === typedef struct glx_fbconfig glx_fbconfig_t; +struct glx_session; struct atom; /// Structure representing needed window updates. @@ -113,30 +97,6 @@ typedef struct _ignore { unsigned long sequence; } ignore_t; -enum wincond_target { - CONDTGT_NAME, - CONDTGT_CLASSI, - CONDTGT_CLASSG, - CONDTGT_ROLE, -}; - -enum wincond_type { - CONDTP_EXACT, - CONDTP_ANYWHERE, - CONDTP_FROMSTART, - CONDTP_WILDCARD, - CONDTP_REGEX_PCRE, -}; - -#define CONDF_IGNORECASE 0x0001 - -/// @brief Possible swap methods. -enum { SWAPM_BUFFER_AGE = -1, - SWAPM_UNDEFINED = 0, - SWAPM_COPY = 1, - SWAPM_EXCHANGE = 2, -}; - typedef struct _glx_texture glx_texture_t; #ifdef CONFIG_OPENGL @@ -205,24 +165,6 @@ typedef struct _latom { #define REG_DATA_INIT \ { NULL, 0 } -#ifdef CONFIG_OPENGL -/// Structure containing GLX-dependent data for a compton session. -typedef struct { - // === OpenGL related === - /// GLX context. - GLXContext context; - /// Whether we have GL_ARB_texture_non_power_of_two. - bool has_texture_non_power_of_two; - /// Current GLX Z value. - int z; - glx_blur_pass_t blur_passes[MAX_BLUR_PASS]; -} glx_session_t; - -#define CGLX_SESSION_INIT \ - { .context = NULL } - -#endif // CONFIG_OPENGL - /// Structure containing all necessary data for a compton session. typedef struct session { // === Event handlers === @@ -292,9 +234,9 @@ typedef struct session { xcb_window_t reg_win; #ifdef CONFIG_OPENGL /// Pointer to GLX data. - glx_session_t *psglx; + struct glx_session *psglx; /// Custom GLX program used for painting window. - // XXX should be in glx_session_t + // XXX should be in struct glx_session glx_prog_main_t glx_prog_win; #endif /// Sync fence to sync draw operations @@ -431,8 +373,6 @@ typedef struct session { #endif /// Whether X Xinerama extension exists. bool xinerama_exists; - /// Xinerama screen info. - xcb_xinerama_query_screens_reply_t *xinerama_scrs; /// Xinerama screen regions. region_t *xinerama_scr_regs; /// Number of Xinerama screens. @@ -461,14 +401,6 @@ typedef struct session { int (*vsync_wait)(session_t *); } session_t; -/// Temporary structure used for communication between -/// get_cfg() and parse_config(). -struct options_tmp { - bool no_dock_shadow; - bool no_dnd_shadow; - double menu_opacity; -}; - /// Enumeration for window event hints. typedef enum { WIN_EVMODE_UNKNOWN, WIN_EVMODE_FRAME, WIN_EVMODE_CLIENT } win_evmode_t; diff --git a/src/compton.c b/src/compton.c index 6e2ab7bd..73aca20e 100644 --- a/src/compton.c +++ b/src/compton.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -62,6 +63,8 @@ (session_t *)((char *)__mptr - offsetof(session_t, member)); \ }) +static const long SWOPTI_TOLERANCE = 3000; + static bool must_use redir_start(session_t *ps); static void redir_stop(session_t *ps); @@ -108,8 +111,6 @@ static inline void free_xinerama_info(session_t *ps) { pixman_region32_fini(&ps->xinerama_scr_regs[i]); free(ps->xinerama_scr_regs); } - free(ps->xinerama_scrs); - ps->xinerama_scrs = NULL; ps->xinerama_nscrs = 0; } @@ -138,14 +139,15 @@ void cxinerama_upd_scrs(session_t *ps) { } free(active); - ps->xinerama_scrs = + auto xinerama_scrs = xcb_xinerama_query_screens_reply(ps->c, xcb_xinerama_query_screens(ps->c), NULL); - if (!ps->xinerama_scrs) + if (!xinerama_scrs) { return; + } xcb_xinerama_screen_info_t *scrs = - xcb_xinerama_query_screens_screen_info(ps->xinerama_scrs); - ps->xinerama_nscrs = xcb_xinerama_query_screens_screen_info_length(ps->xinerama_scrs); + xcb_xinerama_query_screens_screen_info(xinerama_scrs); + ps->xinerama_nscrs = xcb_xinerama_query_screens_screen_info_length(xinerama_scrs); ps->xinerama_scr_regs = ccalloc(ps->xinerama_nscrs, region_t); for (int i = 0; i < ps->xinerama_nscrs; ++i) { @@ -153,6 +155,7 @@ void cxinerama_upd_scrs(session_t *ps) { pixman_region32_init_rect(&ps->xinerama_scr_regs[i], s->x_org, s->y_org, s->width, s->height); } + free(xinerama_scrs); } /** diff --git a/src/event.c b/src/event.c index 1789473e..d29be496 100644 --- a/src/event.c +++ b/src/event.c @@ -3,6 +3,7 @@ #include #include +#include #include "atom.h" #include "common.h" diff --git a/src/opengl.h b/src/opengl.h index 863a84d6..a776c004 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -26,6 +26,21 @@ #include #include +/// Structure containing GLX-dependent data for a compton session. +typedef struct glx_session { + // === OpenGL related === + /// GLX context. + GLXContext context; + /// Whether we have GL_ARB_texture_non_power_of_two. + bool has_texture_non_power_of_two; + /// Current GLX Z value. + int z; + glx_blur_pass_t blur_passes[MAX_BLUR_PASS]; +} glx_session_t; + +#define CGLX_SESSION_INIT \ + { .context = NULL } + bool glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, int z, GLfloat factor, const region_t *reg_tgt); diff --git a/src/win.c b/src/win.c index f2cd554f..9648917a 100644 --- a/src/win.c +++ b/src/win.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "atom.h" #include "backend/backend.h" @@ -42,8 +43,10 @@ #include "win.h" -#define OPAQUE 0xffffffff -#define WIN_GET_LEADER_MAX_RECURSION 20 +static const opacity_t OPAQUE = 0xffffffff; +static const int WIN_GET_LEADER_MAX_RECURSION = 20; +static const int ROUNDED_PIXELS = 1; +static const double ROUNDED_PERCENT = 0.05; /// Generate a "return by value" function, from a function that returns the /// region via a region_t pointer argument. @@ -1839,17 +1842,11 @@ void win_skip_fading(session_t *ps, struct managed_win **_w) { void win_update_screen(session_t *ps, struct managed_win *w) { w->xinerama_scr = -1; - if (!ps->xinerama_scrs) - return; - - xcb_xinerama_screen_info_t *scrs = - xcb_xinerama_query_screens_screen_info(ps->xinerama_scrs); - int length = xcb_xinerama_query_screens_screen_info_length(ps->xinerama_scrs); - for (int i = 0; i < length; i++) { - xcb_xinerama_screen_info_t *s = &scrs[i]; - if (s->x_org <= w->g.x && s->y_org <= w->g.y && - s->x_org + s->width >= w->g.x + w->widthb && - s->y_org + s->height >= w->g.y + w->heightb) { + for (int i = 0; i < ps->xinerama_nscrs; i++) { + auto e = pixman_region32_extents(&ps->xinerama_scr_regs[i]); + if (e->x1 <= w->g.x && e->y1 <= w->g.y && + e->x2 >= w->g.x + w->widthb && + e->y2 >= w->g.y + w->heightb) { w->xinerama_scr = i; return; }