Run clang-format
Now we have a consistent style across the codebase. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
7845673734
commit
22da17630f
241
src/common.h
241
src/common.h
|
@ -28,26 +28,26 @@
|
|||
// === Includes ===
|
||||
|
||||
// For some special functions
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <ev.h>
|
||||
#include <pixman.h>
|
||||
#include <xcb/composite.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/damage.h>
|
||||
#include <xcb/randr.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/shape.h>
|
||||
#include <xcb/sync.h>
|
||||
#include <xcb/xinerama.h>
|
||||
#include <ev.h>
|
||||
#include <pixman.h>
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
// libGL
|
||||
|
@ -76,17 +76,17 @@
|
|||
#endif
|
||||
|
||||
// FIXME This list of includes should get shorter
|
||||
#include "types.h"
|
||||
#include "win.h"
|
||||
#include "region.h"
|
||||
#include "kernel.h"
|
||||
#include "render.h"
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "compiler.h"
|
||||
#include "utils.h"
|
||||
#include "x.h"
|
||||
#include "backend/backend.h"
|
||||
#include "compiler.h"
|
||||
#include "config.h"
|
||||
#include "kernel.h"
|
||||
#include "log.h"
|
||||
#include "region.h"
|
||||
#include "render.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
#include "win.h"
|
||||
#include "x.h"
|
||||
|
||||
// === Constants ===
|
||||
|
||||
|
@ -159,8 +159,7 @@ enum wincond_type {
|
|||
#define CONDF_IGNORECASE 0x0001
|
||||
|
||||
/// @brief Possible swap methods.
|
||||
enum {
|
||||
SWAPM_BUFFER_AGE = -1,
|
||||
enum { SWAPM_BUFFER_AGE = -1,
|
||||
SWAPM_UNDEFINED = 0,
|
||||
SWAPM_COPY = 1,
|
||||
SWAPM_EXCHANGE = 2,
|
||||
|
@ -170,25 +169,22 @@ typedef struct _glx_texture glx_texture_t;
|
|||
|
||||
#ifdef CONFIG_OPENGL
|
||||
#ifdef DEBUG_GLX_DEBUG_CONTEXT
|
||||
typedef GLXContext (*f_glXCreateContextAttribsARB) (Display *dpy,
|
||||
GLXFBConfig config, GLXContext share_context, Bool direct,
|
||||
typedef GLXContext (*f_glXCreateContextAttribsARB)(Display *dpy, GLXFBConfig config,
|
||||
GLXContext share_context, Bool direct,
|
||||
const int *attrib_list);
|
||||
typedef void (*GLDEBUGPROC) (GLenum source, GLenum type,
|
||||
GLuint id, GLenum severity, GLsizei length, const GLchar* message,
|
||||
GLvoid* userParam);
|
||||
typedef void (*f_DebugMessageCallback) (GLDEBUGPROC, void *userParam);
|
||||
typedef void (*GLDEBUGPROC)(GLenum source, GLenum type, GLuint id, GLenum severity,
|
||||
GLsizei length, const GLchar *message, GLvoid *userParam);
|
||||
typedef void (*f_DebugMessageCallback)(GLDEBUGPROC, void *userParam);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
typedef GLsync (*f_FenceSync) (GLenum condition, GLbitfield flags);
|
||||
typedef GLboolean (*f_IsSync) (GLsync sync);
|
||||
typedef void (*f_DeleteSync) (GLsync sync);
|
||||
typedef GLenum (*f_ClientWaitSync) (GLsync sync, GLbitfield flags,
|
||||
GLuint64 timeout);
|
||||
typedef void (*f_WaitSync) (GLsync sync, GLbitfield flags,
|
||||
GLuint64 timeout);
|
||||
typedef GLsync (*f_ImportSyncEXT) (GLenum external_sync_type,
|
||||
GLintptr external_sync, GLbitfield flags);
|
||||
typedef GLsync (*f_FenceSync)(GLenum condition, GLbitfield flags);
|
||||
typedef GLboolean (*f_IsSync)(GLsync sync);
|
||||
typedef void (*f_DeleteSync)(GLsync sync);
|
||||
typedef GLenum (*f_ClientWaitSync)(GLsync sync, GLbitfield flags, GLuint64 timeout);
|
||||
typedef void (*f_WaitSync)(GLsync sync, GLbitfield flags, GLuint64 timeout);
|
||||
typedef GLsync (*f_ImportSyncEXT)(GLenum external_sync_type, GLintptr external_sync,
|
||||
GLbitfield flags);
|
||||
#endif
|
||||
|
||||
/// @brief Wrapper of a binded GLX texture.
|
||||
|
@ -227,19 +223,16 @@ typedef struct glx_prog_main {
|
|||
GLint unifm_tex;
|
||||
} glx_prog_main_t;
|
||||
|
||||
#define GLX_PROG_MAIN_INIT { \
|
||||
.prog = 0, \
|
||||
.unifm_opacity = -1, \
|
||||
.unifm_invert_color = -1, \
|
||||
.unifm_tex = -1, \
|
||||
}
|
||||
#define GLX_PROG_MAIN_INIT \
|
||||
{ .prog = 0, .unifm_opacity = -1, .unifm_invert_color = -1, .unifm_tex = -1, }
|
||||
|
||||
#endif
|
||||
#else
|
||||
struct glx_prog_main { };
|
||||
struct glx_prog_main {};
|
||||
#endif
|
||||
|
||||
#define PAINT_INIT { .pixmap = XCB_NONE, .pict = XCB_NONE }
|
||||
#define PAINT_INIT \
|
||||
{ .pixmap = XCB_NONE, .pict = XCB_NONE }
|
||||
|
||||
/// Linked list type of atoms.
|
||||
typedef struct _latom {
|
||||
|
@ -247,7 +240,8 @@ typedef struct _latom {
|
|||
struct _latom *next;
|
||||
} latom_t;
|
||||
|
||||
#define REG_DATA_INIT { NULL, 0 }
|
||||
#define REG_DATA_INIT \
|
||||
{ NULL, 0 }
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
/// Structure containing GLX-dependent data for a compton session.
|
||||
|
@ -276,7 +270,8 @@ typedef struct {
|
|||
#endif
|
||||
} glx_session_t;
|
||||
|
||||
#define CGLX_SESSION_INIT { .context = NULL }
|
||||
#define CGLX_SESSION_INIT \
|
||||
{ .context = NULL }
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -542,29 +537,22 @@ struct options_tmp {
|
|||
};
|
||||
|
||||
/// Enumeration for window event hints.
|
||||
typedef enum {
|
||||
WIN_EVMODE_UNKNOWN,
|
||||
WIN_EVMODE_FRAME,
|
||||
WIN_EVMODE_CLIENT
|
||||
} win_evmode_t;
|
||||
typedef enum { WIN_EVMODE_UNKNOWN, WIN_EVMODE_FRAME, WIN_EVMODE_CLIENT } win_evmode_t;
|
||||
|
||||
extern const char * const WINTYPES[NUM_WINTYPES];
|
||||
extern const char *const WINTYPES[NUM_WINTYPES];
|
||||
extern session_t *ps_g;
|
||||
|
||||
// == Debugging code ==
|
||||
static inline void
|
||||
print_timestamp(session_t *ps);
|
||||
static inline void print_timestamp(session_t *ps);
|
||||
|
||||
void
|
||||
ev_xcb_error(session_t *ps, xcb_generic_error_t *err);
|
||||
void ev_xcb_error(session_t *ps, xcb_generic_error_t *err);
|
||||
|
||||
// === Functions ===
|
||||
|
||||
/**
|
||||
* Return whether a struct timeval value is empty.
|
||||
*/
|
||||
static inline bool
|
||||
timeval_isempty(struct timeval *ptv) {
|
||||
static inline bool timeval_isempty(struct timeval *ptv) {
|
||||
if (!ptv)
|
||||
return false;
|
||||
|
||||
|
@ -576,8 +564,7 @@ timeval_isempty(struct timeval *ptv) {
|
|||
*
|
||||
* @return > 0 if ptv > ms, 0 if ptv == 0, -1 if ptv < ms
|
||||
*/
|
||||
static inline int
|
||||
timeval_ms_cmp(struct timeval *ptv, unsigned long ms) {
|
||||
static inline int timeval_ms_cmp(struct timeval *ptv, unsigned long ms) {
|
||||
assert(ptv);
|
||||
|
||||
// We use those if statement instead of a - expression because of possible
|
||||
|
@ -611,9 +598,7 @@ timeval_ms_cmp(struct timeval *ptv, unsigned long ms) {
|
|||
* Return 1 if the difference is negative, otherwise 0.
|
||||
*/
|
||||
static inline int
|
||||
timeval_subtract(struct timeval *result,
|
||||
struct timeval *x,
|
||||
struct timeval *y) {
|
||||
timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) {
|
||||
/* Perform the carry for the later subtraction by updating y. */
|
||||
if (x->tv_usec < y->tv_usec) {
|
||||
long nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
|
||||
|
@ -646,9 +631,7 @@ timeval_subtract(struct timeval *result,
|
|||
* Return 1 if the difference is negative, otherwise 0.
|
||||
*/
|
||||
static inline int
|
||||
timespec_subtract(struct timespec *result,
|
||||
struct timespec *x,
|
||||
struct timespec *y) {
|
||||
timespec_subtract(struct timespec *result, struct timespec *x, struct timespec *y) {
|
||||
/* Perform the carry for the later subtraction by updating y. */
|
||||
if (x->tv_nsec < y->tv_nsec) {
|
||||
long nsec = (y->tv_nsec - x->tv_nsec) / NS_PER_SEC + 1;
|
||||
|
@ -674,9 +657,8 @@ timespec_subtract(struct timespec *result,
|
|||
/**
|
||||
* Get current time in struct timeval.
|
||||
*/
|
||||
static inline struct timeval
|
||||
get_time_timeval(void) {
|
||||
struct timeval tv = { 0, 0 };
|
||||
static inline struct timeval get_time_timeval(void) {
|
||||
struct timeval tv = {0, 0};
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
|
@ -689,9 +671,8 @@ get_time_timeval(void) {
|
|||
*
|
||||
* Note its starting time is unspecified.
|
||||
*/
|
||||
static inline struct timespec
|
||||
get_time_timespec(void) {
|
||||
struct timespec tm = { 0, 0 };
|
||||
static inline struct timespec get_time_timespec(void) {
|
||||
struct timespec tm = {0, 0};
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &tm);
|
||||
|
||||
|
@ -699,17 +680,16 @@ get_time_timespec(void) {
|
|||
return tm;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print time passed since program starts execution.
|
||||
*
|
||||
* Used for debugging.
|
||||
*/
|
||||
static inline void
|
||||
print_timestamp(session_t *ps) {
|
||||
static inline void print_timestamp(session_t *ps) {
|
||||
struct timeval tm, diff;
|
||||
|
||||
if (gettimeofday(&tm, NULL)) return;
|
||||
if (gettimeofday(&tm, NULL))
|
||||
return;
|
||||
|
||||
timeval_subtract(&diff, &tm, &ps->time_start);
|
||||
fprintf(stderr, "[ %5ld.%06ld ] ", diff.tv_sec, diff.tv_usec);
|
||||
|
@ -720,14 +700,12 @@ print_timestamp(session_t *ps) {
|
|||
*
|
||||
* Because a NULL pointer cannot be passed to XFree(), its man page says.
|
||||
*/
|
||||
static inline void
|
||||
cxfree(void *data) {
|
||||
static inline void cxfree(void *data) {
|
||||
if (data)
|
||||
XFree(data);
|
||||
}
|
||||
|
||||
_Noreturn static inline void
|
||||
die(const char *msg) {
|
||||
_Noreturn static inline void die(const char *msg) {
|
||||
puts(msg);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -735,12 +713,9 @@ die(const char *msg) {
|
|||
/**
|
||||
* Wrapper of XInternAtom() for convenience.
|
||||
*/
|
||||
static inline xcb_atom_t
|
||||
get_atom(session_t *ps, const char *atom_name) {
|
||||
xcb_intern_atom_reply_t *reply =
|
||||
xcb_intern_atom_reply(ps->c,
|
||||
xcb_intern_atom(ps->c, 0, strlen(atom_name), atom_name),
|
||||
NULL);
|
||||
static inline xcb_atom_t get_atom(session_t *ps, const char *atom_name) {
|
||||
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(
|
||||
ps->c, xcb_intern_atom(ps->c, 0, strlen(atom_name), atom_name), NULL);
|
||||
|
||||
xcb_atom_t atom = XCB_NONE;
|
||||
if (reply) {
|
||||
|
@ -755,16 +730,14 @@ get_atom(session_t *ps, const char *atom_name) {
|
|||
/**
|
||||
* Return the painting target window.
|
||||
*/
|
||||
static inline xcb_window_t
|
||||
get_tgt_window(session_t *ps) {
|
||||
return ps->overlay != XCB_NONE ? ps->overlay: ps->root;
|
||||
static inline xcb_window_t get_tgt_window(session_t *ps) {
|
||||
return ps->overlay != XCB_NONE ? ps->overlay : ps->root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a window from window id in window linked list of the session.
|
||||
*/
|
||||
static inline win *
|
||||
find_win(session_t *ps, xcb_window_t id) {
|
||||
static inline win *find_win(session_t *ps, xcb_window_t id) {
|
||||
if (!id)
|
||||
return NULL;
|
||||
|
||||
|
@ -785,8 +758,7 @@ find_win(session_t *ps, xcb_window_t id) {
|
|||
* @param id window ID
|
||||
* @return struct win object of the found window, NULL if not found
|
||||
*/
|
||||
static inline win *
|
||||
find_toplevel(session_t *ps, xcb_window_t id) {
|
||||
static inline win *find_toplevel(session_t *ps, xcb_window_t id) {
|
||||
if (!id)
|
||||
return NULL;
|
||||
|
||||
|
@ -802,17 +774,14 @@ find_toplevel(session_t *ps, xcb_window_t id) {
|
|||
/**
|
||||
* Check if current backend uses GLX.
|
||||
*/
|
||||
static inline bool
|
||||
bkend_use_glx(session_t *ps) {
|
||||
return BKEND_GLX == ps->o.backend
|
||||
|| BKEND_XR_GLX_HYBRID == ps->o.backend;
|
||||
static inline bool bkend_use_glx(session_t *ps) {
|
||||
return BKEND_GLX == ps->o.backend || BKEND_XR_GLX_HYBRID == ps->o.backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a window is really focused.
|
||||
*/
|
||||
static inline bool
|
||||
win_is_focused_real(session_t *ps, const win *w) {
|
||||
static inline bool win_is_focused_real(session_t *ps, const win *w) {
|
||||
return w->a.map_state == XCB_MAP_STATE_VIEWABLE && ps->active_win == w;
|
||||
}
|
||||
|
||||
|
@ -821,9 +790,9 @@ win_is_focused_real(session_t *ps, const win *w) {
|
|||
*
|
||||
* @return struct win object of the found window, NULL if not found
|
||||
*/
|
||||
static inline win *
|
||||
find_focused(session_t *ps) {
|
||||
if (!ps->o.track_focus) return NULL;
|
||||
static inline win *find_focused(session_t *ps) {
|
||||
if (!ps->o.track_focus)
|
||||
return NULL;
|
||||
|
||||
if (ps->active_win && win_is_focused_real(ps, ps->active_win))
|
||||
return ps->active_win;
|
||||
|
@ -833,20 +802,17 @@ find_focused(session_t *ps) {
|
|||
/**
|
||||
* Check if a rectangle includes the whole screen.
|
||||
*/
|
||||
static inline bool
|
||||
rect_is_fullscreen(session_t *ps, int x, int y, int wid, int hei) {
|
||||
return (x <= 0 && y <= 0 &&
|
||||
(x + wid) >= ps->root_width &&
|
||||
(y + hei) >= ps->root_height);
|
||||
static inline bool rect_is_fullscreen(session_t *ps, int x, int y, int wid, int hei) {
|
||||
return (x <= 0 && y <= 0 && (x + wid) >= ps->root_width && (y + hei) >= ps->root_height);
|
||||
}
|
||||
|
||||
static void
|
||||
set_ignore(session_t *ps, unsigned long sequence) {
|
||||
static void set_ignore(session_t *ps, unsigned long sequence) {
|
||||
if (ps->o.show_all_xerrors)
|
||||
return;
|
||||
|
||||
auto i = cmalloc(ignore_t);
|
||||
if (!i) return;
|
||||
if (!i)
|
||||
return;
|
||||
|
||||
i->sequence = sequence;
|
||||
i->next = 0;
|
||||
|
@ -857,8 +823,7 @@ set_ignore(session_t *ps, unsigned long sequence) {
|
|||
/**
|
||||
* Ignore X errors caused by given X request.
|
||||
*/
|
||||
static inline void
|
||||
set_ignore_cookie(session_t *ps, xcb_void_cookie_t cookie) {
|
||||
static inline void set_ignore_cookie(session_t *ps, xcb_void_cookie_t cookie) {
|
||||
set_ignore(ps, cookie.sequence);
|
||||
}
|
||||
|
||||
|
@ -867,17 +832,15 @@ set_ignore_cookie(session_t *ps, xcb_void_cookie_t cookie) {
|
|||
*
|
||||
* It's not using w->border_size for performance measures.
|
||||
*/
|
||||
static inline bool
|
||||
win_is_fullscreen(session_t *ps, const win *w) {
|
||||
return rect_is_fullscreen(ps, w->g.x, w->g.y, w->widthb, w->heightb)
|
||||
&& (!w->bounding_shaped || w->rounded_corners);
|
||||
static inline bool win_is_fullscreen(session_t *ps, const win *w) {
|
||||
return rect_is_fullscreen(ps, w->g.x, w->g.y, w->widthb, w->heightb) &&
|
||||
(!w->bounding_shaped || w->rounded_corners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a window will be painted solid.
|
||||
*/
|
||||
static inline bool
|
||||
win_is_solid(session_t *ps, const win *w) {
|
||||
static inline bool win_is_solid(session_t *ps, const win *w) {
|
||||
return WMODE_SOLID == w->mode && !ps->o.force_win_blend;
|
||||
}
|
||||
|
||||
|
@ -889,13 +852,9 @@ win_is_solid(session_t *ps, const win *w) {
|
|||
* @param atom atom of property to check
|
||||
* @return true if it has the attribute, false otherwise
|
||||
*/
|
||||
static inline bool
|
||||
wid_has_prop(const session_t *ps, xcb_window_t w, xcb_atom_t atom) {
|
||||
auto r =
|
||||
xcb_get_property_reply(ps->c,
|
||||
xcb_get_property(ps->c, 0, w, atom,
|
||||
XCB_GET_PROPERTY_TYPE_ANY, 0, 0),
|
||||
NULL);
|
||||
static inline bool wid_has_prop(const session_t *ps, xcb_window_t w, xcb_atom_t atom) {
|
||||
auto r = xcb_get_property_reply(
|
||||
ps->c, xcb_get_property(ps->c, 0, w, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, 0), NULL);
|
||||
if (!r) {
|
||||
return false;
|
||||
}
|
||||
|
@ -912,8 +871,7 @@ wid_has_prop(const session_t *ps, xcb_window_t w, xcb_atom_t atom) {
|
|||
/**
|
||||
* Get the numeric property value from a win_prop_t.
|
||||
*/
|
||||
static inline long
|
||||
winprop_get_int(winprop_t prop) {
|
||||
static inline long winprop_get_int(winprop_t prop) {
|
||||
long tgt = 0;
|
||||
|
||||
if (!prop.nitems)
|
||||
|
@ -923,21 +881,17 @@ winprop_get_int(winprop_t prop) {
|
|||
case 8: tgt = *(prop.p8); break;
|
||||
case 16: tgt = *(prop.p16); break;
|
||||
case 32: tgt = *(prop.p32); break;
|
||||
default: assert(0);
|
||||
break;
|
||||
default: assert(0); break;
|
||||
}
|
||||
|
||||
return tgt;
|
||||
}
|
||||
|
||||
void
|
||||
force_repaint(session_t *ps);
|
||||
void force_repaint(session_t *ps);
|
||||
|
||||
bool
|
||||
vsync_init(session_t *ps);
|
||||
bool vsync_init(session_t *ps);
|
||||
|
||||
void
|
||||
vsync_deinit(session_t *ps);
|
||||
void vsync_deinit(session_t *ps);
|
||||
|
||||
/** @name DBus handling
|
||||
*/
|
||||
|
@ -946,31 +900,24 @@ vsync_deinit(session_t *ps);
|
|||
/** @name DBus hooks
|
||||
*/
|
||||
///@{
|
||||
void
|
||||
win_set_shadow_force(session_t *ps, win *w, switch_t val);
|
||||
void win_set_shadow_force(session_t *ps, win *w, switch_t val);
|
||||
|
||||
void
|
||||
win_set_fade_force(session_t *ps, win *w, switch_t val);
|
||||
void win_set_fade_force(session_t *ps, win *w, switch_t val);
|
||||
|
||||
void
|
||||
win_set_focused_force(session_t *ps, win *w, switch_t val);
|
||||
void win_set_focused_force(session_t *ps, win *w, switch_t val);
|
||||
|
||||
void
|
||||
win_set_invert_color_force(session_t *ps, win *w, switch_t val);
|
||||
void win_set_invert_color_force(session_t *ps, win *w, switch_t val);
|
||||
|
||||
void
|
||||
opts_init_track_focus(session_t *ps);
|
||||
void opts_init_track_focus(session_t *ps);
|
||||
|
||||
void
|
||||
opts_set_no_fading_openclose(session_t *ps, bool newval);
|
||||
void opts_set_no_fading_openclose(session_t *ps, bool newval);
|
||||
//!@}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Set a <code>bool</code> array of all wintypes to true.
|
||||
*/
|
||||
static inline void
|
||||
wintype_arr_enable(bool arr[]) {
|
||||
static inline void wintype_arr_enable(bool arr[]) {
|
||||
wintype_t i;
|
||||
|
||||
for (i = 0; i < NUM_WINTYPES; ++i) {
|
||||
|
|
856
src/compton.c
856
src/compton.c
File diff suppressed because it is too large
Load Diff
|
@ -6,24 +6,24 @@
|
|||
|
||||
// === Includes ===
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <locale.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <xcb/xproto.h>
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
#include "common.h"
|
||||
#include "backend/backend.h"
|
||||
#include "win.h"
|
||||
#include "x.h"
|
||||
#include "c2.h"
|
||||
#include "common.h"
|
||||
#include "compiler.h"
|
||||
#include "config.h"
|
||||
#include "log.h" // XXX clean up
|
||||
#include "region.h"
|
||||
#include "compiler.h"
|
||||
#include "render.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
#include "render.h"
|
||||
#include "config.h"
|
||||
#include "win.h"
|
||||
#include "x.h"
|
||||
|
||||
// == Functions ==
|
||||
// TODO move static inline functions that are only used in compton.c, into
|
||||
|
@ -36,16 +36,14 @@ void add_damage(session_t *ps, const region_t *damage);
|
|||
|
||||
long determine_evmask(session_t *ps, xcb_window_t wid, win_evmode_t mode);
|
||||
|
||||
xcb_window_t
|
||||
find_client_win(session_t *ps, xcb_window_t w);
|
||||
xcb_window_t find_client_win(session_t *ps, xcb_window_t w);
|
||||
|
||||
win *find_toplevel2(session_t *ps, xcb_window_t wid);
|
||||
|
||||
/**
|
||||
* Set a <code>switch_t</code> array of all unset wintypes to true.
|
||||
*/
|
||||
static inline void
|
||||
wintype_arr_enable_unset(switch_t arr[]) {
|
||||
static inline void wintype_arr_enable_unset(switch_t arr[]) {
|
||||
wintype_t i;
|
||||
|
||||
for (i = 0; i < NUM_WINTYPES; ++i)
|
||||
|
@ -60,8 +58,7 @@ wintype_arr_enable_unset(switch_t arr[]) {
|
|||
* @param count amount of elements in the array
|
||||
* @param wid window ID to search for
|
||||
*/
|
||||
static inline bool
|
||||
array_wid_exists(const xcb_window_t *arr, int count, xcb_window_t wid) {
|
||||
static inline bool array_wid_exists(const xcb_window_t *arr, int count, xcb_window_t wid) {
|
||||
while (count--) {
|
||||
if (arr[count] == wid) {
|
||||
return true;
|
||||
|
@ -74,24 +71,22 @@ array_wid_exists(const xcb_window_t *arr, int count, xcb_window_t wid) {
|
|||
/**
|
||||
* Destroy a condition list.
|
||||
*/
|
||||
static inline void
|
||||
free_wincondlst(c2_lptr_t **pcondlst) {
|
||||
static inline void free_wincondlst(c2_lptr_t **pcondlst) {
|
||||
while ((*pcondlst = c2_free_lptr(*pcondlst)))
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_OPENGL
|
||||
static inline void
|
||||
free_paint_glx(session_t *ps, paint_t *p) {}
|
||||
static inline void
|
||||
free_win_res_glx(session_t *ps, win *w) {}
|
||||
static inline void free_paint_glx(session_t *ps, paint_t *p) {
|
||||
}
|
||||
static inline void free_win_res_glx(session_t *ps, win *w) {
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Create a XTextProperty of a single string.
|
||||
*/
|
||||
static inline XTextProperty *
|
||||
make_text_prop(session_t *ps, char *str) {
|
||||
static inline XTextProperty *make_text_prop(session_t *ps, char *str) {
|
||||
XTextProperty *pprop = ccalloc(1, XTextProperty);
|
||||
|
||||
if (XmbTextListToTextProperty(ps->dpy, &str, 1, XStringStyle, pprop)) {
|
||||
|
@ -103,7 +98,6 @@ make_text_prop(session_t *ps, char *str) {
|
|||
return pprop;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a single-string text property on a window.
|
||||
*/
|
||||
|
@ -125,8 +119,7 @@ wid_set_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop_atom, char *s
|
|||
/**
|
||||
* Dump an drawable's info.
|
||||
*/
|
||||
static inline void
|
||||
dump_drawable(session_t *ps, xcb_drawable_t drawable) {
|
||||
static inline void dump_drawable(session_t *ps, xcb_drawable_t drawable) {
|
||||
auto r = xcb_get_geometry_reply(ps->c, xcb_get_geometry(ps->c, drawable), NULL);
|
||||
if (!r) {
|
||||
log_trace("Drawable %#010x: Failed", drawable);
|
||||
|
|
123
src/config.c
123
src/config.c
|
@ -2,22 +2,22 @@
|
|||
// Copyright (c) 2011-2013, Christopher Jeffrey
|
||||
// Copyright (c) 2013 Richard Grenville <pyxlcy@gmail.com>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <xcb/render.h> // for xcb_render_fixed_t, XXX
|
||||
|
||||
#include "compiler.h"
|
||||
#include "common.h"
|
||||
#include "utils.h"
|
||||
#include "c2.h"
|
||||
#include "string_utils.h"
|
||||
#include "common.h"
|
||||
#include "compiler.h"
|
||||
#include "kernel.h"
|
||||
#include "log.h"
|
||||
#include "region.h"
|
||||
#include "string_utils.h"
|
||||
#include "types.h"
|
||||
#include "kernel.h"
|
||||
#include "utils.h"
|
||||
#include "win.h"
|
||||
|
||||
#include "config.h"
|
||||
|
@ -25,10 +25,9 @@
|
|||
/**
|
||||
* Parse a long number.
|
||||
*/
|
||||
bool
|
||||
parse_long(const char *s, long *dest) {
|
||||
bool parse_long(const char *s, long *dest) {
|
||||
const char *endptr = NULL;
|
||||
long val = strtol(s, (char **) &endptr, 0);
|
||||
long val = strtol(s, (char **)&endptr, 0);
|
||||
if (!endptr || endptr == s) {
|
||||
log_error("Invalid number: %s", s);
|
||||
return false;
|
||||
|
@ -51,8 +50,7 @@ parse_long(const char *s, long *dest) {
|
|||
* @param[out] dest return the number parsed from the string
|
||||
* @return pointer to the last character parsed
|
||||
*/
|
||||
const char *
|
||||
parse_readnum(const char *src, double *dest) {
|
||||
const char *parse_readnum(const char *src, double *dest) {
|
||||
const char *pc = NULL;
|
||||
double val = strtod_simple(src, &pc);
|
||||
if (!pc || pc == src) {
|
||||
|
@ -73,8 +71,7 @@ parse_readnum(const char *src, double *dest) {
|
|||
* @param[out] endptr return where the end of kernel is in the string
|
||||
* @param[out] hasneg whether the kernel has negative values
|
||||
*/
|
||||
conv *
|
||||
parse_blur_kern(const char *src, const char **endptr, bool *hasneg) {
|
||||
conv *parse_blur_kern(const char *src, const char **endptr, bool *hasneg) {
|
||||
int width = 0, height = 0;
|
||||
*hasneg = false;
|
||||
|
||||
|
@ -126,7 +123,7 @@ parse_blur_kern(const char *src, const char **endptr, bool *hasneg) {
|
|||
}
|
||||
|
||||
// Detect trailing characters
|
||||
for (;*pc && *pc != ';'; pc++) {
|
||||
for (; *pc && *pc != ';'; pc++) {
|
||||
if (!isspace(*pc) && *pc != ',') {
|
||||
// TODO isspace is locale aware, be careful
|
||||
log_error("Trailing characters in blur kernel string.");
|
||||
|
@ -172,28 +169,67 @@ err1:
|
|||
* @param[out] hasneg whether any of the kernels have negative values
|
||||
* @return if the `src` string is a valid kernel list string
|
||||
*/
|
||||
bool
|
||||
parse_blur_kern_lst(const char *src, conv **dest, int max, bool *hasneg) {
|
||||
bool parse_blur_kern_lst(const char *src, conv **dest, int max, bool *hasneg) {
|
||||
// TODO just return a predefined kernels, not parse predefined strings...
|
||||
static const struct {
|
||||
const char *name;
|
||||
const char *kern_str;
|
||||
} CONV_KERN_PREDEF[] = {
|
||||
{ "3x3box", "3,3,1,1,1,1,1,1,1,1," },
|
||||
{ "5x5box", "5,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1," },
|
||||
{ "7x7box", "7,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1," },
|
||||
{ "3x3gaussian", "3,3,0.243117,0.493069,0.243117,0.493069,0.493069,0.243117,0.493069,0.243117," },
|
||||
{ "5x5gaussian", "5,5,0.003493,0.029143,0.059106,0.029143,0.003493,0.029143,0.243117,0.493069,0.243117,0.029143,0.059106,0.493069,0.493069,0.059106,0.029143,0.243117,0.493069,0.243117,0.029143,0.003493,0.029143,0.059106,0.029143,0.003493," },
|
||||
{ "7x7gaussian", "7,7,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0.000102,0.003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.001723,0.059106,0.493069,0.493069,0.059106,0.001723,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.000102,0.003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003," },
|
||||
{ "9x9gaussian", "9,9,0.000000,0.000000,0.000001,0.000006,0.000012,0.000006,0.000001,0.000000,0.000000,0.000000,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0.000000,0.000001,0.000102,0.003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000001,0.000006,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.000006,0.000012,0.001723,0.059106,0.493069,0.493069,0.059106,0.001723,0.000012,0.000006,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.000006,0.000001,0.000102,0.003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000001,0.000000,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0.000000,0.000000,0.000000,0.000001,0.000006,0.000012,0.000006,0.000001,0.000000,0.000000," },
|
||||
{ "11x11gaussian", "11,11,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000001,0.000006,0.000012,0.000006,0.000001,0.000000,0.000000,0.000000,0.000000,0.000000,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0.000000,0.000000,0.000000,0.000001,0.000102,0.003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000001,0.000000,0.000000,0.000006,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.000006,0.000000,0.000000,0.000012,0.001723,0.059106,0.493069,0.493069,0.059106,0.001723,0.000012,0.000000,0.000000,0.000006,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.000006,0.000000,0.000000,0.000001,0.000102,0.003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000001,0.000000,0.000000,0.000000,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0.000000,0.000000,0.000000,0.000000,0.000000,0.000001,0.000006,0.000012,0.000006,0.000001,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000," },
|
||||
{"3x3box", "3,3,1,1,1,1,1,1,1,1,"},
|
||||
{"5x5box", "5,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"},
|
||||
{"7x7box", "7,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"
|
||||
"1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,"},
|
||||
{"3x3gaussian", "3,3,0.243117,0.493069,0.243117,0.493069,0.493069,0.243117,0."
|
||||
"493069,0.243117,"},
|
||||
{"5x5gaussian", "5,5,0.003493,0.029143,0.059106,0.029143,0.003493,0.029143,0."
|
||||
"243117,0.493069,0.243117,0.029143,0.059106,0.493069,0."
|
||||
"493069,0.059106,0.029143,0.243117,0.493069,0.243117,0."
|
||||
"029143,0.003493,0.029143,0.059106,0.029143,0.003493,"},
|
||||
{"7x7gaussian", "7,7,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0."
|
||||
"000003,0.000102,0.003493,0.029143,0.059106,0.029143,0."
|
||||
"003493,0.000102,0.000849,0.029143,0.243117,0.493069,0."
|
||||
"243117,0.029143,0.000849,0.001723,0.059106,0.493069,0."
|
||||
"493069,0.059106,0.001723,0.000849,0.029143,0.243117,0."
|
||||
"493069,0.243117,0.029143,0.000849,0.000102,0.003493,0."
|
||||
"029143,0.059106,0.029143,0.003493,0.000102,0.000003,0."
|
||||
"000102,0.000849,0.001723,0.000849,0.000102,0.000003,"},
|
||||
{"9x9gaussian",
|
||||
"9,9,0.000000,0.000000,0.000001,0.000006,0.000012,0.000006,0.000001,0."
|
||||
"000000,0.000000,0.000000,0.000003,0.000102,0.000849,0.001723,0.000849,0."
|
||||
"000102,0.000003,0.000000,0.000001,0.000102,0.003493,0.029143,0.059106,0."
|
||||
"029143,0.003493,0.000102,0.000001,0.000006,0.000849,0.029143,0.243117,0."
|
||||
"493069,0.243117,0.029143,0.000849,0.000006,0.000012,0.001723,0.059106,0."
|
||||
"493069,0.493069,0.059106,0.001723,0.000012,0.000006,0.000849,0.029143,0."
|
||||
"243117,0.493069,0.243117,0.029143,0.000849,0.000006,0.000001,0.000102,0."
|
||||
"003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000001,0.000000,0."
|
||||
"000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0.000000,0."
|
||||
"000000,0.000000,0.000001,0.000006,0.000012,0.000006,0.000001,0.000000,0."
|
||||
"000000,"},
|
||||
{"11x11gaussian",
|
||||
"11,11,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0."
|
||||
"000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000001,0."
|
||||
"000006,0.000012,0.000006,0.000001,0.000000,0.000000,0.000000,0.000000,0."
|
||||
"000000,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0."
|
||||
"000000,0.000000,0.000000,0.000001,0.000102,0.003493,0.029143,0.059106,0."
|
||||
"029143,0.003493,0.000102,0.000001,0.000000,0.000000,0.000006,0.000849,0."
|
||||
"029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.000006,0.000000,0."
|
||||
"000000,0.000012,0.001723,0.059106,0.493069,0.493069,0.059106,0.001723,0."
|
||||
"000012,0.000000,0.000000,0.000006,0.000849,0.029143,0.243117,0.493069,0."
|
||||
"243117,0.029143,0.000849,0.000006,0.000000,0.000000,0.000001,0.000102,0."
|
||||
"003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000001,0.000000,0."
|
||||
"000000,0.000000,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0."
|
||||
"000003,0.000000,0.000000,0.000000,0.000000,0.000000,0.000001,0.000006,0."
|
||||
"000012,0.000006,0.000001,0.000000,0.000000,0.000000,0.000000,0.000000,0."
|
||||
"000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0."
|
||||
"000000,"},
|
||||
};
|
||||
|
||||
*hasneg = false;
|
||||
for (unsigned int i = 0;
|
||||
i < sizeof(CONV_KERN_PREDEF) / sizeof(CONV_KERN_PREDEF[0]); ++i) {
|
||||
if (!strcmp(CONV_KERN_PREDEF[i].name, src))
|
||||
return parse_blur_kern_lst(CONV_KERN_PREDEF[i].kern_str, dest, max, hasneg);
|
||||
return parse_blur_kern_lst(CONV_KERN_PREDEF[i].kern_str, dest,
|
||||
max, hasneg);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
@ -218,8 +254,10 @@ parse_blur_kern_lst(const char *src, conv **dest, int max, bool *hasneg) {
|
|||
}
|
||||
|
||||
if (i > 1) {
|
||||
log_warn("You are seeing this message because your are using multipassblur. Please "
|
||||
"report an issue to us so we know multipass blur is actually been used. "
|
||||
log_warn("You are seeing this message because your are using "
|
||||
"multipassblur. Please "
|
||||
"report an issue to us so we know multipass blur is actually "
|
||||
"been used. "
|
||||
"Otherwise it might be removed in future releases");
|
||||
}
|
||||
|
||||
|
@ -236,15 +274,14 @@ parse_blur_kern_lst(const char *src, conv **dest, int max, bool *hasneg) {
|
|||
*
|
||||
* ps->root_width and ps->root_height must be valid
|
||||
*/
|
||||
bool
|
||||
parse_geometry(session_t *ps, const char *src, region_t *dest) {
|
||||
bool parse_geometry(session_t *ps, const char *src, region_t *dest) {
|
||||
pixman_region32_clear(dest);
|
||||
if (!src)
|
||||
return true;
|
||||
if (!ps->root_width || !ps->root_height)
|
||||
return true;
|
||||
|
||||
geometry_t geom = { .wid = ps->root_width, .hei = ps->root_height, .x = 0, .y = 0 };
|
||||
geometry_t geom = {.wid = ps->root_width, .hei = ps->root_height, .x = 0, .y = 0};
|
||||
long val = 0L;
|
||||
char *endptr = NULL;
|
||||
|
||||
|
@ -345,14 +382,13 @@ bool parse_rule_opacity(c2_lptr_t **res, const char *src) {
|
|||
|
||||
// Parse pattern
|
||||
// I hope 1-100 is acceptable for (void *)
|
||||
return c2_parse(res, endptr, (void *) val);
|
||||
return c2_parse(res, endptr, (void *)val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a pattern to a condition linked list.
|
||||
*/
|
||||
bool
|
||||
condlst_add(c2_lptr_t **pcondlst, const char *pattern) {
|
||||
bool condlst_add(c2_lptr_t **pcondlst, const char *pattern) {
|
||||
if (!pattern)
|
||||
return false;
|
||||
|
||||
|
@ -362,7 +398,8 @@ condlst_add(c2_lptr_t **pcondlst, const char *pattern) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void set_default_winopts(options_t *opt, win_option_mask_t *mask, bool shadow_enable, bool fading_enable) {
|
||||
void set_default_winopts(options_t *opt, win_option_mask_t *mask, bool shadow_enable,
|
||||
bool fading_enable) {
|
||||
// Apply default wintype options.
|
||||
if (!mask[WINTYPE_DESKTOP].shadow) {
|
||||
// Desktop windows are always drawn without shadow by default.
|
||||
|
@ -372,8 +409,7 @@ void set_default_winopts(options_t *opt, win_option_mask_t *mask, bool shadow_en
|
|||
|
||||
// Focused/unfocused state only apply to a few window types, all other windows
|
||||
// are always considered focused.
|
||||
const wintype_t nofocus_type[] =
|
||||
{ WINTYPE_UNKNOWN, WINTYPE_NORMAL, WINTYPE_UTILITY };
|
||||
const wintype_t nofocus_type[] = {WINTYPE_UNKNOWN, WINTYPE_NORMAL, WINTYPE_UTILITY};
|
||||
for (unsigned long i = 0; i < ARR_SIZE(nofocus_type); i++) {
|
||||
if (!mask[nofocus_type[i]].focus) {
|
||||
mask[nofocus_type[i]].focus = true;
|
||||
|
@ -403,16 +439,15 @@ void set_default_winopts(options_t *opt, win_option_mask_t *mask, bool shadow_en
|
|||
}
|
||||
if (!mask[i].opacity) {
|
||||
mask[i].opacity = true;
|
||||
// Opacity is not set to a concrete number here because the opacity logic
|
||||
// is complicated, and needs an "unset" state
|
||||
// Opacity is not set to a concrete number here because the
|
||||
// opacity logic is complicated, and needs an "unset" state
|
||||
opt->wintype_option[i].opacity = NAN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char *parse_config(options_t *opt, const char *config_file,
|
||||
bool *shadow_enable, bool *fading_enable, bool *hasneg,
|
||||
win_option_mask_t *winopt_mask) {
|
||||
char *parse_config(options_t *opt, const char *config_file, bool *shadow_enable,
|
||||
bool *fading_enable, bool *hasneg, win_option_mask_t *winopt_mask) {
|
||||
char *ret = NULL;
|
||||
#ifdef CONFIG_LIBCONFIG
|
||||
ret = parse_config_libconfig(opt, config_file, shadow_enable, fading_enable,
|
||||
|
|
17
src/config.h
17
src/config.h
|
@ -7,24 +7,24 @@
|
|||
/// Common functions and definitions for configuration parsing
|
||||
/// Used for command line arguments and config files
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/render.h> // for xcb_render_fixed_t, XXX
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xfixes.h>
|
||||
|
||||
#ifdef CONFIG_LIBCONFIG
|
||||
#include <libconfig.h>
|
||||
#endif
|
||||
|
||||
#include "region.h"
|
||||
#include "log.h"
|
||||
#include "compiler.h"
|
||||
#include "win.h"
|
||||
#include "types.h"
|
||||
#include "kernel.h"
|
||||
#include "log.h"
|
||||
#include "region.h"
|
||||
#include "types.h"
|
||||
#include "win.h"
|
||||
|
||||
typedef struct session session_t;
|
||||
|
||||
|
@ -242,8 +242,7 @@ extern const char *const VSYNC_STRS[NUM_VSYNC + 1];
|
|||
extern const char *const BACKEND_STRS[NUM_BKEND + 1];
|
||||
|
||||
attr_warn_unused_result bool parse_long(const char *, long *);
|
||||
attr_warn_unused_result bool
|
||||
parse_blur_kern_lst(const char *, conv **, int, bool *hasneg);
|
||||
attr_warn_unused_result bool parse_blur_kern_lst(const char *, conv **, int, bool *hasneg);
|
||||
attr_warn_unused_result bool parse_geometry(session_t *, const char *, region_t *);
|
||||
attr_warn_unused_result bool parse_rule_opacity(c2_lptr_t **, const char *);
|
||||
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2012-2014 Richard Grenville <pyxlcy@gmail.com>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libgen.h>
|
||||
#include <libconfig.h>
|
||||
#include <basedir_fs.h>
|
||||
#include <libconfig.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include "err.h"
|
||||
#include "common.h"
|
||||
#include "compiler.h"
|
||||
#include "config.h"
|
||||
#include "string_utils.h"
|
||||
#include "options.h"
|
||||
#include "err.h"
|
||||
#include "log.h"
|
||||
#include "options.h"
|
||||
#include "string_utils.h"
|
||||
#include "utils.h"
|
||||
#include "win.h"
|
||||
|
||||
|
@ -27,8 +27,7 @@
|
|||
*
|
||||
* So it takes a pointer to bool.
|
||||
*/
|
||||
static inline int
|
||||
lcfg_lookup_bool(const config_t *config, const char *path, bool *value) {
|
||||
static inline int lcfg_lookup_bool(const config_t *config, const char *path, bool *value) {
|
||||
int ival;
|
||||
|
||||
int ret = config_lookup_bool(config, path, &ival);
|
||||
|
@ -39,12 +38,8 @@ lcfg_lookup_bool(const config_t *config, const char *path, bool *value) {
|
|||
}
|
||||
|
||||
/// Search for config file under a base directory
|
||||
FILE *
|
||||
open_config_file_at(const char *base, char **out_path) {
|
||||
static const char *config_paths[] = {
|
||||
"/compton.conf",
|
||||
"/compton/compton.conf"
|
||||
};
|
||||
FILE *open_config_file_at(const char *base, char **out_path) {
|
||||
static const char *config_paths[] = {"/compton.conf", "/compton/compton.conf"};
|
||||
for (size_t i = 0; i < ARR_SIZE(config_paths); i++) {
|
||||
char *path = mstrjoin(base, config_paths[i]);
|
||||
FILE *ret = fopen(path, "r");
|
||||
|
@ -65,8 +60,7 @@ open_config_file_at(const char *base, char **out_path) {
|
|||
*
|
||||
* Follows the XDG specification to search for the configuration file.
|
||||
*/
|
||||
FILE *
|
||||
open_config_file(const char *cpath, char **ppath) {
|
||||
FILE *open_config_file(const char *cpath, char **ppath) {
|
||||
static const char config_filename_legacy[] = "/.compton.conf";
|
||||
|
||||
if (cpath) {
|
||||
|
@ -116,16 +110,15 @@ open_config_file(const char *cpath, char **ppath) {
|
|||
/**
|
||||
* Parse a condition list in configuration file.
|
||||
*/
|
||||
void
|
||||
parse_cfg_condlst(const config_t *pcfg, c2_lptr_t **pcondlst,
|
||||
const char *name) {
|
||||
void parse_cfg_condlst(const config_t *pcfg, c2_lptr_t **pcondlst, const char *name) {
|
||||
config_setting_t *setting = config_lookup(pcfg, name);
|
||||
if (setting) {
|
||||
// Parse an array of options
|
||||
if (config_setting_is_array(setting)) {
|
||||
int i = config_setting_length(setting);
|
||||
while (i--)
|
||||
condlst_add(pcondlst, config_setting_get_string_elem(setting, i));
|
||||
condlst_add(pcondlst,
|
||||
config_setting_get_string_elem(setting, i));
|
||||
}
|
||||
// Treat it as a single pattern if it's a string
|
||||
else if (CONFIG_TYPE_STRING == config_setting_type(setting)) {
|
||||
|
@ -145,13 +138,15 @@ parse_cfg_condlst_opct(options_t *opt, const config_t *pcfg, const char *name) {
|
|||
if (config_setting_is_array(setting)) {
|
||||
int i = config_setting_length(setting);
|
||||
while (i--)
|
||||
if (!parse_rule_opacity(&opt->opacity_rules,
|
||||
if (!parse_rule_opacity(
|
||||
&opt->opacity_rules,
|
||||
config_setting_get_string_elem(setting, i)))
|
||||
exit(1);
|
||||
}
|
||||
// Treat it as a single pattern if it's a string
|
||||
else if (config_setting_type(setting) == CONFIG_TYPE_STRING) {
|
||||
if (!parse_rule_opacity(&opt->opacity_rules, config_setting_get_string(setting)))
|
||||
if (!parse_rule_opacity(&opt->opacity_rules,
|
||||
config_setting_get_string(setting)))
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +158,8 @@ parse_cfg_condlst_opct(options_t *opt, const config_t *pcfg, const char *name) {
|
|||
* Returns the actually config_file name
|
||||
*/
|
||||
char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shadow_enable,
|
||||
bool *fading_enable, bool *conv_kern_hasneg, win_option_mask_t *winopt_mask)
|
||||
{
|
||||
bool *fading_enable, bool *conv_kern_hasneg,
|
||||
win_option_mask_t *winopt_mask) {
|
||||
char *path = NULL;
|
||||
FILE *f;
|
||||
config_t cfg;
|
||||
|
@ -203,7 +198,8 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
|||
fclose(f);
|
||||
f = NULL;
|
||||
if (read_result == CONFIG_FALSE) {
|
||||
log_fatal("Error when reading configuration file \"%s\", line %d: %s",
|
||||
log_fatal("Error when reading configuration file \"%s\", line "
|
||||
"%d: %s",
|
||||
path, config_error_line(&cfg), config_error_text(&cfg));
|
||||
goto err;
|
||||
}
|
||||
|
@ -257,8 +253,10 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
|||
};
|
||||
// -m (menu_opacity)
|
||||
if (config_lookup_float(&cfg, "menu-opacity", &dval)) {
|
||||
log_warn("Option `menu-opacity` is deprecated, and will be removed.Please use the "
|
||||
"wintype option `opacity` of `popup_menu` and `dropdown_menu` instead.");
|
||||
log_warn("Option `menu-opacity` is deprecated, and will be "
|
||||
"removed.Please use the "
|
||||
"wintype option `opacity` of `popup_menu` and `dropdown_menu` "
|
||||
"instead.");
|
||||
opt->wintype_option[WINTYPE_DROPDOWN_MENU].opacity = dval;
|
||||
opt->wintype_option[WINTYPE_POPUP_MENU].opacity = dval;
|
||||
winopt_mask[WINTYPE_DROPDOWN_MENU].opacity = true;
|
||||
|
@ -270,8 +268,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
|||
// --no-fading-open-close
|
||||
lcfg_lookup_bool(&cfg, "no-fading-openclose", &opt->no_fading_openclose);
|
||||
// --no-fading-destroyed-argb
|
||||
lcfg_lookup_bool(&cfg, "no-fading-destroyed-argb",
|
||||
&opt->no_fading_destroyed_argb);
|
||||
lcfg_lookup_bool(&cfg, "no-fading-destroyed-argb", &opt->no_fading_destroyed_argb);
|
||||
// --shadow-red
|
||||
config_lookup_float(&cfg, "shadow-red", &opt->shadow_red);
|
||||
// --shadow-green
|
||||
|
@ -282,27 +279,21 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
|||
if (config_lookup_string(&cfg, "shadow-exclude-reg", &sval))
|
||||
opt->shadow_exclude_reg_str = strdup(sval);
|
||||
// --inactive-opacity-override
|
||||
lcfg_lookup_bool(&cfg, "inactive-opacity-override",
|
||||
&opt->inactive_opacity_override);
|
||||
lcfg_lookup_bool(&cfg, "inactive-opacity-override", &opt->inactive_opacity_override);
|
||||
// --inactive-dim
|
||||
config_lookup_float(&cfg, "inactive-dim", &opt->inactive_dim);
|
||||
// --mark-wmwin-focused
|
||||
lcfg_lookup_bool(&cfg, "mark-wmwin-focused", &opt->mark_wmwin_focused);
|
||||
// --mark-ovredir-focused
|
||||
lcfg_lookup_bool(&cfg, "mark-ovredir-focused",
|
||||
&opt->mark_ovredir_focused);
|
||||
lcfg_lookup_bool(&cfg, "mark-ovredir-focused", &opt->mark_ovredir_focused);
|
||||
// --shadow-ignore-shaped
|
||||
lcfg_lookup_bool(&cfg, "shadow-ignore-shaped",
|
||||
&opt->shadow_ignore_shaped);
|
||||
lcfg_lookup_bool(&cfg, "shadow-ignore-shaped", &opt->shadow_ignore_shaped);
|
||||
// --detect-rounded-corners
|
||||
lcfg_lookup_bool(&cfg, "detect-rounded-corners",
|
||||
&opt->detect_rounded_corners);
|
||||
lcfg_lookup_bool(&cfg, "detect-rounded-corners", &opt->detect_rounded_corners);
|
||||
// --xinerama-shadow-crop
|
||||
lcfg_lookup_bool(&cfg, "xinerama-shadow-crop",
|
||||
&opt->xinerama_shadow_crop);
|
||||
lcfg_lookup_bool(&cfg, "xinerama-shadow-crop", &opt->xinerama_shadow_crop);
|
||||
// --detect-client-opacity
|
||||
lcfg_lookup_bool(&cfg, "detect-client-opacity",
|
||||
&opt->detect_client_opacity);
|
||||
lcfg_lookup_bool(&cfg, "detect-client-opacity", &opt->detect_client_opacity);
|
||||
// --refresh-rate
|
||||
config_lookup_int(&cfg, "refresh-rate", &opt->refresh_rate);
|
||||
// --vsync
|
||||
|
@ -333,18 +324,17 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
|||
// --log-file
|
||||
if (config_lookup_string(&cfg, "log-file", &sval)) {
|
||||
if (*sval != '/') {
|
||||
log_warn("The log-file in your configuration file is not an absolute path");
|
||||
log_warn("The log-file in your configuration file is not an "
|
||||
"absolute path");
|
||||
}
|
||||
opt->logpath = strdup(sval);
|
||||
}
|
||||
// --sw-opti
|
||||
lcfg_lookup_bool(&cfg, "sw-opti", &opt->sw_opti);
|
||||
// --use-ewmh-active-win
|
||||
lcfg_lookup_bool(&cfg, "use-ewmh-active-win",
|
||||
&opt->use_ewmh_active_win);
|
||||
lcfg_lookup_bool(&cfg, "use-ewmh-active-win", &opt->use_ewmh_active_win);
|
||||
// --unredir-if-possible
|
||||
lcfg_lookup_bool(&cfg, "unredir-if-possible",
|
||||
&opt->unredir_if_possible);
|
||||
lcfg_lookup_bool(&cfg, "unredir-if-possible", &opt->unredir_if_possible);
|
||||
// --unredir-if-possible-delay
|
||||
if (config_lookup_int(&cfg, "unredir-if-possible-delay", &ival))
|
||||
opt->unredir_if_possible_delay = ival;
|
||||
|
@ -353,8 +343,7 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
|||
// --detect-transient
|
||||
lcfg_lookup_bool(&cfg, "detect-transient", &opt->detect_transient);
|
||||
// --detect-client-leader
|
||||
lcfg_lookup_bool(&cfg, "detect-client-leader",
|
||||
&opt->detect_client_leader);
|
||||
lcfg_lookup_bool(&cfg, "detect-client-leader", &opt->detect_client_leader);
|
||||
// --shadow-exclude
|
||||
parse_cfg_condlst(&cfg, &opt->shadow_blacklist, "shadow-exclude");
|
||||
// --fade-exclude
|
||||
|
@ -368,15 +357,14 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
|||
// --opacity-rule
|
||||
parse_cfg_condlst_opct(opt, &cfg, "opacity-rule");
|
||||
// --unredir-if-possible-exclude
|
||||
parse_cfg_condlst(&cfg, &opt->unredir_if_possible_blacklist, "unredir-if-possible-exclude");
|
||||
parse_cfg_condlst(&cfg, &opt->unredir_if_possible_blacklist,
|
||||
"unredir-if-possible-exclude");
|
||||
// --blur-background
|
||||
lcfg_lookup_bool(&cfg, "blur-background", &opt->blur_background);
|
||||
// --blur-background-frame
|
||||
lcfg_lookup_bool(&cfg, "blur-background-frame",
|
||||
&opt->blur_background_frame);
|
||||
lcfg_lookup_bool(&cfg, "blur-background-frame", &opt->blur_background_frame);
|
||||
// --blur-background-fixed
|
||||
lcfg_lookup_bool(&cfg, "blur-background-fixed",
|
||||
&opt->blur_background_fixed);
|
||||
lcfg_lookup_bool(&cfg, "blur-background-fixed", &opt->blur_background_fixed);
|
||||
// --blur-kern
|
||||
if (config_lookup_string(&cfg, "blur-kern", &sval) &&
|
||||
!parse_blur_kern_lst(sval, opt->blur_kerns, MAX_BLUR_PASS, conv_kern_hasneg)) {
|
||||
|
@ -399,7 +387,8 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
|||
}
|
||||
// --glx-use-gpushader4
|
||||
if (config_lookup_bool(&cfg, "glx-use-gpushader4", &ival) && ival) {
|
||||
log_warn("glx-use-gpushader4 is deprecated since v6, please remove it from"
|
||||
log_warn("glx-use-gpushader4 is deprecated since v6, please remove it "
|
||||
"from"
|
||||
"your config file");
|
||||
}
|
||||
// --xrender-sync
|
||||
|
@ -421,7 +410,8 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
|
|||
log_warn("\"alpha-step\" has been removed, compton now tries to make use"
|
||||
" of all alpha values");
|
||||
|
||||
const char *deprecation_message = "has been removed. If you encounter problems "
|
||||
const char *deprecation_message =
|
||||
"has been removed. If you encounter problems "
|
||||
"without this feature, please feel free to open a bug report";
|
||||
if (lcfg_lookup_bool(&cfg, "glx-use-copysubbuffermesa", &bval) && bval)
|
||||
log_warn("\"glx-use-copysubbuffermesa\" %s", deprecation_message);
|
||||
|
|
331
src/dbus.c
331
src/dbus.c
|
@ -9,23 +9,23 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "compiler.h"
|
||||
#include "utils.h"
|
||||
#include "types.h"
|
||||
#include "win.h"
|
||||
#include "string_utils.h"
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "string_utils.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
#include "win.h"
|
||||
|
||||
#include "dbus.h"
|
||||
|
||||
|
@ -52,7 +52,8 @@ typedef uint16_t cdbus_enum_t;
|
|||
#define CDBUS_ERROR_UNKNOWN CDBUS_ERROR_PREFIX ".unknown"
|
||||
#define CDBUS_ERROR_UNKNOWN_S "Well, I don't know what happened. Do you?"
|
||||
#define CDBUS_ERROR_BADMSG CDBUS_ERROR_PREFIX ".bad_message"
|
||||
#define CDBUS_ERROR_BADMSG_S "Unrecognized command. Beware compton " \
|
||||
#define CDBUS_ERROR_BADMSG_S \
|
||||
"Unrecognized command. Beware compton " \
|
||||
"cannot make you a sandwich."
|
||||
#define CDBUS_ERROR_BADARG CDBUS_ERROR_PREFIX ".bad_argument"
|
||||
#define CDBUS_ERROR_BADARG_S "Failed to parse argument %d: %s"
|
||||
|
@ -66,41 +67,34 @@ typedef uint16_t cdbus_enum_t;
|
|||
#define CDBUS_ERROR_CUSTOM_S "%s"
|
||||
|
||||
#define cdbus_reply_err(ps, srcmsg, err_name, err_format, ...) \
|
||||
cdbus_reply_errm((ps), dbus_message_new_error_printf((srcmsg), (err_name), (err_format), ## __VA_ARGS__))
|
||||
cdbus_reply_errm((ps), dbus_message_new_error_printf( \
|
||||
(srcmsg), (err_name), (err_format), ##__VA_ARGS__))
|
||||
|
||||
static DBusHandlerResult
|
||||
cdbus_process(DBusConnection *conn, DBusMessage *m, void *);
|
||||
static DBusHandlerResult cdbus_process(DBusConnection *conn, DBusMessage *m, void *);
|
||||
|
||||
static dbus_bool_t
|
||||
cdbus_callback_add_timeout(DBusTimeout *timeout, void *data);
|
||||
static dbus_bool_t cdbus_callback_add_timeout(DBusTimeout *timeout, void *data);
|
||||
|
||||
static void
|
||||
cdbus_callback_remove_timeout(DBusTimeout *timeout, void *data);
|
||||
static void cdbus_callback_remove_timeout(DBusTimeout *timeout, void *data);
|
||||
|
||||
static void
|
||||
cdbus_callback_timeout_toggled(DBusTimeout *timeout, void *data);
|
||||
static void cdbus_callback_timeout_toggled(DBusTimeout *timeout, void *data);
|
||||
|
||||
static dbus_bool_t
|
||||
cdbus_callback_add_watch(DBusWatch *watch, void *data);
|
||||
static dbus_bool_t cdbus_callback_add_watch(DBusWatch *watch, void *data);
|
||||
|
||||
static void
|
||||
cdbus_callback_remove_watch(DBusWatch *watch, void *data);
|
||||
static void cdbus_callback_remove_watch(DBusWatch *watch, void *data);
|
||||
|
||||
static void
|
||||
cdbus_callback_watch_toggled(DBusWatch *watch, void *data);
|
||||
static void cdbus_callback_watch_toggled(DBusWatch *watch, void *data);
|
||||
|
||||
/**
|
||||
* Initialize D-Bus connection.
|
||||
*/
|
||||
bool
|
||||
cdbus_init(session_t *ps, const char *uniq) {
|
||||
bool cdbus_init(session_t *ps, const char *uniq) {
|
||||
auto cd = cmalloc(struct cdbus_data);
|
||||
cd->dbus_service = NULL;
|
||||
|
||||
// Set ps->dbus_data here because add_watch functions need it
|
||||
ps->dbus_data = cd;
|
||||
|
||||
DBusError err = { };
|
||||
DBusError err = {};
|
||||
|
||||
// Initialize
|
||||
dbus_error_init(&err);
|
||||
|
@ -125,12 +119,13 @@ cdbus_init(session_t *ps, const char *uniq) {
|
|||
// Request service name
|
||||
{
|
||||
// Build service name
|
||||
size_t service_len = strlen(CDBUS_SERVICE_NAME)+strlen(uniq)+2;
|
||||
size_t service_len = strlen(CDBUS_SERVICE_NAME) + strlen(uniq) + 2;
|
||||
char *service = ccalloc(service_len, char);
|
||||
snprintf(service, service_len, "%s.%s", CDBUS_SERVICE_NAME, uniq);
|
||||
|
||||
// Make a valid dbus name by converting non alphanumeric characters to underscore
|
||||
char *tmp = service + strlen(CDBUS_SERVICE_NAME)+1;
|
||||
// Make a valid dbus name by converting non alphanumeric characters to
|
||||
// underscore
|
||||
char *tmp = service + strlen(CDBUS_SERVICE_NAME) + 1;
|
||||
while (*tmp) {
|
||||
if (!isalnum(*tmp)) {
|
||||
*tmp = '_';
|
||||
|
@ -149,25 +144,26 @@ cdbus_init(session_t *ps, const char *uniq) {
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret
|
||||
&& DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER != ret) {
|
||||
log_error("Failed to become the primary owner of requested D-Bus name (%d).", ret);
|
||||
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret &&
|
||||
DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER != ret) {
|
||||
log_error("Failed to become the primary owner of requested D-Bus "
|
||||
"name (%d).",
|
||||
ret);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add watch handlers
|
||||
if (!dbus_connection_set_watch_functions(cd->dbus_conn,
|
||||
cdbus_callback_add_watch, cdbus_callback_remove_watch,
|
||||
if (!dbus_connection_set_watch_functions(cd->dbus_conn, cdbus_callback_add_watch,
|
||||
cdbus_callback_remove_watch,
|
||||
cdbus_callback_watch_toggled, ps, NULL)) {
|
||||
log_error("Failed to add D-Bus watch functions.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// Add timeout handlers
|
||||
if (!dbus_connection_set_timeout_functions(cd->dbus_conn,
|
||||
cdbus_callback_add_timeout, cdbus_callback_remove_timeout,
|
||||
if (!dbus_connection_set_timeout_functions(
|
||||
cd->dbus_conn, cdbus_callback_add_timeout, cdbus_callback_remove_timeout,
|
||||
cdbus_callback_timeout_toggled, ps, NULL)) {
|
||||
log_error("Failed to add D-Bus timeout functions.");
|
||||
goto fail;
|
||||
|
@ -193,13 +189,12 @@ fail:
|
|||
/**
|
||||
* Destroy D-Bus connection.
|
||||
*/
|
||||
void
|
||||
cdbus_destroy(session_t *ps) {
|
||||
void cdbus_destroy(session_t *ps) {
|
||||
struct cdbus_data *cd = ps->dbus_data;
|
||||
if (cd->dbus_conn) {
|
||||
// Release DBus name firstly
|
||||
if (cd->dbus_service) {
|
||||
DBusError err = { };
|
||||
DBusError err = {};
|
||||
dbus_error_init(&err);
|
||||
|
||||
dbus_bus_release_name(cd->dbus_conn, cd->dbus_service, &err);
|
||||
|
@ -229,8 +224,7 @@ typedef struct ev_dbus_timer {
|
|||
/**
|
||||
* Callback for handling a D-Bus timeout.
|
||||
*/
|
||||
static void
|
||||
cdbus_callback_handle_timeout(EV_P_ ev_timer *w, int revents) {
|
||||
static void cdbus_callback_handle_timeout(EV_P_ ev_timer *w, int revents) {
|
||||
ev_dbus_timer *t = (void *)w;
|
||||
dbus_timeout_handle(t->t);
|
||||
}
|
||||
|
@ -238,8 +232,7 @@ cdbus_callback_handle_timeout(EV_P_ ev_timer *w, int revents) {
|
|||
/**
|
||||
* Callback for adding D-Bus timeout.
|
||||
*/
|
||||
static dbus_bool_t
|
||||
cdbus_callback_add_timeout(DBusTimeout *timeout, void *data) {
|
||||
static dbus_bool_t cdbus_callback_add_timeout(DBusTimeout *timeout, void *data) {
|
||||
session_t *ps = data;
|
||||
|
||||
auto t = ccalloc(1, ev_dbus_timer);
|
||||
|
@ -257,8 +250,7 @@ cdbus_callback_add_timeout(DBusTimeout *timeout, void *data) {
|
|||
/**
|
||||
* Callback for removing D-Bus timeout.
|
||||
*/
|
||||
static void
|
||||
cdbus_callback_remove_timeout(DBusTimeout *timeout, void *data) {
|
||||
static void cdbus_callback_remove_timeout(DBusTimeout *timeout, void *data) {
|
||||
session_t *ps = data;
|
||||
|
||||
ev_dbus_timer *t = dbus_timeout_get_data(timeout);
|
||||
|
@ -270,8 +262,7 @@ cdbus_callback_remove_timeout(DBusTimeout *timeout, void *data) {
|
|||
/**
|
||||
* Callback for toggling a D-Bus timeout.
|
||||
*/
|
||||
static void
|
||||
cdbus_callback_timeout_toggled(DBusTimeout *timeout, void *data) {
|
||||
static void cdbus_callback_timeout_toggled(DBusTimeout *timeout, void *data) {
|
||||
session_t *ps = data;
|
||||
ev_dbus_timer *t = dbus_timeout_get_data(timeout);
|
||||
|
||||
|
@ -304,14 +295,14 @@ void cdbus_io_callback(EV_P_ ev_io *w, int revents) {
|
|||
if (revents & EV_WRITE)
|
||||
flags |= DBUS_WATCH_WRITABLE;
|
||||
dbus_watch_handle(dw->dw, flags);
|
||||
while (dbus_connection_dispatch(dw->cd->dbus_conn) != DBUS_DISPATCH_COMPLETE);
|
||||
while (dbus_connection_dispatch(dw->cd->dbus_conn) != DBUS_DISPATCH_COMPLETE)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the poll condition of a DBusWatch.
|
||||
*/
|
||||
static inline int
|
||||
cdbus_get_watch_cond(DBusWatch *watch) {
|
||||
static inline int cdbus_get_watch_cond(DBusWatch *watch) {
|
||||
const unsigned flags = dbus_watch_get_flags(watch);
|
||||
int condition = 0;
|
||||
if (flags & DBUS_WATCH_READABLE)
|
||||
|
@ -325,8 +316,7 @@ cdbus_get_watch_cond(DBusWatch *watch) {
|
|||
/**
|
||||
* Callback for adding D-Bus watch.
|
||||
*/
|
||||
static dbus_bool_t
|
||||
cdbus_callback_add_watch(DBusWatch *watch, void *data) {
|
||||
static dbus_bool_t cdbus_callback_add_watch(DBusWatch *watch, void *data) {
|
||||
session_t *ps = data;
|
||||
|
||||
auto w = ccalloc(1, ev_dbus_io);
|
||||
|
@ -348,8 +338,7 @@ cdbus_callback_add_watch(DBusWatch *watch, void *data) {
|
|||
/**
|
||||
* Callback for removing D-Bus watch.
|
||||
*/
|
||||
static void
|
||||
cdbus_callback_remove_watch(DBusWatch *watch, void *data) {
|
||||
static void cdbus_callback_remove_watch(DBusWatch *watch, void *data) {
|
||||
session_t *ps = data;
|
||||
ev_dbus_io *w = dbus_watch_get_data(watch);
|
||||
ev_io_stop(ps->loop, &w->w);
|
||||
|
@ -359,8 +348,7 @@ cdbus_callback_remove_watch(DBusWatch *watch, void *data) {
|
|||
/**
|
||||
* Callback for toggling D-Bus watch status.
|
||||
*/
|
||||
static void
|
||||
cdbus_callback_watch_toggled(DBusWatch *watch, void *data) {
|
||||
static void cdbus_callback_watch_toggled(DBusWatch *watch, void *data) {
|
||||
session_t *ps = data;
|
||||
ev_io *w = dbus_watch_get_data(watch);
|
||||
if (dbus_watch_get_enabled(watch))
|
||||
|
@ -378,14 +366,12 @@ cdbus_callback_watch_toggled(DBusWatch *watch, void *data) {
|
|||
/**
|
||||
* Callback to append a bool argument to a message.
|
||||
*/
|
||||
static bool
|
||||
cdbus_apdarg_bool(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
static bool cdbus_apdarg_bool(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
assert(data);
|
||||
|
||||
dbus_bool_t val = *(const bool *) data;
|
||||
dbus_bool_t val = *(const bool *)data;
|
||||
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &val,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &val, DBUS_TYPE_INVALID)) {
|
||||
log_error("Failed to append argument.");
|
||||
return false;
|
||||
}
|
||||
|
@ -396,10 +382,8 @@ cdbus_apdarg_bool(session_t *ps, DBusMessage *msg, const void *data) {
|
|||
/**
|
||||
* Callback to append an int32 argument to a message.
|
||||
*/
|
||||
static bool
|
||||
cdbus_apdarg_int32(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_INT32, data,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
static bool cdbus_apdarg_int32(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_INT32, data, DBUS_TYPE_INVALID)) {
|
||||
log_error("Failed to append argument.");
|
||||
return false;
|
||||
}
|
||||
|
@ -410,10 +394,8 @@ cdbus_apdarg_int32(session_t *ps, DBusMessage *msg, const void *data) {
|
|||
/**
|
||||
* Callback to append an uint32 argument to a message.
|
||||
*/
|
||||
static bool
|
||||
cdbus_apdarg_uint32(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, data,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
static bool cdbus_apdarg_uint32(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, data, DBUS_TYPE_INVALID)) {
|
||||
log_error("Failed to append argument.");
|
||||
return false;
|
||||
}
|
||||
|
@ -424,10 +406,8 @@ cdbus_apdarg_uint32(session_t *ps, DBusMessage *msg, const void *data) {
|
|||
/**
|
||||
* Callback to append a double argument to a message.
|
||||
*/
|
||||
static bool
|
||||
cdbus_apdarg_double(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_DOUBLE, data,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
static bool cdbus_apdarg_double(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_DOUBLE, data, DBUS_TYPE_INVALID)) {
|
||||
log_error("Failed to append argument.");
|
||||
return false;
|
||||
}
|
||||
|
@ -438,13 +418,11 @@ cdbus_apdarg_double(session_t *ps, DBusMessage *msg, const void *data) {
|
|||
/**
|
||||
* Callback to append a Window argument to a message.
|
||||
*/
|
||||
static bool
|
||||
cdbus_apdarg_wid(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
static bool cdbus_apdarg_wid(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
assert(data);
|
||||
cdbus_window_t val = *(const xcb_window_t *)data;
|
||||
|
||||
if (!dbus_message_append_args(msg, CDBUS_TYPE_WINDOW, &val,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
if (!dbus_message_append_args(msg, CDBUS_TYPE_WINDOW, &val, DBUS_TYPE_INVALID)) {
|
||||
log_error("Failed to append argument.");
|
||||
return false;
|
||||
}
|
||||
|
@ -455,11 +433,9 @@ cdbus_apdarg_wid(session_t *ps, DBusMessage *msg, const void *data) {
|
|||
/**
|
||||
* Callback to append an cdbus_enum_t argument to a message.
|
||||
*/
|
||||
static bool
|
||||
cdbus_apdarg_enum(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
static bool cdbus_apdarg_enum(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
assert(data);
|
||||
if (!dbus_message_append_args(msg, CDBUS_TYPE_ENUM, data,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
if (!dbus_message_append_args(msg, CDBUS_TYPE_ENUM, data, DBUS_TYPE_INVALID)) {
|
||||
log_error("Failed to append argument.");
|
||||
return false;
|
||||
}
|
||||
|
@ -470,14 +446,12 @@ cdbus_apdarg_enum(session_t *ps, DBusMessage *msg, const void *data) {
|
|||
/**
|
||||
* Callback to append a string argument to a message.
|
||||
*/
|
||||
static bool
|
||||
cdbus_apdarg_string(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
static bool cdbus_apdarg_string(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
const char *str = data;
|
||||
if (!str)
|
||||
str = "";
|
||||
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &str,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID)) {
|
||||
log_error("Failed to append argument.");
|
||||
return false;
|
||||
}
|
||||
|
@ -488,8 +462,7 @@ cdbus_apdarg_string(session_t *ps, DBusMessage *msg, const void *data) {
|
|||
/**
|
||||
* Callback to append all window IDs to a message.
|
||||
*/
|
||||
static bool
|
||||
cdbus_apdarg_wids(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
static bool cdbus_apdarg_wids(session_t *ps, DBusMessage *msg, const void *data) {
|
||||
// Get the number of wids we are to include
|
||||
unsigned count = 0;
|
||||
for (win *w = ps->list; w; w = w->next) {
|
||||
|
@ -520,8 +493,8 @@ cdbus_apdarg_wids(session_t *ps, DBusMessage *msg, const void *data) {
|
|||
}
|
||||
|
||||
// Append arguments
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_ARRAY, CDBUS_TYPE_WINDOW,
|
||||
&arr, count, DBUS_TYPE_INVALID)) {
|
||||
if (!dbus_message_append_args(msg, DBUS_TYPE_ARRAY, CDBUS_TYPE_WINDOW, &arr,
|
||||
count, DBUS_TYPE_INVALID)) {
|
||||
log_error("Failed to append argument.");
|
||||
free(arr);
|
||||
return false;
|
||||
|
@ -541,16 +514,14 @@ cdbus_apdarg_wids(session_t *ps, DBusMessage *msg, const void *data) {
|
|||
* add an argument
|
||||
* @param data data pointer to pass to the function
|
||||
*/
|
||||
static bool
|
||||
cdbus_signal(session_t *ps, const char *name,
|
||||
static bool cdbus_signal(session_t *ps, const char *name,
|
||||
bool (*func)(session_t *ps, DBusMessage *msg, const void *data),
|
||||
const void *data) {
|
||||
struct cdbus_data *cd = ps->dbus_data;
|
||||
DBusMessage* msg = NULL;
|
||||
DBusMessage *msg = NULL;
|
||||
|
||||
// Create a signal
|
||||
msg = dbus_message_new_signal(CDBUS_OBJECT_NAME, CDBUS_INTERFACE_NAME,
|
||||
name);
|
||||
msg = dbus_message_new_signal(CDBUS_OBJECT_NAME, CDBUS_INTERFACE_NAME, name);
|
||||
if (!msg) {
|
||||
log_error("Failed to create D-Bus signal.");
|
||||
return false;
|
||||
|
@ -579,8 +550,7 @@ cdbus_signal(session_t *ps, const char *name,
|
|||
/**
|
||||
* Send a signal with a Window ID as argument.
|
||||
*/
|
||||
static inline bool
|
||||
cdbus_signal_wid(session_t *ps, const char *name, xcb_window_t wid) {
|
||||
static inline bool cdbus_signal_wid(session_t *ps, const char *name, xcb_window_t wid) {
|
||||
return cdbus_signal(ps, name, cdbus_apdarg_wid, &wid);
|
||||
}
|
||||
|
||||
|
@ -593,12 +563,11 @@ cdbus_signal_wid(session_t *ps, const char *name, xcb_window_t wid) {
|
|||
* add an argument
|
||||
* @param data data pointer to pass to the function
|
||||
*/
|
||||
static bool
|
||||
cdbus_reply(session_t *ps, DBusMessage *srcmsg,
|
||||
static bool cdbus_reply(session_t *ps, DBusMessage *srcmsg,
|
||||
bool (*func)(session_t *ps, DBusMessage *msg, const void *data),
|
||||
const void *data) {
|
||||
struct cdbus_data *cd = ps->dbus_data;
|
||||
DBusMessage* msg = NULL;
|
||||
DBusMessage *msg = NULL;
|
||||
|
||||
// Create a reply
|
||||
msg = dbus_message_new_method_return(srcmsg);
|
||||
|
@ -630,56 +599,49 @@ cdbus_reply(session_t *ps, DBusMessage *srcmsg,
|
|||
/**
|
||||
* Send a reply with a bool argument.
|
||||
*/
|
||||
static inline bool
|
||||
cdbus_reply_bool(session_t *ps, DBusMessage *srcmsg, bool bval) {
|
||||
static inline bool cdbus_reply_bool(session_t *ps, DBusMessage *srcmsg, bool bval) {
|
||||
return cdbus_reply(ps, srcmsg, cdbus_apdarg_bool, &bval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reply with an int32 argument.
|
||||
*/
|
||||
static inline bool
|
||||
cdbus_reply_int32(session_t *ps, DBusMessage *srcmsg, int32_t val) {
|
||||
static inline bool cdbus_reply_int32(session_t *ps, DBusMessage *srcmsg, int32_t val) {
|
||||
return cdbus_reply(ps, srcmsg, cdbus_apdarg_int32, &val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reply with an uint32 argument.
|
||||
*/
|
||||
static inline bool
|
||||
cdbus_reply_uint32(session_t *ps, DBusMessage *srcmsg, uint32_t val) {
|
||||
static inline bool cdbus_reply_uint32(session_t *ps, DBusMessage *srcmsg, uint32_t val) {
|
||||
return cdbus_reply(ps, srcmsg, cdbus_apdarg_uint32, &val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reply with a double argument.
|
||||
*/
|
||||
static inline bool
|
||||
cdbus_reply_double(session_t *ps, DBusMessage *srcmsg, double val) {
|
||||
static inline bool cdbus_reply_double(session_t *ps, DBusMessage *srcmsg, double val) {
|
||||
return cdbus_reply(ps, srcmsg, cdbus_apdarg_double, &val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reply with a wid argument.
|
||||
*/
|
||||
static inline bool
|
||||
cdbus_reply_wid(session_t *ps, DBusMessage *srcmsg, xcb_window_t wid) {
|
||||
static inline bool cdbus_reply_wid(session_t *ps, DBusMessage *srcmsg, xcb_window_t wid) {
|
||||
return cdbus_reply(ps, srcmsg, cdbus_apdarg_wid, &wid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reply with a string argument.
|
||||
*/
|
||||
static inline bool
|
||||
cdbus_reply_string(session_t *ps, DBusMessage *srcmsg, const char *str) {
|
||||
static inline bool cdbus_reply_string(session_t *ps, DBusMessage *srcmsg, const char *str) {
|
||||
return cdbus_reply(ps, srcmsg, cdbus_apdarg_string, str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reply with a enum argument.
|
||||
*/
|
||||
static inline bool
|
||||
cdbus_reply_enum(session_t *ps, DBusMessage *srcmsg, cdbus_enum_t eval) {
|
||||
static inline bool cdbus_reply_enum(session_t *ps, DBusMessage *srcmsg, cdbus_enum_t eval) {
|
||||
return cdbus_reply(ps, srcmsg, cdbus_apdarg_enum, &eval);
|
||||
}
|
||||
|
||||
|
@ -689,8 +651,7 @@ cdbus_reply_enum(session_t *ps, DBusMessage *srcmsg, cdbus_enum_t eval) {
|
|||
* @param ps current session
|
||||
* @param msg the new error DBusMessage
|
||||
*/
|
||||
static bool
|
||||
cdbus_reply_errm(session_t *ps, DBusMessage *msg) {
|
||||
static bool cdbus_reply_errm(session_t *ps, DBusMessage *msg) {
|
||||
struct cdbus_data *cd = ps->dbus_data;
|
||||
if (!msg) {
|
||||
log_error("Failed to create D-Bus reply.");
|
||||
|
@ -719,11 +680,10 @@ cdbus_reply_errm(session_t *ps, DBusMessage *msg) {
|
|||
* @param pdest pointer to the target
|
||||
* @return true if successful, false otherwise.
|
||||
*/
|
||||
static bool
|
||||
cdbus_msg_get_arg(DBusMessage *msg, int count, const int type, void *pdest) {
|
||||
static bool cdbus_msg_get_arg(DBusMessage *msg, int count, const int type, void *pdest) {
|
||||
assert(count >= 0);
|
||||
|
||||
DBusMessageIter iter = { };
|
||||
DBusMessageIter iter = {};
|
||||
if (!dbus_message_iter_init(msg, &iter)) {
|
||||
log_error("Message has no argument.");
|
||||
return false;
|
||||
|
@ -757,8 +717,7 @@ cdbus_msg_get_arg(DBusMessage *msg, int count, const int type, void *pdest) {
|
|||
/**
|
||||
* Process a list_win D-Bus request.
|
||||
*/
|
||||
static bool
|
||||
cdbus_process_list_win(session_t *ps, DBusMessage *msg) {
|
||||
static bool cdbus_process_list_win(session_t *ps, DBusMessage *msg) {
|
||||
cdbus_reply(ps, msg, cdbus_apdarg_wids, NULL);
|
||||
|
||||
return true;
|
||||
|
@ -767,16 +726,13 @@ cdbus_process_list_win(session_t *ps, DBusMessage *msg) {
|
|||
/**
|
||||
* Process a win_get D-Bus request.
|
||||
*/
|
||||
static bool
|
||||
cdbus_process_win_get(session_t *ps, DBusMessage *msg) {
|
||||
static bool cdbus_process_win_get(session_t *ps, DBusMessage *msg) {
|
||||
cdbus_window_t wid = XCB_NONE;
|
||||
const char *target = NULL;
|
||||
DBusError err = { };
|
||||
DBusError err = {};
|
||||
|
||||
if (!dbus_message_get_args(msg, &err,
|
||||
CDBUS_TYPE_WINDOW, &wid,
|
||||
DBUS_TYPE_STRING, &target,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
if (!dbus_message_get_args(msg, &err, CDBUS_TYPE_WINDOW, &wid, DBUS_TYPE_STRING,
|
||||
&target, DBUS_TYPE_INVALID)) {
|
||||
log_error("Failed to parse argument of \"win_get\" (%s).", err.message);
|
||||
dbus_error_free(&err);
|
||||
return false;
|
||||
|
@ -800,7 +756,7 @@ cdbus_process_win_get(session_t *ps, DBusMessage *msg) {
|
|||
|
||||
// next
|
||||
if (!strcmp("next", target)) {
|
||||
cdbus_reply_wid(ps, msg, (w->next ? w->next->id: 0));
|
||||
cdbus_reply_wid(ps, msg, (w->next ? w->next->id : 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -869,16 +825,13 @@ cdbus_process_win_get(session_t *ps, DBusMessage *msg) {
|
|||
/**
|
||||
* Process a win_set D-Bus request.
|
||||
*/
|
||||
static bool
|
||||
cdbus_process_win_set(session_t *ps, DBusMessage *msg) {
|
||||
static bool cdbus_process_win_set(session_t *ps, DBusMessage *msg) {
|
||||
cdbus_window_t wid = XCB_NONE;
|
||||
const char *target = NULL;
|
||||
DBusError err = { };
|
||||
DBusError err = {};
|
||||
|
||||
if (!dbus_message_get_args(msg, &err,
|
||||
CDBUS_TYPE_WINDOW, &wid,
|
||||
DBUS_TYPE_STRING, &target,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
if (!dbus_message_get_args(msg, &err, CDBUS_TYPE_WINDOW, &wid, DBUS_TYPE_STRING,
|
||||
&target, DBUS_TYPE_INVALID)) {
|
||||
log_error("(): Failed to parse argument of \"win_set\" (%s).", err.message);
|
||||
dbus_error_free(&err);
|
||||
return false;
|
||||
|
@ -948,8 +901,7 @@ cdbus_process_win_set_success:
|
|||
/**
|
||||
* Process a find_win D-Bus request.
|
||||
*/
|
||||
static bool
|
||||
cdbus_process_find_win(session_t *ps, DBusMessage *msg) {
|
||||
static bool cdbus_process_find_win(session_t *ps, DBusMessage *msg) {
|
||||
const char *target = NULL;
|
||||
|
||||
if (!cdbus_msg_get_arg(msg, 0, DBUS_TYPE_STRING, &target))
|
||||
|
@ -971,8 +923,7 @@ cdbus_process_find_win(session_t *ps, DBusMessage *msg) {
|
|||
win *w = find_focused(ps);
|
||||
if (w)
|
||||
wid = w->id;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
log_error(CDBUS_ERROR_BADTGT_S, target);
|
||||
cdbus_reply_err(ps, msg, CDBUS_ERROR_BADTGT, CDBUS_ERROR_BADTGT_S, target);
|
||||
|
||||
|
@ -987,8 +938,7 @@ cdbus_process_find_win(session_t *ps, DBusMessage *msg) {
|
|||
/**
|
||||
* Process a opts_get D-Bus request.
|
||||
*/
|
||||
static bool
|
||||
cdbus_process_opts_get(session_t *ps, DBusMessage *msg) {
|
||||
static bool cdbus_process_opts_get(session_t *ps, DBusMessage *msg) {
|
||||
const char *target = NULL;
|
||||
|
||||
if (!cdbus_msg_get_arg(msg, 0, DBUS_TYPE_STRING, &target))
|
||||
|
@ -1109,8 +1059,7 @@ void queue_redraw(session_t *ps);
|
|||
/**
|
||||
* Process a opts_set D-Bus request.
|
||||
*/
|
||||
static bool
|
||||
cdbus_process_opts_set(session_t *ps, DBusMessage *msg) {
|
||||
static bool cdbus_process_opts_set(session_t *ps, DBusMessage *msg) {
|
||||
const char *target = NULL;
|
||||
|
||||
if (!cdbus_msg_get_arg(msg, 0, DBUS_TYPE_STRING, &target))
|
||||
|
@ -1218,10 +1167,10 @@ cdbus_process_opts_set_success:
|
|||
/**
|
||||
* Process an Introspect D-Bus request.
|
||||
*/
|
||||
static bool
|
||||
cdbus_process_introspect(session_t *ps, DBusMessage *msg) {
|
||||
static bool cdbus_process_introspect(session_t *ps, DBusMessage *msg) {
|
||||
static const char *str_introspect =
|
||||
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
|
||||
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection "
|
||||
"1.0//EN\"\n"
|
||||
" \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
|
||||
"<node name='" CDBUS_OBJECT_NAME "'>\n"
|
||||
" <interface name='org.freedesktop.DBus.Introspectable'>\n"
|
||||
|
@ -1268,8 +1217,7 @@ cdbus_process_introspect(session_t *ps, DBusMessage *msg) {
|
|||
/**
|
||||
* Process a message from D-Bus.
|
||||
*/
|
||||
static DBusHandlerResult
|
||||
cdbus_process(DBusConnection *c, DBusMessage *msg, void *ud) {
|
||||
static DBusHandlerResult cdbus_process(DBusConnection *c, DBusMessage *msg, void *ud) {
|
||||
session_t *ps = ud;
|
||||
bool handled = false;
|
||||
|
||||
|
@ -1281,77 +1229,66 @@ cdbus_process(DBusConnection *c, DBusMessage *msg, void *ud) {
|
|||
if (!dbus_message_get_no_reply(msg))
|
||||
cdbus_reply_bool(ps, msg, true);
|
||||
handled = true;
|
||||
}
|
||||
else if (cdbus_m_ismethod("repaint")) {
|
||||
} else if (cdbus_m_ismethod("repaint")) {
|
||||
force_repaint(ps);
|
||||
if (!dbus_message_get_no_reply(msg))
|
||||
cdbus_reply_bool(ps, msg, true);
|
||||
handled = true;
|
||||
}
|
||||
else if (cdbus_m_ismethod("list_win")) {
|
||||
} else if (cdbus_m_ismethod("list_win")) {
|
||||
handled = cdbus_process_list_win(ps, msg);
|
||||
}
|
||||
else if (cdbus_m_ismethod("win_get")) {
|
||||
} else if (cdbus_m_ismethod("win_get")) {
|
||||
handled = cdbus_process_win_get(ps, msg);
|
||||
}
|
||||
else if (cdbus_m_ismethod("win_set")) {
|
||||
} else if (cdbus_m_ismethod("win_set")) {
|
||||
handled = cdbus_process_win_set(ps, msg);
|
||||
}
|
||||
else if (cdbus_m_ismethod("find_win")) {
|
||||
} else if (cdbus_m_ismethod("find_win")) {
|
||||
handled = cdbus_process_find_win(ps, msg);
|
||||
}
|
||||
else if (cdbus_m_ismethod("opts_get")) {
|
||||
} else if (cdbus_m_ismethod("opts_get")) {
|
||||
handled = cdbus_process_opts_get(ps, msg);
|
||||
}
|
||||
else if (cdbus_m_ismethod("opts_set")) {
|
||||
} else if (cdbus_m_ismethod("opts_set")) {
|
||||
handled = cdbus_process_opts_set(ps, msg);
|
||||
}
|
||||
#undef cdbus_m_ismethod
|
||||
else if (dbus_message_is_method_call(msg,
|
||||
"org.freedesktop.DBus.Introspectable", "Introspect")) {
|
||||
else if (dbus_message_is_method_call(msg, "org.freedesktop.DBus.Introspectable",
|
||||
"Introspect")) {
|
||||
handled = cdbus_process_introspect(ps, msg);
|
||||
}
|
||||
else if (dbus_message_is_method_call(msg,
|
||||
"org.freedesktop.DBus.Peer", "Ping")) {
|
||||
} else if (dbus_message_is_method_call(msg, "org.freedesktop.DBus.Peer", "Ping")) {
|
||||
cdbus_reply(ps, msg, NULL, NULL);
|
||||
handled = true;
|
||||
}
|
||||
else if (dbus_message_is_method_call(msg,
|
||||
"org.freedesktop.DBus.Peer", "GetMachineId")) {
|
||||
} else if (dbus_message_is_method_call(msg, "org.freedesktop.DBus.Peer",
|
||||
"GetMachineId")) {
|
||||
char *uuid = dbus_get_local_machine_id();
|
||||
if (uuid) {
|
||||
cdbus_reply_string(ps, msg, uuid);
|
||||
dbus_free(uuid);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameAcquired")
|
||||
|| dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameLost")) {
|
||||
} else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameAcquired") ||
|
||||
dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameLost")) {
|
||||
handled = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (DBUS_MESSAGE_TYPE_ERROR == dbus_message_get_type(msg)) {
|
||||
log_error("Error message of path \"%s\" "
|
||||
log_error(
|
||||
"Error message of path \"%s\" "
|
||||
"interface \"%s\", member \"%s\", error \"%s\"",
|
||||
dbus_message_get_path(msg), dbus_message_get_interface(msg),
|
||||
dbus_message_get_member(msg), dbus_message_get_error_name(msg));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
log_error("Illegal message of type \"%s\", path \"%s\" "
|
||||
"interface \"%s\", member \"%s\"",
|
||||
cdbus_repr_msgtype(msg), dbus_message_get_path(msg),
|
||||
dbus_message_get_interface(msg), dbus_message_get_member(msg));
|
||||
dbus_message_get_interface(msg),
|
||||
dbus_message_get_member(msg));
|
||||
}
|
||||
if (DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg)
|
||||
&& !dbus_message_get_no_reply(msg))
|
||||
if (DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg) &&
|
||||
!dbus_message_get_no_reply(msg))
|
||||
cdbus_reply_err(ps, msg, CDBUS_ERROR_BADMSG, CDBUS_ERROR_BADMSG_S);
|
||||
handled = true;
|
||||
}
|
||||
|
||||
// If the message could not be processed, and an reply is expected, return
|
||||
// an empty reply.
|
||||
if (!handled && DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg)
|
||||
&& !dbus_message_get_no_reply(msg)) {
|
||||
if (!handled && DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg) &&
|
||||
!dbus_message_get_no_reply(msg)) {
|
||||
cdbus_reply_err(ps, msg, CDBUS_ERROR_UNKNOWN, CDBUS_ERROR_UNKNOWN_S);
|
||||
handled = true;
|
||||
}
|
||||
|
@ -1362,43 +1299,37 @@ cdbus_process(DBusConnection *c, DBusMessage *msg, void *ud) {
|
|||
/** @name Core callbacks
|
||||
*/
|
||||
///@{
|
||||
void
|
||||
cdbus_ev_win_added(session_t *ps, win *w) {
|
||||
void cdbus_ev_win_added(session_t *ps, win *w) {
|
||||
struct cdbus_data *cd = ps->dbus_data;
|
||||
if (cd->dbus_conn)
|
||||
cdbus_signal_wid(ps, "win_added", w->id);
|
||||
}
|
||||
|
||||
void
|
||||
cdbus_ev_win_destroyed(session_t *ps, win *w) {
|
||||
void cdbus_ev_win_destroyed(session_t *ps, win *w) {
|
||||
struct cdbus_data *cd = ps->dbus_data;
|
||||
if (cd->dbus_conn)
|
||||
cdbus_signal_wid(ps, "win_destroyed", w->id);
|
||||
}
|
||||
|
||||
void
|
||||
cdbus_ev_win_mapped(session_t *ps, win *w) {
|
||||
void cdbus_ev_win_mapped(session_t *ps, win *w) {
|
||||
struct cdbus_data *cd = ps->dbus_data;
|
||||
if (cd->dbus_conn)
|
||||
cdbus_signal_wid(ps, "win_mapped", w->id);
|
||||
}
|
||||
|
||||
void
|
||||
cdbus_ev_win_unmapped(session_t *ps, win *w) {
|
||||
void cdbus_ev_win_unmapped(session_t *ps, win *w) {
|
||||
struct cdbus_data *cd = ps->dbus_data;
|
||||
if (cd->dbus_conn)
|
||||
cdbus_signal_wid(ps, "win_unmapped", w->id);
|
||||
}
|
||||
|
||||
void
|
||||
cdbus_ev_win_focusout(session_t *ps, win *w) {
|
||||
void cdbus_ev_win_focusout(session_t *ps, win *w) {
|
||||
struct cdbus_data *cd = ps->dbus_data;
|
||||
if (cd->dbus_conn)
|
||||
cdbus_signal_wid(ps, "win_focusout", w->id);
|
||||
}
|
||||
|
||||
void
|
||||
cdbus_ev_win_focusin(session_t *ps, win *w) {
|
||||
void cdbus_ev_win_focusin(session_t *ps, win *w) {
|
||||
struct cdbus_data *cd = ps->dbus_data;
|
||||
if (cd->dbus_conn)
|
||||
cdbus_signal_wid(ps, "win_focusin", w->id);
|
||||
|
|
250
src/opengl.c
250
src/opengl.c
|
@ -9,29 +9,28 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/render.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#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 "kernel.h"
|
||||
#include "backend/gl/gl_common.h"
|
||||
#include "backend/gl/glx.h"
|
||||
#include "common.h"
|
||||
#include "compiler.h"
|
||||
#include "config.h"
|
||||
#include "kernel.h"
|
||||
#include "log.h"
|
||||
#include "region.h"
|
||||
#include "string_utils.h"
|
||||
#include "utils.h"
|
||||
#include "win.h"
|
||||
|
||||
#include "opengl.h"
|
||||
|
||||
static inline XVisualInfo *
|
||||
get_visualinfo_from_visual(session_t *ps, xcb_visualid_t visual) {
|
||||
XVisualInfo vreq = { .visualid = visual };
|
||||
static inline XVisualInfo *get_visualinfo_from_visual(session_t *ps, xcb_visualid_t visual) {
|
||||
XVisualInfo vreq = {.visualid = visual};
|
||||
int nitems = 0;
|
||||
|
||||
return XGetVisualInfo(ps->dpy, VisualIDMask, &vreq, &nitems);
|
||||
|
@ -40,8 +39,7 @@ get_visualinfo_from_visual(session_t *ps, xcb_visualid_t visual) {
|
|||
/**
|
||||
* Initialize OpenGL.
|
||||
*/
|
||||
bool
|
||||
glx_init(session_t *ps, bool need_render) {
|
||||
bool glx_init(session_t *ps, bool need_render) {
|
||||
bool success = false;
|
||||
XVisualInfo *pvis = NULL;
|
||||
|
||||
|
@ -75,8 +73,7 @@ glx_init(session_t *ps, bool need_render) {
|
|||
goto glx_init_end;
|
||||
}
|
||||
|
||||
if (Success != glXGetConfig(ps->dpy, pvis, GLX_DOUBLEBUFFER, &value)
|
||||
|| !value) {
|
||||
if (Success != glXGetConfig(ps->dpy, pvis, GLX_DOUBLEBUFFER, &value) || !value) {
|
||||
log_error("Root visual is not a double buffered GL visual.");
|
||||
goto glx_init_end;
|
||||
}
|
||||
|
@ -110,24 +107,24 @@ glx_init(session_t *ps, bool need_render) {
|
|||
{
|
||||
GLXFBConfig fbconfig = get_fbconfig_from_visualinfo(ps, pvis);
|
||||
if (!fbconfig) {
|
||||
log_error("Failed to get GLXFBConfig for root visual %#lx.", pvis->visualid);
|
||||
log_error("Failed to get GLXFBConfig for root visual "
|
||||
"%#lx.",
|
||||
pvis->visualid);
|
||||
goto glx_init_end;
|
||||
}
|
||||
|
||||
f_glXCreateContextAttribsARB p_glXCreateContextAttribsARB =
|
||||
(f_glXCreateContextAttribsARB)
|
||||
glXGetProcAddress((const GLubyte *) "glXCreateContextAttribsARB");
|
||||
(f_glXCreateContextAttribsARB)glXGetProcAddress(
|
||||
(const GLubyte *)"glXCreateContextAttribsARB");
|
||||
if (!p_glXCreateContextAttribsARB) {
|
||||
log_error("Failed to get glXCreateContextAttribsARB().");
|
||||
goto glx_init_end;
|
||||
}
|
||||
|
||||
static const int attrib_list[] = {
|
||||
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
|
||||
None
|
||||
};
|
||||
psglx->context = p_glXCreateContextAttribsARB(ps->dpy, fbconfig, NULL,
|
||||
GL_TRUE, attrib_list);
|
||||
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, None};
|
||||
psglx->context = p_glXCreateContextAttribsARB(
|
||||
ps->dpy, fbconfig, NULL, GL_TRUE, attrib_list);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -145,8 +142,8 @@ glx_init(session_t *ps, bool need_render) {
|
|||
#ifdef DEBUG_GLX_DEBUG_CONTEXT
|
||||
{
|
||||
f_DebugMessageCallback p_DebugMessageCallback =
|
||||
(f_DebugMessageCallback)
|
||||
glXGetProcAddress((const GLubyte *) "glDebugMessageCallback");
|
||||
(f_DebugMessageCallback)glXGetProcAddress(
|
||||
(const GLubyte *)"glDebugMessageCallback");
|
||||
if (!p_DebugMessageCallback) {
|
||||
log_error("Failed to get glDebugMessageCallback(0.");
|
||||
goto glx_init_end;
|
||||
|
@ -154,7 +151,6 @@ glx_init(session_t *ps, bool need_render) {
|
|||
p_DebugMessageCallback(glx_debug_msg_callback, ps);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
// Ensure we have a stencil buffer. X Fixes does not guarantee rectangles
|
||||
|
@ -172,8 +168,8 @@ glx_init(session_t *ps, bool need_render) {
|
|||
// Check GL_ARB_texture_non_power_of_two, requires a GLX context and
|
||||
// must precede FBConfig fetching
|
||||
if (need_render)
|
||||
psglx->has_texture_non_power_of_two = gl_has_extension(
|
||||
"GL_ARB_texture_non_power_of_two");
|
||||
psglx->has_texture_non_power_of_two =
|
||||
gl_has_extension("GL_ARB_texture_non_power_of_two");
|
||||
|
||||
// Render preparations
|
||||
if (need_render) {
|
||||
|
@ -209,8 +205,7 @@ glx_init_end:
|
|||
return success;
|
||||
}
|
||||
|
||||
static void
|
||||
glx_free_prog_main(session_t *ps, glx_prog_main_t *pprogram) {
|
||||
static void glx_free_prog_main(session_t *ps, glx_prog_main_t *pprogram) {
|
||||
if (!pprogram)
|
||||
return;
|
||||
if (pprogram->prog) {
|
||||
|
@ -225,8 +220,7 @@ glx_free_prog_main(session_t *ps, glx_prog_main_t *pprogram) {
|
|||
/**
|
||||
* Destroy GLX related resources.
|
||||
*/
|
||||
void
|
||||
glx_destroy(session_t *ps) {
|
||||
void glx_destroy(session_t *ps) {
|
||||
if (!ps->psglx)
|
||||
return;
|
||||
|
||||
|
@ -260,8 +254,7 @@ glx_destroy(session_t *ps) {
|
|||
/**
|
||||
* Callback to run on root window size change.
|
||||
*/
|
||||
void
|
||||
glx_on_root_change(session_t *ps) {
|
||||
void glx_on_root_change(session_t *ps) {
|
||||
glViewport(0, 0, ps->root_width, ps->root_height);
|
||||
|
||||
// Initialize matrix, copied from dcompmgr
|
||||
|
@ -275,8 +268,7 @@ glx_on_root_change(session_t *ps) {
|
|||
/**
|
||||
* Initialize GLX blur filter.
|
||||
*/
|
||||
bool
|
||||
glx_init_blur(session_t *ps) {
|
||||
bool glx_init_blur(session_t *ps) {
|
||||
assert(ps->o.blur_kerns[0]);
|
||||
|
||||
// Allocate PBO if more than one blur kernel is present
|
||||
|
@ -285,7 +277,8 @@ glx_init_blur(session_t *ps) {
|
|||
GLuint fbo = 0;
|
||||
glGenFramebuffers(1, &fbo);
|
||||
if (!fbo) {
|
||||
log_error("Failed to generate Framebuffer. Cannot do multi-pass blur with GLX"
|
||||
log_error("Failed to generate Framebuffer. Cannot do multi-pass "
|
||||
"blur with GLX"
|
||||
" backend.");
|
||||
return false;
|
||||
}
|
||||
|
@ -309,21 +302,22 @@ glx_init_blur(session_t *ps) {
|
|||
"void main() {\n"
|
||||
" vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);\n";
|
||||
static const char *FRAG_SHADER_BLUR_ADD =
|
||||
" sum += float(%.7g) * %s(tex_scr, vec2(gl_TexCoord[0].x + offset_x * float(%d), gl_TexCoord[0].y + offset_y * float(%d)));\n";
|
||||
" sum += float(%.7g) * %s(tex_scr, vec2(gl_TexCoord[0].x + offset_x "
|
||||
"* float(%d), gl_TexCoord[0].y + offset_y * float(%d)));\n";
|
||||
static const char *FRAG_SHADER_BLUR_SUFFIX =
|
||||
" sum += %s(tex_scr, vec2(gl_TexCoord[0].x, gl_TexCoord[0].y)) * factor_center;\n"
|
||||
" sum += %s(tex_scr, vec2(gl_TexCoord[0].x, gl_TexCoord[0].y)) * "
|
||||
"factor_center;\n"
|
||||
" gl_FragColor = sum / (factor_center + float(%.7g));\n"
|
||||
"}\n";
|
||||
|
||||
const bool use_texture_rect = !ps->psglx->has_texture_non_power_of_two;
|
||||
const char *sampler_type = (use_texture_rect ?
|
||||
"sampler2DRect": "sampler2D");
|
||||
const char *texture_func = (use_texture_rect ?
|
||||
"texture2DRect": "texture2D");
|
||||
const char *sampler_type = (use_texture_rect ? "sampler2DRect" : "sampler2D");
|
||||
const char *texture_func = (use_texture_rect ? "texture2DRect" : "texture2D");
|
||||
const char *shader_add = FRAG_SHADER_BLUR_ADD;
|
||||
char *extension = NULL;
|
||||
if (use_texture_rect) {
|
||||
mstrextend(&extension, "#extension GL_ARB_texture_rectangle : require\n");
|
||||
mstrextend(&extension, "#extension GL_ARB_texture_rectangle : "
|
||||
"require\n");
|
||||
}
|
||||
if (!extension) {
|
||||
extension = strdup("");
|
||||
|
@ -337,9 +331,9 @@ glx_init_blur(session_t *ps) {
|
|||
{
|
||||
int width = kern->w, height = kern->h;
|
||||
int nele = width * height - 1;
|
||||
unsigned int len = strlen(FRAG_SHADER_BLUR_PREFIX) +
|
||||
strlen(sampler_type) +
|
||||
strlen(extension) +
|
||||
unsigned int len =
|
||||
strlen(FRAG_SHADER_BLUR_PREFIX) +
|
||||
strlen(sampler_type) + strlen(extension) +
|
||||
(strlen(shader_add) + strlen(texture_func) + 42) * nele +
|
||||
strlen(FRAG_SHADER_BLUR_SUFFIX) +
|
||||
strlen(texture_func) + 12 + 1;
|
||||
|
@ -359,7 +353,8 @@ glx_init_blur(session_t *ps) {
|
|||
continue;
|
||||
}
|
||||
sum += val;
|
||||
sprintf(pc, shader_add, val, texture_func, k - width / 2, j - height / 2);
|
||||
sprintf(pc, shader_add, val, texture_func,
|
||||
k - width / 2, j - height / 2);
|
||||
pc += strlen(pc);
|
||||
assert(strlen(shader_str) < len);
|
||||
}
|
||||
|
@ -367,7 +362,8 @@ glx_init_blur(session_t *ps) {
|
|||
|
||||
sprintf(pc, FRAG_SHADER_BLUR_SUFFIX, texture_func, sum);
|
||||
assert(strlen(shader_str) < len);
|
||||
ppass->frag_shader = gl_create_shader(GL_FRAGMENT_SHADER, shader_str);
|
||||
ppass->frag_shader =
|
||||
gl_create_shader(GL_FRAGMENT_SHADER, shader_str);
|
||||
free(shader_str);
|
||||
}
|
||||
|
||||
|
@ -388,10 +384,13 @@ glx_init_blur(session_t *ps) {
|
|||
}
|
||||
|
||||
// Get uniform addresses
|
||||
#define P_GET_UNIFM_LOC(name, target) { \
|
||||
#define P_GET_UNIFM_LOC(name, target) \
|
||||
{ \
|
||||
ppass->target = glGetUniformLocation(ppass->prog, name); \
|
||||
if (ppass->target < 0) { \
|
||||
log_error("Failed to get location of %d-th uniform '" name "'. Might be troublesome.", i); \
|
||||
log_error("Failed to get location of %d-th uniform '" name \
|
||||
"'. Might be troublesome.", \
|
||||
i); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
@ -408,7 +407,6 @@ glx_init_blur(session_t *ps) {
|
|||
free(lc_numeric_old);
|
||||
}
|
||||
|
||||
|
||||
gl_check_err();
|
||||
|
||||
return true;
|
||||
|
@ -417,9 +415,7 @@ glx_init_blur(session_t *ps) {
|
|||
/**
|
||||
* Load a GLSL main program from shader strings.
|
||||
*/
|
||||
bool
|
||||
glx_load_prog_main(session_t *ps,
|
||||
const char *vshader_str, const char *fshader_str,
|
||||
bool glx_load_prog_main(session_t *ps, const char *vshader_str, const char *fshader_str,
|
||||
glx_prog_main_t *pprogram) {
|
||||
assert(pprogram);
|
||||
|
||||
|
@ -431,10 +427,12 @@ glx_load_prog_main(session_t *ps,
|
|||
}
|
||||
|
||||
// Get uniform addresses
|
||||
#define P_GET_UNIFM_LOC(name, target) { \
|
||||
#define P_GET_UNIFM_LOC(name, target) \
|
||||
{ \
|
||||
pprogram->target = glGetUniformLocation(pprogram->prog, name); \
|
||||
if (pprogram->target < 0) { \
|
||||
log_error("Failed to get location of uniform '" name "'. Might be troublesome."); \
|
||||
log_error("Failed to get location of uniform '" name \
|
||||
"'. Might be troublesome."); \
|
||||
} \
|
||||
}
|
||||
P_GET_UNIFM_LOC("opacity", unifm_opacity);
|
||||
|
@ -450,9 +448,8 @@ glx_load_prog_main(session_t *ps,
|
|||
/**
|
||||
* Bind a X pixmap to an OpenGL texture.
|
||||
*/
|
||||
bool
|
||||
glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
|
||||
unsigned width, unsigned height, bool repeat, const struct glx_fbconfig_info *fbcfg) {
|
||||
bool glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap, unsigned width,
|
||||
unsigned height, bool repeat, const struct glx_fbconfig_info *fbcfg) {
|
||||
if (ps->o.backend != BKEND_GLX && ps->o.backend != BKEND_XR_GLX_HYBRID)
|
||||
return true;
|
||||
|
||||
|
@ -497,8 +494,8 @@ glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
|
|||
Window rroot = None;
|
||||
int rx = 0, ry = 0;
|
||||
unsigned rbdwid = 0;
|
||||
if (!XGetGeometry(ps->dpy, pixmap, &rroot, &rx, &ry,
|
||||
&width, &height, &rbdwid, &depth)) {
|
||||
if (!XGetGeometry(ps->dpy, pixmap, &rroot, &rx, &ry, &width,
|
||||
&height, &rbdwid, &depth)) {
|
||||
log_error("Failed to query info of pixmap %#010x.", pixmap);
|
||||
return false;
|
||||
}
|
||||
|
@ -513,8 +510,8 @@ glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
|
|||
// The assumption we made here is the target never changes based on any
|
||||
// pixmap-specific parameters, and this may change in the future
|
||||
GLenum tex_tgt = 0;
|
||||
if (GLX_TEXTURE_2D_BIT_EXT & fbcfg->texture_tgts
|
||||
&& ps->psglx->has_texture_non_power_of_two)
|
||||
if (GLX_TEXTURE_2D_BIT_EXT & fbcfg->texture_tgts &&
|
||||
ps->psglx->has_texture_non_power_of_two)
|
||||
tex_tgt = GLX_TEXTURE_2D_EXT;
|
||||
else if (GLX_TEXTURE_RECTANGLE_BIT_EXT & fbcfg->texture_tgts)
|
||||
tex_tgt = GLX_TEXTURE_RECTANGLE_EXT;
|
||||
|
@ -536,8 +533,8 @@ glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
|
|||
|
||||
ptex->glpixmap = glXCreatePixmap(ps->dpy, fbcfg->cfg, pixmap, attrs);
|
||||
ptex->pixmap = pixmap;
|
||||
ptex->target = (GLX_TEXTURE_2D_EXT == tex_tgt ? GL_TEXTURE_2D:
|
||||
GL_TEXTURE_RECTANGLE);
|
||||
ptex->target =
|
||||
(GLX_TEXTURE_2D_EXT == tex_tgt ? GL_TEXTURE_2D : GL_TEXTURE_RECTANGLE);
|
||||
ptex->width = width;
|
||||
ptex->height = height;
|
||||
ptex->y_inverted = fbcfg->y_inverted;
|
||||
|
@ -597,8 +594,7 @@ glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
|
|||
/**
|
||||
* @brief Release binding of a texture.
|
||||
*/
|
||||
void
|
||||
glx_release_pixmap(session_t *ps, glx_texture_t *ptex) {
|
||||
void glx_release_pixmap(session_t *ps, glx_texture_t *ptex) {
|
||||
// Release binding
|
||||
if (ptex->glpixmap && ptex->texture) {
|
||||
glBindTexture(ptex->target, ptex->texture);
|
||||
|
@ -618,8 +614,7 @@ glx_release_pixmap(session_t *ps, glx_texture_t *ptex) {
|
|||
/**
|
||||
* Set clipping region on the target window.
|
||||
*/
|
||||
void
|
||||
glx_set_clip(session_t *ps, const region_t *reg) {
|
||||
void glx_set_clip(session_t *ps, const region_t *reg) {
|
||||
// Quit if we aren't using stencils
|
||||
if (ps->o.glx_no_stencil)
|
||||
return;
|
||||
|
@ -635,8 +630,8 @@ glx_set_clip(session_t *ps, const region_t *reg) {
|
|||
|
||||
if (nrects == 1) {
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(rects[0].x1, ps->root_height-rects[0].y2,
|
||||
rects[0].x2-rects[0].x1, rects[0].y2-rects[0].y1);
|
||||
glScissor(rects[0].x1, ps->root_height - rects[0].y2,
|
||||
rects[0].x2 - rects[0].x1, rects[0].y2 - rects[0].y1);
|
||||
}
|
||||
|
||||
gl_check_err();
|
||||
|
@ -660,30 +655,28 @@ glx_set_clip(session_t *ps, const region_t *reg) {
|
|||
\
|
||||
pixman_region32_fini(®_new);
|
||||
|
||||
static inline GLuint
|
||||
glx_gen_texture(session_t *ps, GLenum tex_tgt, int width, int height) {
|
||||
static inline GLuint glx_gen_texture(session_t *ps, GLenum tex_tgt, int width, int height) {
|
||||
GLuint tex = 0;
|
||||
glGenTextures(1, &tex);
|
||||
if (!tex) return 0;
|
||||
if (!tex)
|
||||
return 0;
|
||||
glEnable(tex_tgt);
|
||||
glBindTexture(tex_tgt, tex);
|
||||
glTexParameteri(tex_tgt, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(tex_tgt, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(tex_tgt, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(tex_tgt, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(tex_tgt, 0, GL_RGB, width, height, 0, GL_RGB,
|
||||
GL_UNSIGNED_BYTE, NULL);
|
||||
glTexImage2D(tex_tgt, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||
glBindTexture(tex_tgt, 0);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
static inline void
|
||||
glx_copy_region_to_tex(session_t *ps, GLenum tex_tgt, int basex, int basey,
|
||||
int dx, int dy, int width, int height) {
|
||||
static inline void glx_copy_region_to_tex(session_t *ps, GLenum tex_tgt, int basex,
|
||||
int basey, int dx, int dy, int width, int height) {
|
||||
if (width > 0 && height > 0)
|
||||
glCopyTexSubImage2D(tex_tgt, 0, dx - basex, dy - basey,
|
||||
dx, ps->root_height - dy - height, width, height);
|
||||
glCopyTexSubImage2D(tex_tgt, 0, dx - basex, dy - basey, dx,
|
||||
ps->root_height - dy - height, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -691,11 +684,8 @@ glx_copy_region_to_tex(session_t *ps, GLenum tex_tgt, int basex, int basey,
|
|||
*
|
||||
* XXX seems to be way to complex for what it does
|
||||
*/
|
||||
bool
|
||||
glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
||||
GLfloat factor_center,
|
||||
const region_t *reg_tgt,
|
||||
glx_blur_cache_t *pbc) {
|
||||
bool glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
||||
GLfloat factor_center, const region_t *reg_tgt, glx_blur_cache_t *pbc) {
|
||||
assert(ps->psglx->blur_passes[0].prog);
|
||||
const bool more_passes = ps->psglx->blur_passes[1].prog;
|
||||
const bool have_scissors = glIsEnabled(GL_SCISSOR_TEST);
|
||||
|
@ -703,12 +693,12 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
|||
bool ret = false;
|
||||
|
||||
// Calculate copy region size
|
||||
glx_blur_cache_t ibc = { .width = 0, .height = 0 };
|
||||
glx_blur_cache_t ibc = {.width = 0, .height = 0};
|
||||
if (!pbc)
|
||||
pbc = &ibc;
|
||||
|
||||
int mdx = dx, mdy = dy, mwidth = width, mheight = height;
|
||||
//log_trace("%d, %d, %d, %d", mdx, mdy, mwidth, mheight);
|
||||
// log_trace("%d, %d, %d, %d", mdx, mdy, mwidth, mheight);
|
||||
|
||||
/*
|
||||
if (ps->o.resize_damage > 0) {
|
||||
|
@ -804,13 +794,11 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
|||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D, tex_scr2, 0);
|
||||
glDrawBuffer(GL_COLOR_ATTACHMENT0);
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER)
|
||||
!= GL_FRAMEBUFFER_COMPLETE) {
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
log_error("Framebuffer attachment failed.");
|
||||
goto glx_blur_dst_end;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glDrawBuffer(GL_BACK);
|
||||
if (have_scissors)
|
||||
|
@ -848,7 +836,8 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
|||
GLfloat rdxe = rdx + (crect.x2 - crect.x1);
|
||||
GLfloat rdye = rdy - (crect.y2 - crect.y1);
|
||||
|
||||
//log_trace("%f, %f, %f, %f -> %f, %f, %f, %f", rx, ry, rxe, rye, rdx,
|
||||
// log_trace("%f, %f, %f, %f -> %f, %f, %f, %f", rx, ry,
|
||||
// rxe, rye, rdx,
|
||||
// rdy, rdxe, rdye);
|
||||
|
||||
glTexCoord2f(rx, ry);
|
||||
|
@ -862,7 +851,8 @@ glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
|||
|
||||
glTexCoord2f(rx, rye);
|
||||
glVertex3f(rdx, rdye, z);
|
||||
} P_PAINTREG_END();
|
||||
}
|
||||
P_PAINTREG_END();
|
||||
}
|
||||
|
||||
glUseProgram(0);
|
||||
|
@ -895,8 +885,7 @@ glx_blur_dst_end:
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
||||
bool glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
||||
GLfloat factor, const region_t *reg_tgt) {
|
||||
// It's possible to dim in glx_render(), but it would be over-complicated
|
||||
// considering all those mess in color negation and modulation
|
||||
|
@ -931,12 +920,9 @@ glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
|||
/**
|
||||
* @brief Render a region with texture data.
|
||||
*/
|
||||
bool
|
||||
glx_render(session_t *ps, const glx_texture_t *ptex,
|
||||
int x, int y, int dx, int dy, int width, int height, int z,
|
||||
double opacity, bool argb, bool neg,
|
||||
const region_t *reg_tgt, const glx_prog_main_t *pprogram
|
||||
) {
|
||||
bool glx_render(session_t *ps, const glx_texture_t *ptex, int x, int y, int dx, int dy,
|
||||
int width, int height, int z, double opacity, bool argb, bool neg,
|
||||
const region_t *reg_tgt, const glx_prog_main_t *pprogram) {
|
||||
if (!ptex || !ptex->texture) {
|
||||
log_error("Missing texture.");
|
||||
return false;
|
||||
|
@ -963,8 +949,7 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
|
|||
glColor4f(opacity, opacity, opacity, opacity);
|
||||
}
|
||||
|
||||
if (!has_prog)
|
||||
{
|
||||
if (!has_prog) {
|
||||
// The default, fixed-function path
|
||||
// Color negation
|
||||
if (neg) {
|
||||
|
@ -977,9 +962,9 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
|
|||
else if (argb) {
|
||||
dual_texture = true;
|
||||
|
||||
// Use two texture stages because the calculation is too complicated,
|
||||
// thanks to madsy for providing code
|
||||
// Texture stage 0
|
||||
// Use two texture stages because the calculation is too
|
||||
// complicated, thanks to madsy for providing code Texture
|
||||
// stage 0
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
// Negation for premultiplied color: color = A - C
|
||||
|
@ -1025,7 +1010,8 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
|
|||
// Modulation with constant factor
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB,
|
||||
GL_ONE_MINUS_SRC_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
|
||||
|
||||
|
@ -1037,8 +1023,7 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
|
|||
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Programmable path
|
||||
assert(pprogram->prog);
|
||||
glUseProgram(pprogram->prog);
|
||||
|
@ -1050,7 +1035,7 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
|
|||
glUniform1i(pprogram->unifm_tex, 0);
|
||||
}
|
||||
|
||||
//log_trace("Draw: %d, %d, %d, %d -> %d, %d (%d, %d) z %d", x, y, width, height,
|
||||
// log_trace("Draw: %d, %d, %d, %d -> %d, %d (%d, %d) z %d", x, y, width, height,
|
||||
// dx, dy, ptex->width, ptex->height, z);
|
||||
|
||||
// Bind texture
|
||||
|
@ -1065,12 +1050,12 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
|
|||
{
|
||||
P_PAINTREG_START(crect) {
|
||||
// XXX explain these variables
|
||||
GLfloat rx = (double) (crect.x1 - dx + x);
|
||||
GLfloat ry = (double) (crect.y1 - dy + y);
|
||||
GLfloat rxe = rx + (double) (crect.x2 - crect.x1);
|
||||
GLfloat rye = ry + (double) (crect.y2 - crect.y1);
|
||||
// Rectangle textures have [0-w] [0-h] while 2D texture has [0-1] [0-1]
|
||||
// Thanks to amonakov for pointing out!
|
||||
GLfloat rx = (double)(crect.x1 - dx + x);
|
||||
GLfloat ry = (double)(crect.y1 - dy + y);
|
||||
GLfloat rxe = rx + (double)(crect.x2 - crect.x1);
|
||||
GLfloat rye = ry + (double)(crect.y2 - crect.y1);
|
||||
// Rectangle textures have [0-w] [0-h] while 2D texture has [0-1]
|
||||
// [0-1] Thanks to amonakov for pointing out!
|
||||
if (GL_TEXTURE_2D == ptex->target) {
|
||||
rx = rx / ptex->width;
|
||||
ry = ry / ptex->height;
|
||||
|
@ -1082,23 +1067,25 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
|
|||
GLint rdxe = rdx + (crect.x2 - crect.x1);
|
||||
GLint rdye = rdy - (crect.y2 - crect.y1);
|
||||
|
||||
// Invert Y if needed, this may not work as expected, though. I don't
|
||||
// have such a FBConfig to test with.
|
||||
// Invert Y if needed, this may not work as expected, though. I
|
||||
// don't have such a FBConfig to test with.
|
||||
if (!ptex->y_inverted) {
|
||||
ry = 1.0 - ry;
|
||||
rye = 1.0 - rye;
|
||||
}
|
||||
|
||||
//log_trace("Rect %d: %f, %f, %f, %f -> %d, %d, %d, %d", ri, rx, ry, rxe, rye,
|
||||
// log_trace("Rect %d: %f, %f, %f, %f -> %d, %d, %d, %d", ri, rx,
|
||||
// ry, rxe, rye,
|
||||
// rdx, rdy, rdxe, rdye);
|
||||
|
||||
#define P_TEXCOORD(cx, cy) { \
|
||||
#define P_TEXCOORD(cx, cy) \
|
||||
{ \
|
||||
if (dual_texture) { \
|
||||
glMultiTexCoord2f(GL_TEXTURE0, cx, cy); \
|
||||
glMultiTexCoord2f(GL_TEXTURE1, cx, cy); \
|
||||
} \
|
||||
else glTexCoord2f(cx, cy); \
|
||||
}
|
||||
} else \
|
||||
glTexCoord2f(cx, cy); \
|
||||
}
|
||||
P_TEXCOORD(rx, ry);
|
||||
glVertex3i(rdx, rdy, z);
|
||||
|
||||
|
@ -1110,7 +1097,8 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
|
|||
|
||||
P_TEXCOORD(rx, rye);
|
||||
glVertex3i(rdx, rdye, z);
|
||||
} P_PAINTREG_END();
|
||||
}
|
||||
P_PAINTREG_END();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
|
|
109
src/opengl.h
109
src/opengl.h
|
@ -12,104 +12,78 @@
|
|||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
#include "compiler.h"
|
||||
#include "log.h"
|
||||
#include "region.h"
|
||||
#include "render.h"
|
||||
#include "compiler.h"
|
||||
#include "win.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/render.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <GL/gl.h>
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <GL/gl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
bool
|
||||
glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
||||
bool glx_dim_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
||||
GLfloat factor, const region_t *reg_tgt);
|
||||
|
||||
bool
|
||||
glx_render(session_t *ps, const glx_texture_t *ptex,
|
||||
int x, int y, int dx, int dy, int width, int height, int z,
|
||||
double opacity, bool argb, bool neg,
|
||||
const region_t *reg_tgt,
|
||||
const glx_prog_main_t *pprogram);
|
||||
bool glx_render(session_t *ps, const glx_texture_t *ptex, int x, int y, int dx, int dy,
|
||||
int width, int height, int z, double opacity, bool argb, bool neg,
|
||||
const region_t *reg_tgt, const glx_prog_main_t *pprogram);
|
||||
|
||||
bool
|
||||
glx_init(session_t *ps, bool need_render);
|
||||
bool glx_init(session_t *ps, bool need_render);
|
||||
|
||||
void
|
||||
glx_destroy(session_t *ps);
|
||||
void glx_destroy(session_t *ps);
|
||||
|
||||
void
|
||||
glx_on_root_change(session_t *ps);
|
||||
void glx_on_root_change(session_t *ps);
|
||||
|
||||
bool
|
||||
glx_init_blur(session_t *ps);
|
||||
bool glx_init_blur(session_t *ps);
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
bool
|
||||
glx_load_prog_main(session_t *ps,
|
||||
const char *vshader_str, const char *fshader_str,
|
||||
bool glx_load_prog_main(session_t *ps, const char *vshader_str, const char *fshader_str,
|
||||
glx_prog_main_t *pprogram);
|
||||
#endif
|
||||
|
||||
bool
|
||||
glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap,
|
||||
unsigned width, unsigned height, bool repeat, const struct glx_fbconfig_info *);
|
||||
bool glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap, unsigned width,
|
||||
unsigned height, bool repeat, const struct glx_fbconfig_info *);
|
||||
|
||||
void
|
||||
glx_release_pixmap(session_t *ps, glx_texture_t *ptex);
|
||||
void glx_release_pixmap(session_t *ps, glx_texture_t *ptex);
|
||||
|
||||
void glx_paint_pre(session_t *ps, region_t *preg)
|
||||
attr_nonnull(1, 2);
|
||||
void glx_paint_pre(session_t *ps, region_t *preg) attr_nonnull(1, 2);
|
||||
|
||||
/**
|
||||
* Check if a texture is binded, or is binded to the given pixmap.
|
||||
*/
|
||||
static inline bool
|
||||
glx_tex_binded(const glx_texture_t *ptex, xcb_pixmap_t pixmap) {
|
||||
return ptex && ptex->glpixmap && ptex->texture
|
||||
&& (!pixmap || pixmap == ptex->pixmap);
|
||||
static inline bool glx_tex_binded(const glx_texture_t *ptex, xcb_pixmap_t pixmap) {
|
||||
return ptex && ptex->glpixmap && ptex->texture && (!pixmap || pixmap == ptex->pixmap);
|
||||
}
|
||||
|
||||
void
|
||||
glx_set_clip(session_t *ps, const region_t *reg);
|
||||
void glx_set_clip(session_t *ps, const region_t *reg);
|
||||
|
||||
bool
|
||||
glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
||||
GLfloat factor_center,
|
||||
const region_t *reg_tgt,
|
||||
glx_blur_cache_t *pbc);
|
||||
bool glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,
|
||||
GLfloat factor_center, const region_t *reg_tgt, glx_blur_cache_t *pbc);
|
||||
|
||||
GLuint
|
||||
glx_create_shader(GLenum shader_type, const char *shader_str);
|
||||
GLuint glx_create_shader(GLenum shader_type, const char *shader_str);
|
||||
|
||||
GLuint
|
||||
glx_create_program(const GLuint * const shaders, int nshaders);
|
||||
GLuint glx_create_program(const GLuint *const shaders, int nshaders);
|
||||
|
||||
GLuint
|
||||
glx_create_program_from_str(const char *vert_shader_str,
|
||||
const char *frag_shader_str);
|
||||
GLuint glx_create_program_from_str(const char *vert_shader_str, const char *frag_shader_str);
|
||||
|
||||
unsigned char *
|
||||
glx_take_screenshot(session_t *ps, int *out_length);
|
||||
unsigned char *glx_take_screenshot(session_t *ps, int *out_length);
|
||||
|
||||
/**
|
||||
* Check if there's a GLX context.
|
||||
*/
|
||||
static inline bool
|
||||
glx_has_context(session_t *ps) {
|
||||
static inline bool glx_has_context(session_t *ps) {
|
||||
return ps->psglx && ps->psglx->context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure we have a GLX context.
|
||||
*/
|
||||
static inline bool
|
||||
ensure_glx_context(session_t *ps) {
|
||||
static inline bool ensure_glx_context(session_t *ps) {
|
||||
// Create GLX context
|
||||
if (!glx_has_context(ps))
|
||||
glx_init(ps, false);
|
||||
|
@ -120,8 +94,7 @@ ensure_glx_context(session_t *ps) {
|
|||
/**
|
||||
* Free a GLX texture.
|
||||
*/
|
||||
static inline void
|
||||
free_texture_r(session_t *ps, GLuint *ptexture) {
|
||||
static inline void free_texture_r(session_t *ps, GLuint *ptexture) {
|
||||
if (*ptexture) {
|
||||
assert(glx_has_context(ps));
|
||||
glDeleteTextures(1, ptexture);
|
||||
|
@ -132,8 +105,7 @@ free_texture_r(session_t *ps, GLuint *ptexture) {
|
|||
/**
|
||||
* Free a GLX Framebuffer object.
|
||||
*/
|
||||
static inline void
|
||||
free_glx_fbo(session_t *ps, GLuint *pfbo) {
|
||||
static inline void free_glx_fbo(session_t *ps, GLuint *pfbo) {
|
||||
if (*pfbo) {
|
||||
glDeleteFramebuffers(1, pfbo);
|
||||
*pfbo = 0;
|
||||
|
@ -144,8 +116,7 @@ free_glx_fbo(session_t *ps, GLuint *pfbo) {
|
|||
/**
|
||||
* Free data in glx_blur_cache_t on resize.
|
||||
*/
|
||||
static inline void
|
||||
free_glx_bc_resize(session_t *ps, glx_blur_cache_t *pbc) {
|
||||
static inline void free_glx_bc_resize(session_t *ps, glx_blur_cache_t *pbc) {
|
||||
free_texture_r(ps, &pbc->textures[0]);
|
||||
free_texture_r(ps, &pbc->textures[1]);
|
||||
pbc->width = 0;
|
||||
|
@ -155,8 +126,7 @@ free_glx_bc_resize(session_t *ps, glx_blur_cache_t *pbc) {
|
|||
/**
|
||||
* Free a glx_blur_cache_t
|
||||
*/
|
||||
static inline void
|
||||
free_glx_bc(session_t *ps, glx_blur_cache_t *pbc) {
|
||||
static inline void free_glx_bc(session_t *ps, glx_blur_cache_t *pbc) {
|
||||
free_glx_fbo(ps, &pbc->fbo);
|
||||
free_glx_bc_resize(ps, pbc);
|
||||
}
|
||||
|
@ -164,8 +134,7 @@ free_glx_bc(session_t *ps, glx_blur_cache_t *pbc) {
|
|||
/**
|
||||
* Free a glx_texture_t.
|
||||
*/
|
||||
static inline void
|
||||
free_texture(session_t *ps, glx_texture_t **pptex) {
|
||||
static inline void free_texture(session_t *ps, glx_texture_t **pptex) {
|
||||
glx_texture_t *ptex = *pptex;
|
||||
|
||||
// Quit if there's nothing
|
||||
|
@ -185,16 +154,14 @@ free_texture(session_t *ps, glx_texture_t **pptex) {
|
|||
/**
|
||||
* Free GLX part of paint_t.
|
||||
*/
|
||||
static inline void
|
||||
free_paint_glx(session_t *ps, paint_t *ppaint) {
|
||||
static inline void free_paint_glx(session_t *ps, paint_t *ppaint) {
|
||||
free_texture(ps, &ppaint->ptex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free GLX part of win.
|
||||
*/
|
||||
static inline void
|
||||
free_win_res_glx(session_t *ps, win *w) {
|
||||
static inline void free_win_res_glx(session_t *ps, win *w) {
|
||||
free_paint_glx(ps, &w->paint);
|
||||
free_paint_glx(ps, &w->shadow_paint);
|
||||
#ifdef CONFIG_OPENGL
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
#define mstrncmp(s1, s2) strncmp((s1), (s2), strlen(s1))
|
||||
|
||||
char *mstrjoin(const char *src1, const char *src2);
|
||||
char *
|
||||
mstrjoin3(const char *src1, const char *src2, const char *src3);
|
||||
char *mstrjoin3(const char *src1, const char *src2, const char *src3);
|
||||
void mstrextend(char **psrc1, const char *src2);
|
||||
|
||||
/// Parse a floating point number of form (+|-)?[0-9]*(\.[0-9]*)
|
||||
|
@ -27,14 +26,13 @@ static inline int uitostr(unsigned int n, char *buf) {
|
|||
|
||||
int pos = ret;
|
||||
while (pos--) {
|
||||
buf[pos] = n%10 + '0';
|
||||
buf[pos] = n % 10 + '0';
|
||||
n /= 10;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline const char *
|
||||
skip_space_const(const char *src) {
|
||||
static inline const char *skip_space_const(const char *src) {
|
||||
if (!src)
|
||||
return NULL;
|
||||
while (*src && isspace(*src))
|
||||
|
@ -42,8 +40,7 @@ skip_space_const(const char *src) {
|
|||
return src;
|
||||
}
|
||||
|
||||
static inline char *
|
||||
skip_space_mut(char *src) {
|
||||
static inline char *skip_space_mut(char *src) {
|
||||
if (!src)
|
||||
return NULL;
|
||||
while (*src && isspace(*src))
|
||||
|
@ -51,7 +48,5 @@ skip_space_mut(char *src) {
|
|||
return src;
|
||||
}
|
||||
|
||||
#define skip_space(x) _Generic((x), \
|
||||
char *: skip_space_mut, \
|
||||
const char *: skip_space_const \
|
||||
)(x)
|
||||
#define skip_space(x) \
|
||||
_Generic((x), char * : skip_space_mut, const char * : skip_space_const)(x)
|
||||
|
|
|
@ -32,4 +32,5 @@ typedef struct {
|
|||
|
||||
typedef uint32_t opacity_t;
|
||||
|
||||
#define MARGIN_INIT { 0, 0, 0, 0 }
|
||||
#define MARGIN_INIT \
|
||||
{ 0, 0, 0, 0 }
|
||||
|
|
76
src/vsync.c
76
src/vsync.c
|
@ -12,12 +12,12 @@
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_VSYNC_DRM
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <drm.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
|
@ -27,15 +27,14 @@
|
|||
/**
|
||||
* Wait for next VSync, DRM method.
|
||||
*
|
||||
* Stolen from: https://github.com/MythTV/mythtv/blob/master/mythtv/libs/libmythtv/vsync.cpp
|
||||
* Stolen from:
|
||||
* https://github.com/MythTV/mythtv/blob/master/mythtv/libs/libmythtv/vsync.cpp
|
||||
*/
|
||||
static int
|
||||
vsync_drm_wait(session_t *ps) {
|
||||
static int vsync_drm_wait(session_t *ps) {
|
||||
int ret = -1;
|
||||
drm_wait_vblank_t vbl;
|
||||
|
||||
vbl.request.type = _DRM_VBLANK_RELATIVE,
|
||||
vbl.request.sequence = 1;
|
||||
vbl.request.type = _DRM_VBLANK_RELATIVE, vbl.request.sequence = 1;
|
||||
|
||||
do {
|
||||
ret = ioctl(ps->drm_fd, DRM_IOCTL_WAIT_VBLANK, &vbl);
|
||||
|
@ -46,7 +45,6 @@ vsync_drm_wait(session_t *ps) {
|
|||
log_error("VBlank ioctl did not work, unimplemented in this drmver?");
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -55,8 +53,7 @@ vsync_drm_wait(session_t *ps) {
|
|||
*
|
||||
* @return true for success, false otherwise
|
||||
*/
|
||||
static bool
|
||||
vsync_drm_init(session_t *ps) {
|
||||
static bool vsync_drm_init(session_t *ps) {
|
||||
#ifdef CONFIG_VSYNC_DRM
|
||||
// Should we always open card0?
|
||||
if (ps->drm_fd < 0 && (ps->drm_fd = open("/dev/dri/card0", O_RDWR)) < 0) {
|
||||
|
@ -77,13 +74,13 @@ vsync_drm_init(session_t *ps) {
|
|||
/**
|
||||
* Initialize OpenGL VSync.
|
||||
*
|
||||
* Stolen from: http://git.tuxfamily.org/?p=ccm/cairocompmgr.git;a=commitdiff;h=efa4ceb97da501e8630ca7f12c99b1dce853c73e
|
||||
* Stolen from:
|
||||
* http://git.tuxfamily.org/?p=ccm/cairocompmgr.git;a=commitdiff;h=efa4ceb97da501e8630ca7f12c99b1dce853c73e
|
||||
* Possible original source: http://www.inb.uni-luebeck.de/~boehme/xvideo_sync.html
|
||||
*
|
||||
* @return true for success, false otherwise
|
||||
*/
|
||||
static bool
|
||||
vsync_opengl_init(session_t *ps) {
|
||||
static bool vsync_opengl_init(session_t *ps) {
|
||||
#ifdef CONFIG_OPENGL
|
||||
if (!ensure_glx_context(ps))
|
||||
return false;
|
||||
|
@ -95,8 +92,7 @@ vsync_opengl_init(session_t *ps) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
vsync_opengl_oml_init(session_t *ps) {
|
||||
static bool vsync_opengl_oml_init(session_t *ps) {
|
||||
#ifdef CONFIG_OPENGL
|
||||
if (!ensure_glx_context(ps))
|
||||
return false;
|
||||
|
@ -109,8 +105,7 @@ vsync_opengl_oml_init(session_t *ps) {
|
|||
}
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
static inline bool
|
||||
vsync_opengl_swc_swap_interval(session_t *ps, unsigned int interval) {
|
||||
static inline bool vsync_opengl_swc_swap_interval(session_t *ps, unsigned int interval) {
|
||||
if (glxext.has_GLX_MESA_swap_control)
|
||||
return glXSwapIntervalMESA(interval) == 0;
|
||||
else if (glxext.has_GLX_SGI_swap_control)
|
||||
|
@ -128,8 +123,7 @@ vsync_opengl_swc_swap_interval(session_t *ps, unsigned int interval) {
|
|||
}
|
||||
#endif
|
||||
|
||||
static bool
|
||||
vsync_opengl_swc_init(session_t *ps) {
|
||||
static bool vsync_opengl_swc_init(session_t *ps) {
|
||||
#ifdef CONFIG_OPENGL
|
||||
if (!bkend_use_glx(ps)) {
|
||||
log_warn("OpenGL swap control requires the GLX backend.");
|
||||
|
@ -148,26 +142,24 @@ vsync_opengl_swc_init(session_t *ps) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
vsync_opengl_mswc_init(session_t *ps) {
|
||||
static bool vsync_opengl_mswc_init(session_t *ps) {
|
||||
log_warn("opengl-mswc is deprecated, please use opengl-swc instead.");
|
||||
return vsync_opengl_swc_init(ps);
|
||||
}
|
||||
|
||||
bool (*const VSYNC_FUNCS_INIT[NUM_VSYNC])(session_t *ps) = {
|
||||
[VSYNC_DRM ] = vsync_drm_init,
|
||||
[VSYNC_OPENGL ] = vsync_opengl_init,
|
||||
[VSYNC_OPENGL_OML ] = vsync_opengl_oml_init,
|
||||
[VSYNC_OPENGL_SWC ] = vsync_opengl_swc_init,
|
||||
[VSYNC_OPENGL_MSWC ] = vsync_opengl_mswc_init,
|
||||
[VSYNC_DRM] = vsync_drm_init,
|
||||
[VSYNC_OPENGL] = vsync_opengl_init,
|
||||
[VSYNC_OPENGL_OML] = vsync_opengl_oml_init,
|
||||
[VSYNC_OPENGL_SWC] = vsync_opengl_swc_init,
|
||||
[VSYNC_OPENGL_MSWC] = vsync_opengl_mswc_init,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
/**
|
||||
* Wait for next VSync, OpenGL method.
|
||||
*/
|
||||
static int
|
||||
vsync_opengl_wait(session_t *ps) {
|
||||
static int vsync_opengl_wait(session_t *ps) {
|
||||
unsigned vblank_count = 0;
|
||||
|
||||
glXGetVideoSyncSGI(&vblank_count);
|
||||
|
@ -182,13 +174,11 @@ vsync_opengl_wait(session_t *ps) {
|
|||
*
|
||||
* https://mail.gnome.org/archives/clutter-list/2012-November/msg00031.html
|
||||
*/
|
||||
static int
|
||||
vsync_opengl_oml_wait(session_t *ps) {
|
||||
static int vsync_opengl_oml_wait(session_t *ps) {
|
||||
int64_t ust = 0, msc = 0, sbc = 0;
|
||||
|
||||
glXGetSyncValuesOML(ps->dpy, ps->reg_win, &ust, &msc, &sbc);
|
||||
glXWaitForMscOML(ps->dpy, ps->reg_win, 0, 2, (msc + 1) % 2,
|
||||
&ust, &msc, &sbc);
|
||||
glXWaitForMscOML(ps->dpy, ps->reg_win, 0, 2, (msc + 1) % 2, &ust, &msc, &sbc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -198,27 +188,25 @@ vsync_opengl_oml_wait(session_t *ps) {
|
|||
/// Function pointers to wait for VSync.
|
||||
int (*const VSYNC_FUNCS_WAIT[NUM_VSYNC])(session_t *ps) = {
|
||||
#ifdef CONFIG_VSYNC_DRM
|
||||
[VSYNC_DRM ] = vsync_drm_wait,
|
||||
[VSYNC_DRM] = vsync_drm_wait,
|
||||
#endif
|
||||
#ifdef CONFIG_OPENGL
|
||||
[VSYNC_OPENGL ] = vsync_opengl_wait,
|
||||
[VSYNC_OPENGL_OML ] = vsync_opengl_oml_wait,
|
||||
[VSYNC_OPENGL] = vsync_opengl_wait,
|
||||
[VSYNC_OPENGL_OML] = vsync_opengl_oml_wait,
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
static void
|
||||
vsync_opengl_swc_deinit(session_t *ps) {
|
||||
static void vsync_opengl_swc_deinit(session_t *ps) {
|
||||
vsync_opengl_swc_swap_interval(ps, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/// Function pointers to deinitialize VSync.
|
||||
void (*const VSYNC_FUNCS_DEINIT[NUM_VSYNC])(session_t *ps) = {
|
||||
#ifdef CONFIG_OPENGL
|
||||
[VSYNC_OPENGL_SWC ] = vsync_opengl_swc_deinit,
|
||||
[VSYNC_OPENGL_MSWC ] = vsync_opengl_swc_deinit,
|
||||
[VSYNC_OPENGL_SWC] = vsync_opengl_swc_deinit,
|
||||
[VSYNC_OPENGL_MSWC] = vsync_opengl_swc_deinit,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -232,12 +220,10 @@ bool vsync_init(session_t *ps) {
|
|||
vsync_opengl_swc_swap_interval(ps, 0);
|
||||
#endif
|
||||
|
||||
if (ps->o.vsync && VSYNC_FUNCS_INIT[ps->o.vsync]
|
||||
&& !VSYNC_FUNCS_INIT[ps->o.vsync](ps)) {
|
||||
if (ps->o.vsync && VSYNC_FUNCS_INIT[ps->o.vsync] && !VSYNC_FUNCS_INIT[ps->o.vsync](ps)) {
|
||||
ps->o.vsync = VSYNC_NONE;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
306
src/win.c
306
src/win.c
|
@ -4,29 +4,29 @@
|
|||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/damage.h>
|
||||
#include <xcb/composite.h>
|
||||
#include <xcb/xcb_renderutil.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <xcb/composite.h>
|
||||
#include <xcb/damage.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_renderutil.h>
|
||||
|
||||
#include "compiler.h"
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "compton.h"
|
||||
#include "c2.h"
|
||||
#include "x.h"
|
||||
#include "string_utils.h"
|
||||
#include "utils.h"
|
||||
#include "log.h"
|
||||
#include "types.h"
|
||||
#include "region.h"
|
||||
#include "backend/backend.h"
|
||||
#include "c2.h"
|
||||
#include "common.h"
|
||||
#include "compiler.h"
|
||||
#include "compton.h"
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "region.h"
|
||||
#include "render.h"
|
||||
#include "string_utils.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
#include "x.h"
|
||||
|
||||
#ifdef CONFIG_DBUS
|
||||
#include "dbus.h"
|
||||
|
@ -44,31 +44,29 @@
|
|||
/// Generate a "return by value" function, from a function that returns the
|
||||
/// region via a region_t pointer argument.
|
||||
/// Function signature has to be (win *, region_t *)
|
||||
#define gen_by_val(fun) region_t fun##_by_val(const win *w) { \
|
||||
#define gen_by_val(fun) \
|
||||
region_t fun##_by_val(const win *w) { \
|
||||
region_t ret; \
|
||||
pixman_region32_init(&ret); \
|
||||
fun(w, &ret); \
|
||||
return ret; \
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear leader cache of all windows.
|
||||
*/
|
||||
static inline void
|
||||
clear_cache_win_leaders(session_t *ps) {
|
||||
static inline void clear_cache_win_leaders(session_t *ps) {
|
||||
for (win *w = ps->list; w; w = w->next)
|
||||
w->cache_leader = XCB_NONE;
|
||||
}
|
||||
|
||||
static inline void
|
||||
wid_set_opacity_prop(session_t *ps, xcb_window_t wid, opacity_t val) {
|
||||
static inline void wid_set_opacity_prop(session_t *ps, xcb_window_t wid, opacity_t val) {
|
||||
const uint32_t v = val;
|
||||
xcb_change_property(ps->c, XCB_PROP_MODE_REPLACE, wid, ps->atom_opacity,
|
||||
XCB_ATOM_CARDINAL, 32, 1, &v);
|
||||
}
|
||||
|
||||
static inline void
|
||||
wid_rm_opacity_prop(session_t *ps, xcb_window_t wid) {
|
||||
static inline void wid_rm_opacity_prop(session_t *ps, xcb_window_t wid) {
|
||||
xcb_delete_property(ps->c, wid, ps->atom_opacity);
|
||||
}
|
||||
|
||||
|
@ -77,8 +75,7 @@ wid_rm_opacity_prop(session_t *ps, xcb_window_t wid) {
|
|||
*
|
||||
* @param leader leader window ID
|
||||
*/
|
||||
static inline void
|
||||
group_update_focused(session_t *ps, xcb_window_t leader) {
|
||||
static inline void group_update_focused(session_t *ps, xcb_window_t leader) {
|
||||
if (!leader)
|
||||
return;
|
||||
|
||||
|
@ -96,14 +93,13 @@ group_update_focused(session_t *ps, xcb_window_t leader) {
|
|||
* @param leader leader window ID
|
||||
* @return true if the window group is focused, false otherwise
|
||||
*/
|
||||
static inline bool
|
||||
group_is_focused(session_t *ps, xcb_window_t leader) {
|
||||
static inline bool group_is_focused(session_t *ps, xcb_window_t leader) {
|
||||
if (!leader)
|
||||
return false;
|
||||
|
||||
for (win *w = ps->list; w; w = w->next) {
|
||||
if (win_get_leader(ps, w) == leader && w->state != WSTATE_DESTROYING
|
||||
&& win_is_focused_real(ps, w))
|
||||
if (win_get_leader(ps, w) == leader && w->state != WSTATE_DESTROYING &&
|
||||
win_is_focused_real(ps, w))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -118,7 +114,6 @@ static void win_get_region_local(const win *w, region_t *res) {
|
|||
pixman_region32_init_rect(res, 0, 0, w->widthb, w->heightb);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a rectangular region a window occupies, excluding frame and shadow.
|
||||
*/
|
||||
|
@ -135,21 +130,24 @@ void win_get_region_noframe_local(const win *w, region_t *res) {
|
|||
pixman_region32_init_rect(res, x, y, width, height);
|
||||
}
|
||||
|
||||
gen_by_val(win_get_region_noframe_local)
|
||||
gen_by_val(win_get_region_noframe_local);
|
||||
|
||||
void win_get_region_frame_local(const win *w, region_t *res) {
|
||||
const margin_t extents = win_calc_frame_extents(w);
|
||||
pixman_region32_fini(res);
|
||||
pixman_region32_init_rects(res, (rect_t[]){
|
||||
pixman_region32_init_rects(
|
||||
res,
|
||||
(rect_t[]){
|
||||
// top
|
||||
{.x1 = 0, .y1 = 0, .x2 = w->g.width, .y2 = extents.top},
|
||||
// bottom
|
||||
{.x1 = 0, .y1 = w->g.height - extents.bottom, .x2 = w->g.width, .y2 = w->g.height},
|
||||
//left
|
||||
// left
|
||||
{.x1 = 0, .y1 = 0, .x2 = extents.left, .y2 = w->g.height},
|
||||
// right
|
||||
{.x1 = w->g.width - extents.right, .y1 = 0, .x2 = w->g.width, .y2 = w->g.height},
|
||||
}, 4);
|
||||
},
|
||||
4);
|
||||
|
||||
// limit the frame region to inside the window
|
||||
region_t reg_win;
|
||||
|
@ -158,7 +156,7 @@ void win_get_region_frame_local(const win *w, region_t *res) {
|
|||
pixman_region32_fini(®_win);
|
||||
}
|
||||
|
||||
gen_by_val(win_get_region_frame_local)
|
||||
gen_by_val(win_get_region_frame_local);
|
||||
|
||||
/**
|
||||
* Add a window to damaged area.
|
||||
|
@ -192,19 +190,21 @@ static bool attr_pure win_has_rounded_corners(const win *w) {
|
|||
|
||||
// Determine the minimum width/height of a rectangle that could mark
|
||||
// a window as having rounded corners
|
||||
unsigned short minwidth = max_i(w->widthb * (1 - ROUNDED_PERCENT),
|
||||
w->widthb - ROUNDED_PIXELS);
|
||||
unsigned short minheight = max_i(w->heightb * (1 - ROUNDED_PERCENT),
|
||||
w->heightb - ROUNDED_PIXELS);
|
||||
unsigned short minwidth =
|
||||
max_i(w->widthb * (1 - ROUNDED_PERCENT), w->widthb - ROUNDED_PIXELS);
|
||||
unsigned short minheight =
|
||||
max_i(w->heightb * (1 - ROUNDED_PERCENT), w->heightb - ROUNDED_PIXELS);
|
||||
|
||||
// Get the rectangles in the bounding region
|
||||
int nrects = 0;
|
||||
const rect_t *rects = pixman_region32_rectangles((region_t *)&w->bounding_shape, &nrects);
|
||||
const rect_t *rects =
|
||||
pixman_region32_rectangles((region_t *)&w->bounding_shape, &nrects);
|
||||
|
||||
// Look for a rectangle large enough for this window be considered
|
||||
// having rounded corners
|
||||
for (int i = 0; i < nrects; ++i) {
|
||||
if (rects[i].x2 - rects[i].x1 >= minwidth && rects[i].y2 - rects[i].y1 >= minheight) {
|
||||
if (rects[i].x2 - rects[i].x1 >= minwidth &&
|
||||
rects[i].y2 - rects[i].y1 >= minheight) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ static bool attr_pure win_has_rounded_corners(const win *w) {
|
|||
}
|
||||
|
||||
int win_get_name(session_t *ps, win *w) {
|
||||
XTextProperty text_prop = { NULL, XCB_NONE, 0, 0 };
|
||||
XTextProperty text_prop = {NULL, XCB_NONE, 0, 0};
|
||||
char **strlst = NULL;
|
||||
int nstr = 0;
|
||||
|
||||
|
@ -220,14 +220,14 @@ int win_get_name(session_t *ps, win *w) {
|
|||
return 0;
|
||||
|
||||
if (!(wid_get_text_prop(ps, w->client_win, ps->atom_name_ewmh, &strlst, &nstr))) {
|
||||
log_trace("(%#010x): _NET_WM_NAME unset, falling back to WM_NAME.", w->client_win);
|
||||
log_trace("(%#010x): _NET_WM_NAME unset, falling back to WM_NAME.",
|
||||
w->client_win);
|
||||
|
||||
if (!(XGetWMName(ps->dpy, w->client_win, &text_prop) && text_prop.value)) {
|
||||
return -1;
|
||||
}
|
||||
if (Success !=
|
||||
XmbTextPropertyToTextList(ps->dpy, &text_prop, &strlst, &nstr)
|
||||
|| !nstr || !strlst) {
|
||||
if (Success != XmbTextPropertyToTextList(ps->dpy, &text_prop, &strlst, &nstr) ||
|
||||
!nstr || !strlst) {
|
||||
if (strlst)
|
||||
XFreeStringList(strlst);
|
||||
cxfree(text_prop.value);
|
||||
|
@ -246,7 +246,8 @@ int win_get_name(session_t *ps, win *w) {
|
|||
XFreeStringList(strlst);
|
||||
|
||||
log_trace("(%#010x): client = %#010x, name = \"%s\", "
|
||||
"ret = %d", w->id, w->client_win, w->name, ret);
|
||||
"ret = %d",
|
||||
w->id, w->client_win, w->name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -267,7 +268,8 @@ int win_get_role(session_t *ps, win *w) {
|
|||
XFreeStringList(strlst);
|
||||
|
||||
log_trace("(%#010x): client = %#010x, role = \"%s\", "
|
||||
"ret = %d", w->id, w->client_win, w->role, ret);
|
||||
"ret = %d",
|
||||
w->id, w->client_win, w->role, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -279,8 +281,8 @@ static inline bool win_bounding_shaped(const session_t *ps, xcb_window_t wid) {
|
|||
xcb_shape_query_extents_reply_t *reply;
|
||||
Bool bounding_shaped;
|
||||
|
||||
reply = xcb_shape_query_extents_reply(ps->c,
|
||||
xcb_shape_query_extents(ps->c, wid), NULL);
|
||||
reply = xcb_shape_query_extents_reply(
|
||||
ps->c, xcb_shape_query_extents(ps->c, wid), NULL);
|
||||
bounding_shaped = reply && reply->bounding_shaped;
|
||||
free(reply);
|
||||
|
||||
|
@ -290,8 +292,7 @@ static inline bool win_bounding_shaped(const session_t *ps, xcb_window_t wid) {
|
|||
return false;
|
||||
}
|
||||
|
||||
static wintype_t
|
||||
wid_get_prop_wintype(session_t *ps, xcb_window_t wid) {
|
||||
static wintype_t wid_get_prop_wintype(session_t *ps, xcb_window_t wid) {
|
||||
winprop_t prop = wid_get_prop(ps, wid, ps->atom_win_type, 32L, XCB_ATOM_ATOM, 32);
|
||||
|
||||
for (unsigned i = 0; i < prop.nitems; ++i) {
|
||||
|
@ -309,8 +310,7 @@ wid_get_prop_wintype(session_t *ps, xcb_window_t wid) {
|
|||
}
|
||||
|
||||
static bool
|
||||
wid_get_opacity_prop(session_t *ps, xcb_window_t wid, opacity_t def,
|
||||
opacity_t *out) {
|
||||
wid_get_opacity_prop(session_t *ps, xcb_window_t wid, opacity_t def, opacity_t *out) {
|
||||
bool ret = false;
|
||||
*out = def;
|
||||
|
||||
|
@ -328,8 +328,7 @@ wid_get_opacity_prop(session_t *ps, xcb_window_t wid, opacity_t def,
|
|||
|
||||
// XXX should distinguish between frame has alpha and window body has alpha
|
||||
bool win_has_alpha(const win *w) {
|
||||
return w->pictfmt &&
|
||||
w->pictfmt->type == XCB_RENDER_PICT_TYPE_DIRECT &&
|
||||
return w->pictfmt && w->pictfmt->type == XCB_RENDER_PICT_TYPE_DIRECT &&
|
||||
w->pictfmt->direct.alpha_mask;
|
||||
}
|
||||
|
||||
|
@ -428,7 +427,7 @@ bool win_should_fade(session_t *ps, const win *w) {
|
|||
}
|
||||
// Ignore other possible causes of fading state changes after window
|
||||
// gets unmapped
|
||||
//if (w->a.map_state != XCB_MAP_STATE_VIEWABLE) {
|
||||
// if (w->a.map_state != XCB_MAP_STATE_VIEWABLE) {
|
||||
//}
|
||||
if (c2_match(ps, w, ps->o.fade_blacklist, NULL)) {
|
||||
return false;
|
||||
|
@ -530,8 +529,7 @@ void win_determine_invert_color(session_t *ps, win *w) {
|
|||
if (UNSET != w->invert_color_force)
|
||||
invert_color_new = w->invert_color_force;
|
||||
else if (w->a.map_state == XCB_MAP_STATE_VIEWABLE)
|
||||
invert_color_new =
|
||||
c2_match(ps, w, ps->o.invert_color_list, NULL);
|
||||
invert_color_new = c2_match(ps, w, ps->o.invert_color_list, NULL);
|
||||
|
||||
win_set_invert_color(ps, w, invert_color_new);
|
||||
}
|
||||
|
@ -555,8 +553,7 @@ void win_determine_blur_background(session_t *ps, win *w) {
|
|||
if (w->a.map_state != XCB_MAP_STATE_VIEWABLE)
|
||||
return;
|
||||
|
||||
bool blur_background_new =
|
||||
ps->o.blur_background &&
|
||||
bool blur_background_new = ps->o.blur_background &&
|
||||
!c2_match(ps, w, ps->o.blur_background_blacklist, NULL);
|
||||
|
||||
win_set_blur_background(ps, w, blur_background_new);
|
||||
|
@ -620,11 +617,10 @@ void win_on_factor_change(session_t *ps, win *w) {
|
|||
if (ps->o.opacity_rules)
|
||||
win_update_opacity_rule(ps, w);
|
||||
if (w->a.map_state == XCB_MAP_STATE_VIEWABLE && ps->o.paint_blacklist)
|
||||
w->paint_excluded =
|
||||
c2_match(ps, w, ps->o.paint_blacklist, NULL);
|
||||
w->paint_excluded = c2_match(ps, w, ps->o.paint_blacklist, NULL);
|
||||
if (w->a.map_state == XCB_MAP_STATE_VIEWABLE && ps->o.unredir_if_possible_blacklist)
|
||||
w->unredir_if_possible_excluded = c2_match(
|
||||
ps, w, ps->o.unredir_if_possible_blacklist, NULL);
|
||||
w->unredir_if_possible_excluded =
|
||||
c2_match(ps, w, ps->o.unredir_if_possible_blacklist, NULL);
|
||||
w->reg_ignore_valid = false;
|
||||
}
|
||||
|
||||
|
@ -641,20 +637,22 @@ void win_on_win_size_change(session_t *ps, win *w) {
|
|||
w->flags |= WFLAG_SIZE_CHANGE;
|
||||
// Invalidate the shadow we built
|
||||
if (ps->o.experimental_backends && ps->redirected) {
|
||||
if (w->state == WSTATE_MAPPED ||
|
||||
w->state == WSTATE_MAPPING ||
|
||||
if (w->state == WSTATE_MAPPED || w->state == WSTATE_MAPPING ||
|
||||
w->state == WSTATE_FADING) {
|
||||
ps->backend_data->ops->release_image(ps->backend_data, w->win_image);
|
||||
if (w->shadow_image) {
|
||||
ps->backend_data->ops->release_image(ps->backend_data, w->shadow_image);
|
||||
ps->backend_data->ops->release_image(ps->backend_data,
|
||||
w->shadow_image);
|
||||
}
|
||||
auto pixmap = xcb_generate_id(ps->c);
|
||||
xcb_composite_name_window_pixmap(ps->c, w->id, pixmap);
|
||||
w->win_image = ps->backend_data->ops->bind_pixmap(ps->backend_data, pixmap, x_get_visual_info(ps->c, w->a.visual), true);
|
||||
w->win_image = ps->backend_data->ops->bind_pixmap(
|
||||
ps->backend_data, pixmap,
|
||||
x_get_visual_info(ps->c, w->a.visual), true);
|
||||
if (w->shadow) {
|
||||
w->shadow_image = ps->backend_data->ops->render_shadow(ps->backend_data, w->widthb,
|
||||
w->heightb, ps->gaussian_map,
|
||||
ps->o.shadow_red, ps->o.shadow_green,
|
||||
w->shadow_image = ps->backend_data->ops->render_shadow(
|
||||
ps->backend_data, w->widthb, w->heightb,
|
||||
ps->gaussian_map, ps->o.shadow_red, ps->o.shadow_green,
|
||||
ps->o.shadow_blue, ps->o.shadow_opacity);
|
||||
}
|
||||
} else {
|
||||
|
@ -749,8 +747,9 @@ void win_unmark_client(session_t *ps, win *w) {
|
|||
w->client_win = XCB_NONE;
|
||||
|
||||
// Recheck event mask
|
||||
xcb_change_window_attributes(ps->c, client, XCB_CW_EVENT_MASK,
|
||||
(const uint32_t[]) { determine_evmask(ps, client, WIN_EVMODE_UNKNOWN) });
|
||||
xcb_change_window_attributes(
|
||||
ps->c, client, XCB_CW_EVENT_MASK,
|
||||
(const uint32_t[]){determine_evmask(ps, client, WIN_EVMODE_UNKNOWN)});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -803,8 +802,7 @@ void free_win_res(session_t *ps, win *w) {
|
|||
|
||||
pixman_region32_fini(&w->bounding_shape);
|
||||
// BadDamage may be thrown if the window is destroyed
|
||||
set_ignore_cookie(ps,
|
||||
xcb_damage_destroy(ps->c, w->damage));
|
||||
set_ignore_cookie(ps, xcb_damage_destroy(ps->c, w->damage));
|
||||
rc_region_unref(&w->reg_ignore);
|
||||
free(w->name);
|
||||
free(w->class_instance);
|
||||
|
@ -833,7 +831,7 @@ void add_win(session_t *ps, xcb_window_t id, xcb_window_t prev) {
|
|||
.need_configure = false, // set to true when window is configured
|
||||
// while unmapped.
|
||||
.queue_configure = {}, // same as above
|
||||
.reg_ignore_valid = false,// set to true when damaged
|
||||
.reg_ignore_valid = false, // set to true when damaged
|
||||
.flags = 0, // updated by property/attributes/etc change
|
||||
|
||||
// Runtime variables, updated by dbus
|
||||
|
@ -910,7 +908,8 @@ void add_win(session_t *ps, xcb_window_t id, xcb_window_t prev) {
|
|||
log_debug("Adding window %#010x, prev %#010x", id, prev);
|
||||
xcb_get_window_attributes_cookie_t acookie = xcb_get_window_attributes(ps->c, id);
|
||||
xcb_get_geometry_cookie_t gcookie = xcb_get_geometry(ps->c, id);
|
||||
xcb_get_window_attributes_reply_t *a = xcb_get_window_attributes_reply(ps->c, acookie, NULL);
|
||||
xcb_get_window_attributes_reply_t *a =
|
||||
xcb_get_window_attributes_reply(ps->c, acookie, NULL);
|
||||
xcb_get_geometry_reply_t *g = xcb_get_geometry_reply(ps->c, gcookie, NULL);
|
||||
if (!a || !g || a->map_state == XCB_MAP_STATE_UNVIEWABLE) {
|
||||
// Failed to get window attributes or geometry probably means
|
||||
|
@ -941,8 +940,9 @@ void add_win(session_t *ps, xcb_window_t id, xcb_window_t prev) {
|
|||
// Create Damage for window (if not Input Only)
|
||||
if (new->a._class != XCB_WINDOW_CLASS_INPUT_ONLY) {
|
||||
new->damage = xcb_generate_id(ps->c);
|
||||
xcb_generic_error_t *e = xcb_request_check(ps->c,
|
||||
xcb_damage_create_checked(ps->c, new->damage, id, XCB_DAMAGE_REPORT_LEVEL_NON_EMPTY));
|
||||
xcb_generic_error_t *e = xcb_request_check(
|
||||
ps->c, xcb_damage_create_checked(ps->c, new->damage, id,
|
||||
XCB_DAMAGE_REPORT_LEVEL_NON_EMPTY));
|
||||
if (e) {
|
||||
free(e);
|
||||
free(new);
|
||||
|
@ -987,18 +987,17 @@ void win_update_focused(session_t *ps, win *w) {
|
|||
|
||||
// Use wintype_focus, and treat WM windows and override-redirected
|
||||
// windows specially
|
||||
if (ps->o.wintype_option[w->window_type].focus
|
||||
|| (ps->o.mark_wmwin_focused && w->wmwin)
|
||||
|| (ps->o.mark_ovredir_focused &&
|
||||
w->id == w->client_win && !w->wmwin)
|
||||
|| (w->a.map_state == XCB_MAP_STATE_VIEWABLE &&
|
||||
if (ps->o.wintype_option[w->window_type].focus ||
|
||||
(ps->o.mark_wmwin_focused && w->wmwin) ||
|
||||
(ps->o.mark_ovredir_focused && w->id == w->client_win && !w->wmwin) ||
|
||||
(w->a.map_state == XCB_MAP_STATE_VIEWABLE &&
|
||||
c2_match(ps, w, ps->o.focus_blacklist, NULL)))
|
||||
w->focused = true;
|
||||
|
||||
// If window grouping detection is enabled, mark the window active if
|
||||
// its group is
|
||||
if (ps->o.track_leader && ps->active_leader
|
||||
&& win_get_leader(ps, w) == ps->active_leader) {
|
||||
if (ps->o.track_leader && ps->active_leader &&
|
||||
win_get_leader(ps, w) == ps->active_leader) {
|
||||
w->focused = true;
|
||||
}
|
||||
}
|
||||
|
@ -1064,8 +1063,8 @@ void win_update_leader(session_t *ps, win *w) {
|
|||
|
||||
win_set_leader(ps, w, leader);
|
||||
|
||||
log_trace("(%#010x): client %#010x, leader %#010x, cache %#010x",
|
||||
w->id, w->client_win, w->leader, win_get_leader(ps, w));
|
||||
log_trace("(%#010x): client %#010x, leader %#010x, cache %#010x", w->id,
|
||||
w->client_win, w->leader, win_get_leader(ps, w));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1131,13 +1130,10 @@ bool win_get_class(session_t *ps, win *w) {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handle window focus change.
|
||||
*/
|
||||
static void
|
||||
win_on_focus_change(session_t *ps, win *w) {
|
||||
static void win_on_focus_change(session_t *ps, win *w) {
|
||||
// If window grouping detection is enabled
|
||||
if (ps->o.track_leader) {
|
||||
xcb_window_t leader = win_get_leader(ps, w);
|
||||
|
@ -1152,8 +1148,8 @@ win_on_focus_change(session_t *ps, win *w) {
|
|||
group_update_focused(ps, leader);
|
||||
}
|
||||
// If the group get unfocused, remove it from active_leader
|
||||
else if (!win_is_focused_real(ps, w) && leader && leader == ps->active_leader
|
||||
&& !group_is_focused(ps, leader)) {
|
||||
else if (!win_is_focused_real(ps, w) && leader &&
|
||||
leader == ps->active_leader && !group_is_focused(ps, leader)) {
|
||||
ps->active_leader = XCB_NONE;
|
||||
group_update_focused(ps, leader);
|
||||
}
|
||||
|
@ -1183,20 +1179,19 @@ win_on_focus_change(session_t *ps, win *w) {
|
|||
/**
|
||||
* Set real focused state of a window.
|
||||
*/
|
||||
void
|
||||
win_set_focused(session_t *ps, win *w, bool focused) {
|
||||
void win_set_focused(session_t *ps, win *w, bool focused) {
|
||||
// Unmapped windows will have their focused state reset on map
|
||||
if (w->a.map_state == XCB_MAP_STATE_UNMAPPED)
|
||||
return;
|
||||
|
||||
if (win_is_focused_real(ps, w) == focused) return;
|
||||
if (win_is_focused_real(ps, w) == focused)
|
||||
return;
|
||||
|
||||
if (focused) {
|
||||
if (ps->active_win)
|
||||
win_set_focused(ps, ps->active_win, false);
|
||||
ps->active_win = w;
|
||||
}
|
||||
else if (w == ps->active_win)
|
||||
} else if (w == ps->active_win)
|
||||
ps->active_win = NULL;
|
||||
|
||||
assert(win_is_focused_real(ps, w) == focused);
|
||||
|
@ -1216,17 +1211,18 @@ void win_extents(const win *w, region_t *res) {
|
|||
|
||||
if (w->shadow)
|
||||
pixman_region32_union_rect(res, res, w->g.x + w->shadow_dx,
|
||||
w->g.y + w->shadow_dy, w->shadow_width, w->shadow_height);
|
||||
w->g.y + w->shadow_dy, w->shadow_width,
|
||||
w->shadow_height);
|
||||
}
|
||||
|
||||
gen_by_val(win_extents)
|
||||
gen_by_val(win_extents);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Update the out-dated bounding shape of a window.
|
||||
*
|
||||
* Mark the window shape as updated
|
||||
*/
|
||||
void win_update_bounding_shape(session_t *ps, win *w) {
|
||||
void win_update_bounding_shape(session_t *ps, win *w) {
|
||||
if (ps->shape_exists)
|
||||
w->bounding_shaped = win_bounding_shaped(ps, w->id);
|
||||
|
||||
|
@ -1242,8 +1238,8 @@ void win_update_bounding_shape(session_t *ps, win *w) {
|
|||
* as well as not generate a region.
|
||||
*/
|
||||
|
||||
xcb_shape_get_rectangles_reply_t *r = xcb_shape_get_rectangles_reply(ps->c,
|
||||
xcb_shape_get_rectangles(ps->c, w->id, XCB_SHAPE_SK_BOUNDING), NULL);
|
||||
xcb_shape_get_rectangles_reply_t *r = xcb_shape_get_rectangles_reply(
|
||||
ps->c, xcb_shape_get_rectangles(ps->c, w->id, XCB_SHAPE_SK_BOUNDING), NULL);
|
||||
|
||||
if (!r)
|
||||
break;
|
||||
|
@ -1279,7 +1275,7 @@ void win_update_bounding_shape(session_t *ps, win *w) {
|
|||
|
||||
// Window shape changed, we should free old wpaint and shadow pict
|
||||
if (ps->o.experimental_backends) {
|
||||
//log_trace("free out dated pict");
|
||||
// log_trace("free out dated pict");
|
||||
// Window shape changed, we should free win_data
|
||||
if (ps->redirected && w->state != WSTATE_UNMAPPED) {
|
||||
// Note we only do this when screen is redirected, because
|
||||
|
@ -1287,15 +1283,18 @@ void win_update_bounding_shape(session_t *ps, win *w) {
|
|||
assert(w->state != WSTATE_UNMAPPING && w->state != WSTATE_DESTROYING);
|
||||
ps->backend_data->ops->release_image(ps->backend_data, w->win_image);
|
||||
if (w->shadow_image) {
|
||||
ps->backend_data->ops->release_image(ps->backend_data, w->shadow_image);
|
||||
ps->backend_data->ops->release_image(ps->backend_data,
|
||||
w->shadow_image);
|
||||
}
|
||||
auto pixmap = xcb_generate_id(ps->c);
|
||||
xcb_composite_name_window_pixmap(ps->c, w->id, pixmap);
|
||||
w->win_image = ps->backend_data->ops->bind_pixmap(ps->backend_data, pixmap, x_get_visual_info(ps->c, w->a.visual), true);
|
||||
w->win_image = ps->backend_data->ops->bind_pixmap(
|
||||
ps->backend_data, pixmap,
|
||||
x_get_visual_info(ps->c, w->a.visual), true);
|
||||
if (w->shadow) {
|
||||
w->shadow_image = ps->backend_data->ops->render_shadow(ps->backend_data, w->widthb,
|
||||
w->heightb, ps->gaussian_map,
|
||||
ps->o.shadow_red, ps->o.shadow_green,
|
||||
w->shadow_image = ps->backend_data->ops->render_shadow(
|
||||
ps->backend_data, w->widthb, w->heightb,
|
||||
ps->gaussian_map, ps->o.shadow_red, ps->o.shadow_green,
|
||||
ps->o.shadow_blue, ps->o.shadow_opacity);
|
||||
}
|
||||
}
|
||||
|
@ -1312,8 +1311,7 @@ void win_update_bounding_shape(session_t *ps, win *w) {
|
|||
*/
|
||||
void win_update_opacity_prop(session_t *ps, win *w) {
|
||||
// get frame opacity first
|
||||
w->has_opacity_prop =
|
||||
wid_get_opacity_prop(ps, w->id, OPAQUE, &w->opacity_prop);
|
||||
w->has_opacity_prop = wid_get_opacity_prop(ps, w->id, OPAQUE, &w->opacity_prop);
|
||||
|
||||
if (w->has_opacity_prop)
|
||||
// opacity found
|
||||
|
@ -1331,13 +1329,12 @@ void win_update_opacity_prop(session_t *ps, win *w) {
|
|||
/**
|
||||
* Retrieve frame extents from a window.
|
||||
*/
|
||||
void
|
||||
win_update_frame_extents(session_t *ps, win *w, xcb_window_t client) {
|
||||
winprop_t prop = wid_get_prop(ps, client, ps->atom_frame_extents,
|
||||
4L, XCB_ATOM_CARDINAL, 32);
|
||||
void win_update_frame_extents(session_t *ps, win *w, xcb_window_t client) {
|
||||
winprop_t prop =
|
||||
wid_get_prop(ps, client, ps->atom_frame_extents, 4L, XCB_ATOM_CARDINAL, 32);
|
||||
|
||||
if (prop.nitems == 4) {
|
||||
const uint32_t * const extents = prop.c32;
|
||||
const uint32_t *const extents = prop.c32;
|
||||
const bool changed = w->frame_extents.left != extents[0] ||
|
||||
w->frame_extents.right != extents[1] ||
|
||||
w->frame_extents.top != extents[2] ||
|
||||
|
@ -1353,15 +1350,14 @@ win_update_frame_extents(session_t *ps, win *w, xcb_window_t client) {
|
|||
w->reg_ignore_valid = false;
|
||||
}
|
||||
|
||||
log_trace("(%#010x): %d, %d, %d, %d", w->id,
|
||||
w->frame_extents.left, w->frame_extents.right,
|
||||
w->frame_extents.top, w->frame_extents.bottom);
|
||||
log_trace("(%#010x): %d, %d, %d, %d", w->id, w->frame_extents.left,
|
||||
w->frame_extents.right, w->frame_extents.top, w->frame_extents.bottom);
|
||||
|
||||
free_winprop(&prop);
|
||||
}
|
||||
|
||||
bool win_is_region_ignore_valid(session_t *ps, const win *w) {
|
||||
for(win *i = ps->list; w; w = w->next) {
|
||||
for (win *i = ps->list; w; w = w->next) {
|
||||
if (i == w)
|
||||
break;
|
||||
if (!i->reg_ignore_valid)
|
||||
|
@ -1374,10 +1370,11 @@ bool win_is_region_ignore_valid(session_t *ps, const win *w) {
|
|||
* Stop listening for events on a particular window.
|
||||
*/
|
||||
void win_ev_stop(session_t *ps, const win *w) {
|
||||
xcb_change_window_attributes(ps->c, w->id, XCB_CW_EVENT_MASK, (const uint32_t[]) { 0 });
|
||||
xcb_change_window_attributes(ps->c, w->id, XCB_CW_EVENT_MASK, (const uint32_t[]){0});
|
||||
|
||||
if (w->client_win) {
|
||||
xcb_change_window_attributes(ps->c, w->client_win, XCB_CW_EVENT_MASK, (const uint32_t[]) { 0 });
|
||||
xcb_change_window_attributes(ps->c, w->client_win, XCB_CW_EVENT_MASK,
|
||||
(const uint32_t[]){0});
|
||||
}
|
||||
|
||||
if (ps->shape_exists) {
|
||||
|
@ -1385,8 +1382,7 @@ void win_ev_stop(session_t *ps, const win *w) {
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
finish_unmap_win(session_t *ps, win **_w) {
|
||||
static void finish_unmap_win(session_t *ps, win **_w) {
|
||||
win *w = *_w;
|
||||
w->ever_damaged = false;
|
||||
w->reg_ignore_valid = false;
|
||||
|
@ -1399,7 +1395,8 @@ finish_unmap_win(session_t *ps, win **_w) {
|
|||
assert(w->win_image);
|
||||
ps->backend_data->ops->release_image(ps->backend_data, w->win_image);
|
||||
if (w->shadow_image) {
|
||||
ps->backend_data->ops->release_image(ps->backend_data, w->shadow_image);
|
||||
ps->backend_data->ops->release_image(ps->backend_data,
|
||||
w->shadow_image);
|
||||
}
|
||||
w->win_image = NULL;
|
||||
w->shadow_image = NULL;
|
||||
|
@ -1410,8 +1407,7 @@ finish_unmap_win(session_t *ps, win **_w) {
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
finish_destroy_win(session_t *ps, win **_w) {
|
||||
static void finish_destroy_win(session_t *ps, win **_w) {
|
||||
win *w = *_w;
|
||||
win **prev = NULL;
|
||||
|
||||
|
@ -1465,15 +1461,13 @@ finish_destroy_win(session_t *ps, win **_w) {
|
|||
assert(false);
|
||||
}
|
||||
|
||||
static void
|
||||
finish_map_win(session_t *ps, win **_w) {
|
||||
static void finish_map_win(session_t *ps, win **_w) {
|
||||
win *w = *_w;
|
||||
w->in_openclose = false;
|
||||
w->state = WSTATE_MAPPED;
|
||||
}
|
||||
|
||||
void
|
||||
unmap_win(session_t *ps, win **_w, bool destroy) {
|
||||
void unmap_win(session_t *ps, win **_w, bool destroy) {
|
||||
win *w = *_w;
|
||||
|
||||
winstate_t target_state = destroy ? WSTATE_DESTROYING : WSTATE_UNMAPPING;
|
||||
|
@ -1490,7 +1484,7 @@ unmap_win(session_t *ps, win **_w, bool destroy) {
|
|||
return;
|
||||
}
|
||||
|
||||
log_trace("Unmapping %#010x \"%s\", destroy = %d", w->id, (w ? w->name: NULL), destroy);
|
||||
log_trace("Unmapping %#010x \"%s\", destroy = %d", w->id, (w ? w->name : NULL), destroy);
|
||||
|
||||
if (unlikely(w->state == WSTATE_DESTROYING && !destroy)) {
|
||||
log_warn("Trying to undestroy a window?");
|
||||
|
@ -1505,7 +1499,8 @@ unmap_win(session_t *ps, win **_w, bool destroy) {
|
|||
|
||||
if (unlikely(w->state == WSTATE_UNMAPPED) || w->a._class == XCB_WINDOW_CLASS_INPUT_ONLY) {
|
||||
if (unlikely(!destroy)) {
|
||||
log_warn("Unmapping an already unmapped window %#010x %s twice", w->id, w->name);
|
||||
log_warn("Unmapping an already unmapped window %#010x %s twice",
|
||||
w->id, w->name);
|
||||
return;
|
||||
}
|
||||
// Window is already unmapped, or is an Input Only window, just destroy it
|
||||
|
@ -1546,8 +1541,7 @@ unmap_win(session_t *ps, win **_w, bool destroy) {
|
|||
/**
|
||||
* Execute fade callback of a window if fading finished.
|
||||
*/
|
||||
void
|
||||
win_check_fade_finished(session_t *ps, win **_w) {
|
||||
void win_check_fade_finished(session_t *ps, win **_w) {
|
||||
win *w = *_w;
|
||||
if (w->state == WSTATE_MAPPED || w->state == WSTATE_UNMAPPED) {
|
||||
// No fading in progress
|
||||
|
@ -1591,13 +1585,14 @@ void win_update_screen(session_t *ps, win *w) {
|
|||
if (!ps->xinerama_scrs)
|
||||
return;
|
||||
|
||||
xcb_xinerama_screen_info_t *scrs = xcb_xinerama_query_screens_screen_info(ps->xinerama_scrs);
|
||||
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) {
|
||||
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) {
|
||||
w->xinerama_scr = i;
|
||||
return;
|
||||
}
|
||||
|
@ -1634,8 +1629,9 @@ void map_win(session_t *ps, win *w) {
|
|||
|
||||
// Set window event mask before reading properties so that no property
|
||||
// changes are lost
|
||||
xcb_change_window_attributes(ps->c, w->id, XCB_CW_EVENT_MASK,
|
||||
(const uint32_t[]) { determine_evmask(ps, w->id, WIN_EVMODE_FRAME) });
|
||||
xcb_change_window_attributes(
|
||||
ps->c, w->id, XCB_CW_EVENT_MASK,
|
||||
(const uint32_t[]){determine_evmask(ps, w->id, WIN_EVMODE_FRAME)});
|
||||
|
||||
// Notify compton when the shape of a window changes
|
||||
if (ps->shape_exists) {
|
||||
|
@ -1681,16 +1677,17 @@ void map_win(session_t *ps, win *w) {
|
|||
if (ps->redirected && ps->o.experimental_backends) {
|
||||
auto pixmap = xcb_generate_id(ps->c);
|
||||
xcb_composite_name_window_pixmap(ps->c, w->id, pixmap);
|
||||
w->win_image = ps->backend_data->ops->bind_pixmap(ps->backend_data, pixmap, x_get_visual_info(ps->c, w->a.visual), true);
|
||||
w->win_image = ps->backend_data->ops->bind_pixmap(
|
||||
ps->backend_data, pixmap, x_get_visual_info(ps->c, w->a.visual), true);
|
||||
if (w->shadow) {
|
||||
w->shadow_image =
|
||||
ps->backend_data->ops->render_shadow(ps->backend_data, w->widthb,
|
||||
w->heightb, ps->gaussian_map,
|
||||
ps->o.shadow_red, ps->o.shadow_green,
|
||||
ps->o.shadow_blue, ps->o.shadow_opacity);
|
||||
w->shadow_image = ps->backend_data->ops->render_shadow(
|
||||
ps->backend_data, w->widthb, w->heightb, ps->gaussian_map,
|
||||
ps->o.shadow_red, ps->o.shadow_green, ps->o.shadow_blue,
|
||||
ps->o.shadow_opacity);
|
||||
}
|
||||
}
|
||||
log_debug("Window %#010x has opacity %f, opacity target is %f", w->id, w->opacity, w->opacity_tgt);
|
||||
log_debug("Window %#010x has opacity %f, opacity target is %f", w->id, w->opacity,
|
||||
w->opacity_tgt);
|
||||
|
||||
win_determine_blur_background(ps, w);
|
||||
|
||||
|
@ -1744,5 +1741,4 @@ void map_win_by_id(session_t *ps, xcb_window_t id) {
|
|||
map_win(ps, w);
|
||||
}
|
||||
|
||||
|
||||
// vim: set et sw=2 :
|
||||
|
|
33
src/win.h
33
src/win.h
|
@ -3,22 +3,22 @@
|
|||
// Copyright (c) 2013 Richard Grenville <pyxlcy@gmail.com>
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/damage.h>
|
||||
#include <xcb/render.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
// FIXME shouldn't need this
|
||||
#ifdef CONFIG_OPENGL
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include "x.h"
|
||||
#include "c2.h"
|
||||
#include "compiler.h"
|
||||
#include "region.h"
|
||||
#include "types.h"
|
||||
#include "c2.h"
|
||||
#include "render.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
#include "x.h"
|
||||
|
||||
typedef struct session session_t;
|
||||
typedef struct _glx_texture glx_texture_t;
|
||||
|
@ -363,8 +363,7 @@ region_t win_get_region_frame_local_by_val(const win *w);
|
|||
/**
|
||||
* Retrieve frame extents from a window.
|
||||
*/
|
||||
void
|
||||
win_update_frame_extents(session_t *ps, win *w, xcb_window_t client);
|
||||
void win_update_frame_extents(session_t *ps, win *w, xcb_window_t client);
|
||||
void add_win(session_t *ps, xcb_window_t id, xcb_window_t prev);
|
||||
/// Unmap or destroy a window
|
||||
void unmap_win(session_t *ps, win **, bool destroy);
|
||||
|
@ -375,8 +374,7 @@ void map_win_by_id(session_t *ps, xcb_window_t id);
|
|||
/**
|
||||
* Execute fade callback of a window if fading finished.
|
||||
*/
|
||||
void
|
||||
win_check_fade_finished(session_t *ps, win **_w);
|
||||
void win_check_fade_finished(session_t *ps, win **_w);
|
||||
|
||||
// Stop receiving events (except ConfigureNotify, XXX why?) from a window
|
||||
void win_ev_stop(session_t *ps, const win *w);
|
||||
|
@ -390,8 +388,7 @@ void win_skip_fading(session_t *ps, win **_w);
|
|||
*
|
||||
* This function updates w->cache_leader if necessary.
|
||||
*/
|
||||
static inline xcb_window_t
|
||||
win_get_leader(session_t *ps, win *w) {
|
||||
static inline xcb_window_t win_get_leader(session_t *ps, win *w) {
|
||||
return win_get_leader_raw(ps, w, 0);
|
||||
}
|
||||
|
||||
|
@ -404,8 +401,7 @@ bool attr_pure win_is_region_ignore_valid(session_t *ps, const win *w);
|
|||
/// Free all resources in a struct win
|
||||
void free_win_res(session_t *ps, win *w);
|
||||
|
||||
static inline region_t
|
||||
win_get_bounding_shape_global_by_val(win *w) {
|
||||
static inline region_t win_get_bounding_shape_global_by_val(win *w) {
|
||||
region_t ret;
|
||||
pixman_region32_init(&ret);
|
||||
pixman_region32_copy(&ret, &w->bounding_shape);
|
||||
|
@ -417,8 +413,7 @@ win_get_bounding_shape_global_by_val(win *w) {
|
|||
* Calculate the extents of the frame of the given window based on EWMH
|
||||
* _NET_FRAME_EXTENTS and the X window border width.
|
||||
*/
|
||||
static inline margin_t attr_pure
|
||||
win_calc_frame_extents(const win *w) {
|
||||
static inline margin_t attr_pure win_calc_frame_extents(const win *w) {
|
||||
margin_t result = w->frame_extents;
|
||||
result.top = max_i(result.top, w->g.border_width);
|
||||
result.left = max_i(result.left, w->g.border_width);
|
||||
|
@ -430,9 +425,7 @@ win_calc_frame_extents(const win *w) {
|
|||
/**
|
||||
* Check whether a window has WM frames.
|
||||
*/
|
||||
static inline bool attr_pure
|
||||
win_has_frame(const win *w) {
|
||||
return w->g.border_width
|
||||
|| w->frame_extents.top || w->frame_extents.left
|
||||
|| w->frame_extents.right || w->frame_extents.bottom;
|
||||
static inline bool attr_pure win_has_frame(const win *w) {
|
||||
return w->g.border_width || w->frame_extents.top || w->frame_extents.left ||
|
||||
w->frame_extents.right || w->frame_extents.bottom;
|
||||
}
|
||||
|
|
203
src/x.c
203
src/x.c
|
@ -4,23 +4,23 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_renderutil.h>
|
||||
#include <xcb/xfixes.h>
|
||||
#include <xcb/sync.h>
|
||||
#include <pixman.h>
|
||||
#include <xcb/composite.h>
|
||||
#include <xcb/damage.h>
|
||||
#include <xcb/render.h>
|
||||
#include <pixman.h>
|
||||
#include <xcb/sync.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_renderutil.h>
|
||||
#include <xcb/xfixes.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "region.h"
|
||||
#include "compiler.h"
|
||||
#include "common.h"
|
||||
#include "kernel.h"
|
||||
#include "x.h"
|
||||
#include "log.h"
|
||||
#include "backend/gl/glx.h"
|
||||
#include "common.h"
|
||||
#include "compiler.h"
|
||||
#include "kernel.h"
|
||||
#include "log.h"
|
||||
#include "region.h"
|
||||
#include "utils.h"
|
||||
#include "x.h"
|
||||
|
||||
/**
|
||||
* Get a specific attribute of a window.
|
||||
|
@ -37,21 +37,19 @@
|
|||
* @return a <code>winprop_t</code> structure containing the attribute
|
||||
* and number of items. A blank one on failure.
|
||||
*/
|
||||
winprop_t
|
||||
wid_get_prop_adv(const session_t *ps, xcb_window_t w, xcb_atom_t atom, long offset,
|
||||
long length, xcb_atom_t rtype, int rformat) {
|
||||
xcb_get_property_reply_t *r = xcb_get_property_reply(ps->c,
|
||||
xcb_get_property(ps->c, 0, w, atom, rtype, offset, length), NULL);
|
||||
winprop_t wid_get_prop_adv(const session_t *ps, xcb_window_t w, xcb_atom_t atom,
|
||||
long offset, long length, xcb_atom_t rtype, int rformat) {
|
||||
xcb_get_property_reply_t *r = xcb_get_property_reply(
|
||||
ps->c, xcb_get_property(ps->c, 0, w, atom, rtype, offset, length), NULL);
|
||||
|
||||
if (r && xcb_get_property_value_length(r) &&
|
||||
(rtype == XCB_GET_PROPERTY_TYPE_ANY || r->type == rtype) &&
|
||||
(!rformat || r->format == rformat) &&
|
||||
(r->format == 8 || r->format == 16 || r->format == 32))
|
||||
{
|
||||
(r->format == 8 || r->format == 16 || r->format == 32)) {
|
||||
int len = xcb_get_property_value_length(r);
|
||||
return (winprop_t) {
|
||||
return (winprop_t){
|
||||
.ptr = xcb_get_property_value(r),
|
||||
.nitems = len/(r->format/8),
|
||||
.nitems = len / (r->format / 8),
|
||||
.type = r->type,
|
||||
.format = r->format,
|
||||
.r = r,
|
||||
|
@ -59,12 +57,8 @@ wid_get_prop_adv(const session_t *ps, xcb_window_t w, xcb_atom_t atom, long offs
|
|||
}
|
||||
|
||||
free(r);
|
||||
return (winprop_t) {
|
||||
.ptr = NULL,
|
||||
.nitems = 0,
|
||||
.type = XCB_GET_PROPERTY_TYPE_ANY,
|
||||
.format = 0
|
||||
};
|
||||
return (winprop_t){
|
||||
.ptr = NULL, .nitems = 0, .type = XCB_GET_PROPERTY_TYPE_ANY, .format = 0};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,8 +66,7 @@ wid_get_prop_adv(const session_t *ps, xcb_window_t w, xcb_atom_t atom, long offs
|
|||
*
|
||||
* @return the value if successful, 0 otherwise
|
||||
*/
|
||||
xcb_window_t
|
||||
wid_get_prop_window(session_t *ps, xcb_window_t wid, xcb_atom_t aprop) {
|
||||
xcb_window_t wid_get_prop_window(session_t *ps, xcb_window_t wid, xcb_atom_t aprop) {
|
||||
// Get the attribute
|
||||
xcb_window_t p = XCB_NONE;
|
||||
winprop_t prop = wid_get_prop(ps, wid, aprop, 1L, XCB_ATOM_WINDOW, 32);
|
||||
|
@ -91,16 +84,15 @@ wid_get_prop_window(session_t *ps, xcb_window_t wid, xcb_atom_t aprop) {
|
|||
/**
|
||||
* Get the value of a text property of a window.
|
||||
*/
|
||||
bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop,
|
||||
char ***pstrlst, int *pnstr) {
|
||||
XTextProperty text_prop = { NULL, XCB_NONE, 0, 0 };
|
||||
bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char ***pstrlst,
|
||||
int *pnstr) {
|
||||
XTextProperty text_prop = {NULL, XCB_NONE, 0, 0};
|
||||
|
||||
if (!(XGetTextProperty(ps->dpy, wid, &text_prop, prop) && text_prop.value))
|
||||
return false;
|
||||
|
||||
if (Success !=
|
||||
XmbTextPropertyToTextList(ps->dpy, &text_prop, pstrlst, pnstr)
|
||||
|| !*pnstr) {
|
||||
if (Success != XmbTextPropertyToTextList(ps->dpy, &text_prop, pstrlst, pnstr) ||
|
||||
!*pnstr) {
|
||||
*pnstr = 0;
|
||||
if (*pstrlst)
|
||||
XFreeStringList(*pstrlst);
|
||||
|
@ -122,8 +114,7 @@ static inline void x_get_server_pictfmts(xcb_connection_t *c) {
|
|||
xcb_generic_error_t *e = NULL;
|
||||
// Get window picture format
|
||||
g_pictfmts =
|
||||
xcb_render_query_pict_formats_reply(c,
|
||||
xcb_render_query_pict_formats(c), &e);
|
||||
xcb_render_query_pict_formats_reply(c, xcb_render_query_pict_formats(c), &e);
|
||||
if (e || !g_pictfmts) {
|
||||
log_fatal("failed to get pict formats\n");
|
||||
abort();
|
||||
|
@ -135,9 +126,9 @@ x_get_pictform_for_visual(xcb_connection_t *c, xcb_visualid_t visual) {
|
|||
x_get_server_pictfmts(c);
|
||||
|
||||
xcb_render_pictvisual_t *pv = xcb_render_util_find_visual_format(g_pictfmts, visual);
|
||||
for(xcb_render_pictforminfo_iterator_t i =
|
||||
xcb_render_query_pict_formats_formats_iterator(g_pictfmts); i.rem;
|
||||
xcb_render_pictforminfo_next(&i)) {
|
||||
for (xcb_render_pictforminfo_iterator_t i =
|
||||
xcb_render_query_pict_formats_formats_iterator(g_pictfmts);
|
||||
i.rem; xcb_render_pictforminfo_next(&i)) {
|
||||
if (i.data->id == pv->format) {
|
||||
return i.data;
|
||||
}
|
||||
|
@ -145,15 +136,14 @@ x_get_pictform_for_visual(xcb_connection_t *c, xcb_visualid_t visual) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static xcb_visualid_t attr_pure
|
||||
x_get_visual_for_pictfmt(xcb_render_query_pict_formats_reply_t *r,
|
||||
static xcb_visualid_t attr_pure x_get_visual_for_pictfmt(xcb_render_query_pict_formats_reply_t *r,
|
||||
xcb_render_pictformat_t fmt) {
|
||||
for (auto screen = xcb_render_query_pict_formats_screens_iterator(r);
|
||||
screen.rem; xcb_render_pictscreen_next(&screen)) {
|
||||
for (auto screen = xcb_render_query_pict_formats_screens_iterator(r); screen.rem;
|
||||
xcb_render_pictscreen_next(&screen)) {
|
||||
for (auto depth = xcb_render_pictscreen_depths_iterator(screen.data);
|
||||
depth.rem; xcb_render_pictdepth_next(&depth)) {
|
||||
for (auto pv = xcb_render_pictdepth_visuals_iterator(depth.data); pv.rem;
|
||||
xcb_render_pictvisual_next(&pv)) {
|
||||
for (auto pv = xcb_render_pictdepth_visuals_iterator(depth.data);
|
||||
pv.rem; xcb_render_pictvisual_next(&pv)) {
|
||||
if (pv.data->format == fmt) {
|
||||
return pv.data->visual;
|
||||
}
|
||||
|
@ -163,20 +153,20 @@ x_get_visual_for_pictfmt(xcb_render_query_pict_formats_reply_t *r,
|
|||
return XCB_NONE;
|
||||
}
|
||||
|
||||
xcb_visualid_t
|
||||
x_get_visual_for_standard(xcb_connection_t *c, xcb_pict_standard_t std) {
|
||||
xcb_visualid_t x_get_visual_for_standard(xcb_connection_t *c, xcb_pict_standard_t std) {
|
||||
x_get_server_pictfmts(c);
|
||||
|
||||
auto pictfmt =
|
||||
xcb_render_util_find_standard_format(g_pictfmts, std);
|
||||
auto pictfmt = xcb_render_util_find_standard_format(g_pictfmts, std);
|
||||
|
||||
return x_get_visual_for_pictfmt(g_pictfmts, pictfmt->id);
|
||||
}
|
||||
|
||||
int x_get_visual_depth(xcb_connection_t *c, xcb_visualid_t visual) {
|
||||
auto setup = xcb_get_setup(c);
|
||||
for (auto screen = xcb_setup_roots_iterator(setup); screen.rem; xcb_screen_next(&screen)) {
|
||||
for (auto depth = xcb_screen_allowed_depths_iterator(screen.data); depth.rem; xcb_depth_next(&depth)) {
|
||||
for (auto screen = xcb_setup_roots_iterator(setup); screen.rem;
|
||||
xcb_screen_next(&screen)) {
|
||||
for (auto depth = xcb_screen_allowed_depths_iterator(screen.data);
|
||||
depth.rem; xcb_depth_next(&depth)) {
|
||||
const int len = xcb_depth_visuals_length(depth.data);
|
||||
const xcb_visualtype_t *visuals = xcb_depth_visuals(depth.data);
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
@ -190,11 +180,10 @@ int x_get_visual_depth(xcb_connection_t *c, xcb_visualid_t visual) {
|
|||
}
|
||||
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_pictfmt_and_pixmap(
|
||||
xcb_connection_t *c, const xcb_render_pictforminfo_t * pictfmt,
|
||||
x_create_picture_with_pictfmt_and_pixmap(xcb_connection_t *c,
|
||||
const xcb_render_pictforminfo_t *pictfmt,
|
||||
xcb_pixmap_t pixmap, unsigned long valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr)
|
||||
{
|
||||
const xcb_render_create_picture_value_list_t *attr) {
|
||||
void *buf = NULL;
|
||||
if (attr) {
|
||||
xcb_render_create_picture_value_list_serialize(&buf, valuemask, attr);
|
||||
|
@ -206,8 +195,8 @@ x_create_picture_with_pictfmt_and_pixmap(
|
|||
|
||||
xcb_render_picture_t tmp_picture = xcb_generate_id(c);
|
||||
xcb_generic_error_t *e =
|
||||
xcb_request_check(c, xcb_render_create_picture_checked(c, tmp_picture,
|
||||
pixmap, pictfmt->id, valuemask, buf));
|
||||
xcb_request_check(c, xcb_render_create_picture_checked(
|
||||
c, tmp_picture, pixmap, pictfmt->id, valuemask, buf));
|
||||
free(buf);
|
||||
if (e) {
|
||||
x_print_error(e->full_sequence, e->major_code, e->minor_code, e->error_code);
|
||||
|
@ -218,25 +207,20 @@ x_create_picture_with_pictfmt_and_pixmap(
|
|||
}
|
||||
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_visual_and_pixmap(
|
||||
xcb_connection_t *c, xcb_visualid_t visual,
|
||||
x_create_picture_with_visual_and_pixmap(xcb_connection_t *c, xcb_visualid_t visual,
|
||||
xcb_pixmap_t pixmap, unsigned long valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr)
|
||||
{
|
||||
const xcb_render_create_picture_value_list_t *attr) {
|
||||
const xcb_render_pictforminfo_t *pictfmt = x_get_pictform_for_visual(c, visual);
|
||||
return x_create_picture_with_pictfmt_and_pixmap(c, pictfmt, pixmap, valuemask, attr);
|
||||
}
|
||||
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_standard_and_pixmap(
|
||||
xcb_connection_t *c, xcb_pict_standard_t standard,
|
||||
x_create_picture_with_standard_and_pixmap(xcb_connection_t *c, xcb_pict_standard_t standard,
|
||||
xcb_pixmap_t pixmap, unsigned long valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr)
|
||||
{
|
||||
const xcb_render_create_picture_value_list_t *attr) {
|
||||
x_get_server_pictfmts(c);
|
||||
|
||||
auto pictfmt =
|
||||
xcb_render_util_find_standard_format(g_pictfmts, standard);
|
||||
auto pictfmt = xcb_render_util_find_standard_format(g_pictfmts, standard);
|
||||
assert(pictfmt);
|
||||
return x_create_picture_with_pictfmt_and_pixmap(c, pictfmt, pixmap, valuemask, attr);
|
||||
}
|
||||
|
@ -247,16 +231,15 @@ x_create_picture_with_standard_and_pixmap(
|
|||
xcb_render_picture_t
|
||||
x_create_picture_with_pictfmt(xcb_connection_t *c, xcb_drawable_t d, int wid, int hei,
|
||||
const xcb_render_pictforminfo_t *pictfmt, unsigned long valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr)
|
||||
{
|
||||
const xcb_render_create_picture_value_list_t *attr) {
|
||||
int depth = pictfmt->depth;
|
||||
|
||||
xcb_pixmap_t tmp_pixmap = x_create_pixmap(c, depth, d, wid, hei);
|
||||
if (!tmp_pixmap)
|
||||
return XCB_NONE;
|
||||
|
||||
xcb_render_picture_t picture =
|
||||
x_create_picture_with_pictfmt_and_pixmap(c, pictfmt, tmp_pixmap, valuemask, attr);
|
||||
xcb_render_picture_t picture = x_create_picture_with_pictfmt_and_pixmap(
|
||||
c, pictfmt, tmp_pixmap, valuemask, attr);
|
||||
|
||||
xcb_free_pixmap(c, tmp_pixmap);
|
||||
|
||||
|
@ -266,16 +249,15 @@ x_create_picture_with_pictfmt(xcb_connection_t *c, xcb_drawable_t d, int wid, in
|
|||
xcb_render_picture_t
|
||||
x_create_picture_with_visual(xcb_connection_t *c, xcb_drawable_t d, int w, int h,
|
||||
xcb_visualid_t visual, unsigned long valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr)
|
||||
{
|
||||
const xcb_render_create_picture_value_list_t *attr) {
|
||||
auto pictfmt = x_get_pictform_for_visual(c, visual);
|
||||
return x_create_picture_with_pictfmt(c, d, w, h, pictfmt, valuemask, attr);
|
||||
}
|
||||
|
||||
bool x_fetch_region(xcb_connection_t *c, xcb_xfixes_region_t r, pixman_region32_t *res) {
|
||||
xcb_generic_error_t *e = NULL;
|
||||
xcb_xfixes_fetch_region_reply_t *xr = xcb_xfixes_fetch_region_reply(c,
|
||||
xcb_xfixes_fetch_region(c, r), &e);
|
||||
xcb_xfixes_fetch_region_reply_t *xr =
|
||||
xcb_xfixes_fetch_region_reply(c, xcb_xfixes_fetch_region(c, r), &e);
|
||||
if (!xr) {
|
||||
log_error("Failed to fetch rectangles");
|
||||
return false;
|
||||
|
@ -285,12 +267,10 @@ bool x_fetch_region(xcb_connection_t *c, xcb_xfixes_region_t r, pixman_region32_
|
|||
auto b = ccalloc(nrect, pixman_box32_t);
|
||||
xcb_rectangle_t *xrect = xcb_xfixes_fetch_region_rectangles(xr);
|
||||
for (int i = 0; i < nrect; i++) {
|
||||
b[i] = (pixman_box32_t) {
|
||||
.x1 = xrect[i].x,
|
||||
b[i] = (pixman_box32_t){.x1 = xrect[i].x,
|
||||
.y1 = xrect[i].y,
|
||||
.x2 = xrect[i].x + xrect[i].width,
|
||||
.y2 = xrect[i].y + xrect[i].height
|
||||
};
|
||||
.y2 = xrect[i].y + xrect[i].height};
|
||||
}
|
||||
bool ret = pixman_region32_init_rects(res, b, nrect);
|
||||
free(b);
|
||||
|
@ -312,8 +292,8 @@ void x_set_picture_clip_region(xcb_connection_t *c, xcb_render_picture_t pict,
|
|||
};
|
||||
|
||||
xcb_generic_error_t *e =
|
||||
xcb_request_check(c, xcb_render_set_picture_clip_rectangles_checked(c, pict,
|
||||
clip_x_origin, clip_y_origin, nrects, xrects));
|
||||
xcb_request_check(c, xcb_render_set_picture_clip_rectangles_checked(
|
||||
c, pict, clip_x_origin, clip_y_origin, nrects, xrects));
|
||||
if (e)
|
||||
log_error("Failed to set clip region");
|
||||
free(e);
|
||||
|
@ -322,20 +302,16 @@ void x_set_picture_clip_region(xcb_connection_t *c, xcb_render_picture_t pict,
|
|||
}
|
||||
|
||||
void x_clear_picture_clip_region(xcb_connection_t *c, xcb_render_picture_t pict) {
|
||||
xcb_render_change_picture_value_list_t v = {
|
||||
.clipmask = XCB_NONE
|
||||
};
|
||||
xcb_generic_error_t *e =
|
||||
xcb_request_check(c, xcb_render_change_picture(c, pict,
|
||||
XCB_RENDER_CP_CLIP_MASK, &v));
|
||||
xcb_render_change_picture_value_list_t v = {.clipmask = XCB_NONE};
|
||||
xcb_generic_error_t *e = xcb_request_check(
|
||||
c, xcb_render_change_picture(c, pict, XCB_RENDER_CP_CLIP_MASK, &v));
|
||||
if (e)
|
||||
log_error("failed to clear clip region");
|
||||
free(e);
|
||||
return;
|
||||
}
|
||||
|
||||
enum {
|
||||
XSyncBadCounter = 0,
|
||||
enum { XSyncBadCounter = 0,
|
||||
XSyncBadAlarm = 1,
|
||||
XSyncBadFence = 2,
|
||||
};
|
||||
|
@ -345,31 +321,26 @@ enum {
|
|||
*
|
||||
* XXX consider making this error to string
|
||||
*/
|
||||
void
|
||||
x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_code) {
|
||||
session_t * const ps = ps_g;
|
||||
void x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_code) {
|
||||
session_t *const ps = ps_g;
|
||||
|
||||
int o = 0;
|
||||
const char *name = "Unknown";
|
||||
|
||||
if (major == ps->composite_opcode
|
||||
&& minor == XCB_COMPOSITE_REDIRECT_SUBWINDOWS) {
|
||||
if (major == ps->composite_opcode && minor == XCB_COMPOSITE_REDIRECT_SUBWINDOWS) {
|
||||
log_fatal("Another composite manager is already running "
|
||||
"(and does not handle _NET_WM_CM_Sn correctly)");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#define CASESTRRET2(s) case s: name = #s; break
|
||||
#define CASESTRRET2(s) \
|
||||
case s: name = #s; break
|
||||
|
||||
o = error_code - ps->xfixes_error;
|
||||
switch (o) {
|
||||
CASESTRRET2(XCB_XFIXES_BAD_REGION);
|
||||
}
|
||||
switch (o) { CASESTRRET2(XCB_XFIXES_BAD_REGION); }
|
||||
|
||||
o = error_code - ps->damage_error;
|
||||
switch (o) {
|
||||
CASESTRRET2(XCB_DAMAGE_BAD_DAMAGE);
|
||||
}
|
||||
switch (o) { CASESTRRET2(XCB_DAMAGE_BAD_DAMAGE); }
|
||||
|
||||
o = error_code - ps->render_error;
|
||||
switch (o) {
|
||||
|
@ -426,17 +397,18 @@ x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_
|
|||
|
||||
#undef CASESTRRET2
|
||||
|
||||
log_debug("X error %d %s request %d minor %d serial %lu",
|
||||
error_code, name, major, minor, serial);
|
||||
log_debug("X error %d %s request %d minor %d serial %lu", error_code, name, major,
|
||||
minor, serial);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a pixmap and check that creation succeeded.
|
||||
*/
|
||||
xcb_pixmap_t
|
||||
x_create_pixmap(xcb_connection_t *c, uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height) {
|
||||
xcb_pixmap_t x_create_pixmap(xcb_connection_t *c, uint8_t depth, xcb_drawable_t drawable,
|
||||
uint16_t width, uint16_t height) {
|
||||
xcb_pixmap_t pix = xcb_generate_id(c);
|
||||
xcb_void_cookie_t cookie = xcb_create_pixmap_checked(c, depth, pix, drawable, width, height);
|
||||
xcb_void_cookie_t cookie =
|
||||
xcb_create_pixmap_checked(c, depth, pix, drawable, width, height);
|
||||
xcb_generic_error_t *err = xcb_request_check(c, cookie);
|
||||
if (err == NULL)
|
||||
return pix;
|
||||
|
@ -453,8 +425,7 @@ x_create_pixmap(xcb_connection_t *c, uint8_t depth, xcb_drawable_t drawable, uin
|
|||
* Detect whether the pixmap is valid with XGetGeometry. Well, maybe there
|
||||
* are better ways.
|
||||
*/
|
||||
bool
|
||||
x_validate_pixmap(xcb_connection_t *c, xcb_pixmap_t pixmap) {
|
||||
bool x_validate_pixmap(xcb_connection_t *c, xcb_pixmap_t pixmap) {
|
||||
if (pixmap == XCB_NONE) {
|
||||
return false;
|
||||
}
|
||||
|
@ -537,8 +508,8 @@ bool x_fence_sync(xcb_connection_t *c, xcb_sync_fence_t f) {
|
|||
}
|
||||
|
||||
// xcb-render specific macros
|
||||
#define XFIXED_TO_DOUBLE(value) (((double) (value)) / 65536)
|
||||
#define DOUBLE_TO_XFIXED(value) ((xcb_render_fixed_t) (((double) (value)) * 65536))
|
||||
#define XFIXED_TO_DOUBLE(value) (((double)(value)) / 65536)
|
||||
#define DOUBLE_TO_XFIXED(value) ((xcb_render_fixed_t)(((double)(value)) * 65536))
|
||||
|
||||
/**
|
||||
* Convert a struct conv to a X picture convolution filter, normalizing the kernel
|
||||
|
@ -552,8 +523,8 @@ bool x_fence_sync(xcb_connection_t *c, xcb_sync_fence_t f) {
|
|||
* @param[inout] size size of the array pointed to by `ret`, in number of elements
|
||||
* @return number of elements filled into `*ret`
|
||||
*/
|
||||
size_t x_picture_filter_from_conv(const conv *kernel, double center, xcb_render_fixed_t **ret,
|
||||
size_t *size) {
|
||||
size_t x_picture_filter_from_conv(const conv *kernel, double center,
|
||||
xcb_render_fixed_t **ret, size_t *size) {
|
||||
if (*size < (size_t)(kernel->w * kernel->h + 2)) {
|
||||
*size = kernel->w * kernel->h + 2;
|
||||
*ret = crealloc(*ret, *size);
|
||||
|
@ -573,14 +544,14 @@ size_t x_picture_filter_from_conv(const conv *kernel, double center, xcb_render_
|
|||
buf[i + 2] = DOUBLE_TO_XFIXED(kernel->data[i] * factor);
|
||||
}
|
||||
|
||||
buf[kernel->h / 2 * kernel->w + kernel->w / 2 + 2] = DOUBLE_TO_XFIXED(center * factor);
|
||||
buf[kernel->h / 2 * kernel->w + kernel->w / 2 + 2] =
|
||||
DOUBLE_TO_XFIXED(center * factor);
|
||||
return kernel->w * kernel->h + 2;
|
||||
}
|
||||
|
||||
/// Generate a search criteria for fbconfig from a X visual.
|
||||
/// Returns {-1, -1, -1, -1, -1, -1} on failure
|
||||
struct xvisual_info
|
||||
x_get_visual_info(xcb_connection_t *c, xcb_visualid_t visual) {
|
||||
struct xvisual_info x_get_visual_info(xcb_connection_t *c, xcb_visualid_t visual) {
|
||||
auto pictfmt = x_get_pictform_for_visual(c, visual);
|
||||
auto depth = x_get_visual_depth(c, visual);
|
||||
if (!pictfmt || depth == -1) {
|
||||
|
|
23
src/x.h
23
src/x.h
|
@ -137,16 +137,17 @@ x_create_picture_with_standard_and_pixmap(xcb_connection_t *, xcb_pict_standard_
|
|||
/**
|
||||
* Create an picture.
|
||||
*/
|
||||
xcb_render_picture_t attr_nonnull(1, 5)
|
||||
x_create_picture_with_pictfmt(xcb_connection_t *, xcb_drawable_t, int wid, int hei,
|
||||
const xcb_render_pictforminfo_t *pictfmt,
|
||||
unsigned long valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr);
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_pictfmt(xcb_connection_t *, xcb_drawable_t, int wid, int hei,
|
||||
const xcb_render_pictforminfo_t *pictfmt, unsigned long valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr)
|
||||
attr_nonnull(1, 5);
|
||||
|
||||
xcb_render_picture_t attr_nonnull(1)
|
||||
x_create_picture_with_visual(xcb_connection_t *, xcb_drawable_t, int w, int h,
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_visual(xcb_connection_t *, xcb_drawable_t, int w, int h,
|
||||
xcb_visualid_t visual, unsigned long valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr);
|
||||
const xcb_render_create_picture_value_list_t *attr)
|
||||
attr_nonnull(1);
|
||||
|
||||
/// Fetch a X region and store it in a pixman region
|
||||
bool x_fetch_region(xcb_connection_t *, xcb_xfixes_region_t r, region_t *res);
|
||||
|
@ -206,8 +207,6 @@ size_t x_picture_filter_from_conv(const conv *kernel, double center,
|
|||
|
||||
/// Generate a search criteria for fbconfig from a X visual.
|
||||
/// Returns {-1, -1, -1, -1, -1, -1} on failure
|
||||
struct xvisual_info
|
||||
x_get_visual_info(xcb_connection_t *c, xcb_visualid_t visual);
|
||||
struct xvisual_info x_get_visual_info(xcb_connection_t *c, xcb_visualid_t visual);
|
||||
|
||||
xcb_visualid_t
|
||||
x_get_visual_for_standard(xcb_connection_t *c, xcb_pict_standard_t std);
|
||||
xcb_visualid_t x_get_visual_for_standard(xcb_connection_t *c, xcb_pict_standard_t std);
|
||||
|
|
|
@ -8,22 +8,19 @@
|
|||
|
||||
static xrc_xid_record_t *gs_xid_records = NULL;
|
||||
|
||||
#define HASH_ADD_XID(head, xidfield, add) \
|
||||
HASH_ADD(hh, head, xidfield, sizeof(xid), add)
|
||||
#define HASH_ADD_XID(head, xidfield, add) HASH_ADD(hh, head, xidfield, sizeof(xid), add)
|
||||
|
||||
#define HASH_FIND_XID(head, findxid, out) \
|
||||
HASH_FIND(hh, head, findxid, sizeof(xid), out)
|
||||
#define HASH_FIND_XID(head, findxid, out) HASH_FIND(hh, head, findxid, sizeof(xid), out)
|
||||
|
||||
#define M_CPY_POS_DATA(prec) \
|
||||
prec->file = file; \
|
||||
prec->func = func; \
|
||||
prec->line = line; \
|
||||
prec->line = line;
|
||||
|
||||
/**
|
||||
* @brief Add a record of given XID to the allocation table.
|
||||
*/
|
||||
void
|
||||
xrc_add_xid_(XID xid, const char *type, M_POS_DATA_PARAMS) {
|
||||
void xrc_add_xid_(XID xid, const char *type, M_POS_DATA_PARAMS) {
|
||||
auto prec = ccalloc(1, xrc_xid_record_t);
|
||||
prec->xid = xid;
|
||||
prec->type = type;
|
||||
|
@ -35,8 +32,7 @@ xrc_add_xid_(XID xid, const char *type, M_POS_DATA_PARAMS) {
|
|||
/**
|
||||
* @brief Delete a record of given XID in the allocation table.
|
||||
*/
|
||||
void
|
||||
xrc_delete_xid_(XID xid, M_POS_DATA_PARAMS) {
|
||||
void xrc_delete_xid_(XID xid, M_POS_DATA_PARAMS) {
|
||||
xrc_xid_record_t *prec = NULL;
|
||||
HASH_FIND_XID(gs_xid_records, &xid, prec);
|
||||
if (!prec) {
|
||||
|
@ -51,18 +47,16 @@ xrc_delete_xid_(XID xid, M_POS_DATA_PARAMS) {
|
|||
/**
|
||||
* @brief Report about issues found in the XID allocation table.
|
||||
*/
|
||||
void
|
||||
xrc_report_xid(void) {
|
||||
void xrc_report_xid(void) {
|
||||
for (xrc_xid_record_t *prec = gs_xid_records; prec; prec = prec->hh.next)
|
||||
log_trace("XRC: %s:%d %s(): %#010lx (%s) not freed.\n",
|
||||
prec->file, prec->line, prec->func, prec->xid, prec->type);
|
||||
log_trace("XRC: %s:%d %s(): %#010lx (%s) not freed.\n", prec->file,
|
||||
prec->line, prec->func, prec->xid, prec->type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear the XID allocation table.
|
||||
*/
|
||||
void
|
||||
xrc_clear_xid(void) {
|
||||
void xrc_clear_xid(void) {
|
||||
xrc_xid_record_t *prec = NULL, *ptmp = NULL;
|
||||
HASH_ITER(hh, gs_xid_records, prec, ptmp) {
|
||||
HASH_DEL(gs_xid_records, prec);
|
||||
|
|
|
@ -18,27 +18,23 @@ typedef struct {
|
|||
#define M_POS_DATA_PASSTHROUGH file, line, func
|
||||
#define M_POS_DATA __FILE__, __LINE__, __func__
|
||||
|
||||
void
|
||||
xrc_add_xid_(XID xid, const char *type, M_POS_DATA_PARAMS);
|
||||
void xrc_add_xid_(XID xid, const char *type, M_POS_DATA_PARAMS);
|
||||
|
||||
#define xrc_add_xid(xid, type) xrc_add_xid_(xid, type, M_POS_DATA)
|
||||
|
||||
void
|
||||
xrc_delete_xid_(XID xid, M_POS_DATA_PARAMS);
|
||||
void xrc_delete_xid_(XID xid, M_POS_DATA_PARAMS);
|
||||
|
||||
#define xrc_delete_xid(xid) xrc_delete_xid_(xid, M_POS_DATA)
|
||||
|
||||
void
|
||||
xrc_report_xid(void);
|
||||
void xrc_report_xid(void);
|
||||
|
||||
void
|
||||
xrc_clear_xid(void);
|
||||
void xrc_clear_xid(void);
|
||||
|
||||
// Pixmap
|
||||
|
||||
static inline void
|
||||
xcb_create_pixmap_(xcb_connection_t *c, uint8_t depth, xcb_pixmap_t pixmap,
|
||||
xcb_drawable_t drawable, uint16_t width, uint16_t height, M_POS_DATA_PARAMS) {
|
||||
static inline void xcb_create_pixmap_(xcb_connection_t *c, uint8_t depth,
|
||||
xcb_pixmap_t pixmap, xcb_drawable_t drawable,
|
||||
uint16_t width, uint16_t height, M_POS_DATA_PARAMS) {
|
||||
xcb_create_pixmap(c, depth, pixmap, drawable, width, height);
|
||||
xrc_add_xid_(pixmap, "Pixmap", M_POS_DATA_PASSTHROUGH);
|
||||
}
|
||||
|
@ -47,7 +43,8 @@ xcb_create_pixmap_(xcb_connection_t *c, uint8_t depth, xcb_pixmap_t pixmap,
|
|||
xcb_create_pixmap_(c, depth, pixmap, drawable, width, height, M_POS_DATA)
|
||||
|
||||
static inline xcb_void_cookie_t
|
||||
xcb_composite_name_window_pixmap_(xcb_connection_t *c, xcb_window_t window, xcb_pixmap_t pixmap, M_POS_DATA_PARAMS) {
|
||||
xcb_composite_name_window_pixmap_(xcb_connection_t *c, xcb_window_t window,
|
||||
xcb_pixmap_t pixmap, M_POS_DATA_PARAMS) {
|
||||
xcb_void_cookie_t ret = xcb_composite_name_window_pixmap(c, window, pixmap);
|
||||
xrc_add_xid_(pixmap, "PixmapC", M_POS_DATA_PASSTHROUGH);
|
||||
return ret;
|
||||
|
|
Loading…
Reference in New Issue