You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1322 lines
29 KiB
1322 lines
29 KiB
13 years ago
|
/**
|
||
|
* compton.h
|
||
|
*/
|
||
|
|
||
|
// Throw everything in here.
|
||
|
|
||
12 years ago
|
|
||
|
// === Includes ===
|
||
|
|
||
12 years ago
|
#include "common.h"
|
||
12 years ago
|
|
||
13 years ago
|
#include <math.h>
|
||
12 years ago
|
#include <sys/select.h>
|
||
|
#include <limits.h>
|
||
13 years ago
|
#include <unistd.h>
|
||
|
#include <getopt.h>
|
||
12 years ago
|
#include <locale.h>
|
||
12 years ago
|
#include <signal.h>
|
||
12 years ago
|
|
||
11 years ago
|
#include <sys/types.h>
|
||
|
#include <pwd.h>
|
||
|
|
||
12 years ago
|
#ifdef CONFIG_VSYNC_DRM
|
||
|
#include <fcntl.h>
|
||
|
// We references some definitions in drm.h, which could also be found in
|
||
|
// /usr/src/linux/include/drm/drm.h, but that path is probably even less
|
||
|
// reliable than libdrm
|
||
12 years ago
|
#include <drm.h>
|
||
12 years ago
|
#include <sys/ioctl.h>
|
||
|
#include <errno.h>
|
||
|
#endif
|
||
|
|
||
12 years ago
|
// == Functions ==
|
||
13 years ago
|
|
||
12 years ago
|
// inline functions must be made static to compile correctly under clang:
|
||
|
// http://clang.llvm.org/compatibility.html#inline
|
||
|
|
||
12 years ago
|
// Helper functions
|
||
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
discard_ignore(session_t *ps, unsigned long sequence);
|
||
12 years ago
|
|
||
|
static void
|
||
12 years ago
|
set_ignore(session_t *ps, unsigned long sequence);
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Ignore X errors caused by next X request.
|
||
|
*/
|
||
12 years ago
|
static inline void
|
||
|
set_ignore_next(session_t *ps) {
|
||
|
set_ignore(ps, NextRequest(ps->dpy));
|
||
|
}
|
||
12 years ago
|
|
||
|
static int
|
||
12 years ago
|
should_ignore(session_t *ps, unsigned long sequence);
|
||
12 years ago
|
|
||
12 years ago
|
/**
|
||
|
* Reset filter on a <code>Picture</code>.
|
||
|
*/
|
||
|
static inline void
|
||
|
xrfilter_reset(session_t *ps, Picture p) {
|
||
|
XRenderSetPictureFilter(ps->dpy, p, "Nearest", NULL, 0);
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Subtract two unsigned long values.
|
||
|
*
|
||
|
* Truncate to 0 if the result is negative.
|
||
|
*/
|
||
12 years ago
|
static inline unsigned long __attribute__((const))
|
||
12 years ago
|
sub_unslong(unsigned long a, unsigned long b) {
|
||
|
return (a > b) ? a - b : 0;
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
12 years ago
|
* Set a <code>bool</code> array of all wintypes to true.
|
||
12 years ago
|
*/
|
||
12 years ago
|
static inline void
|
||
12 years ago
|
wintype_arr_enable(bool arr[]) {
|
||
|
wintype_t i;
|
||
12 years ago
|
|
||
|
for (i = 0; i < NUM_WINTYPES; ++i) {
|
||
12 years ago
|
arr[i] = true;
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Set a <code>switch_t</code> array of all unset wintypes to true.
|
||
|
*/
|
||
|
static inline void
|
||
|
wintype_arr_enable_unset(switch_t arr[]) {
|
||
|
wintype_t i;
|
||
|
|
||
|
for (i = 0; i < NUM_WINTYPES; ++i)
|
||
|
if (UNSET == arr[i])
|
||
|
arr[i] = ON;
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Check if a window ID exists in an array of window IDs.
|
||
|
*
|
||
|
* @param arr the array of window IDs
|
||
|
* @param count amount of elements in the array
|
||
|
* @param wid window ID to search for
|
||
|
*/
|
||
12 years ago
|
static inline bool
|
||
12 years ago
|
array_wid_exists(const Window *arr, int count, Window wid) {
|
||
12 years ago
|
while (count--) {
|
||
12 years ago
|
if (arr[count] == wid) {
|
||
12 years ago
|
return true;
|
||
12 years ago
|
}
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
12 years ago
|
return false;
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
12 years ago
|
/**
|
||
|
* Convert a geometry_t value to XRectangle.
|
||
|
*/
|
||
|
static inline XRectangle
|
||
|
geom_to_rect(session_t *ps, const geometry_t *src, const XRectangle *def) {
|
||
|
XRectangle rect_def = { .x = 0, .y = 0,
|
||
|
.width = ps->root_width, .height = ps->root_height };
|
||
|
if (!def) def = &rect_def;
|
||
|
|
||
|
XRectangle rect = { .x = src->x, .y = src->y,
|
||
|
.width = src->wid, .height = src->hei };
|
||
|
if (src->wid < 0) rect.width = def->width;
|
||
|
if (src->hei < 0) rect.height = def->height;
|
||
|
if (-1 == src->x) rect.x = def->x;
|
||
|
else if (src->x < 0) rect.x = ps->root_width + rect.x + 2 - rect.width;
|
||
|
if (-1 == src->y) rect.y = def->y;
|
||
|
else if (src->y < 0) rect.y = ps->root_height + rect.y + 2 - rect.height;
|
||
|
return rect;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Convert a XRectangle to a XServerRegion.
|
||
|
*/
|
||
|
static inline XserverRegion
|
||
|
rect_to_reg(session_t *ps, const XRectangle *src) {
|
||
|
if (!src) return None;
|
||
|
XRectangle bound = { .x = 0, .y = 0,
|
||
|
.width = ps->root_width, .height = ps->root_height };
|
||
|
XRectangle res = { };
|
||
|
rect_crop(&res, src, &bound);
|
||
|
if (res.width && res.height)
|
||
|
return XFixesCreateRegion(ps->dpy, &res, 1);
|
||
|
return None;
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Destroy a <code>Picture</code>.
|
||
|
*/
|
||
|
inline static void
|
||
12 years ago
|
free_picture(session_t *ps, Picture *p) {
|
||
12 years ago
|
if (*p) {
|
||
12 years ago
|
XRenderFreePicture(ps->dpy, *p);
|
||
12 years ago
|
*p = None;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Destroy a <code>Pixmap</code>.
|
||
|
*/
|
||
|
inline static void
|
||
12 years ago
|
free_pixmap(session_t *ps, Pixmap *p) {
|
||
12 years ago
|
if (*p) {
|
||
12 years ago
|
XFreePixmap(ps->dpy, *p);
|
||
12 years ago
|
*p = None;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Destroy a <code>Damage</code>.
|
||
|
*/
|
||
|
inline static void
|
||
12 years ago
|
free_damage(session_t *ps, Damage *p) {
|
||
12 years ago
|
if (*p) {
|
||
12 years ago
|
// BadDamage will be thrown if the window is destroyed
|
||
12 years ago
|
set_ignore_next(ps);
|
||
|
XDamageDestroy(ps->dpy, *p);
|
||
12 years ago
|
*p = None;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
12 years ago
|
* Destroy a condition list.
|
||
12 years ago
|
*/
|
||
12 years ago
|
static inline void
|
||
|
free_wincondlst(c2_lptr_t **pcondlst) {
|
||
12 years ago
|
#ifdef CONFIG_C2
|
||
12 years ago
|
while ((*pcondlst = c2_free_lptr(*pcondlst)))
|
||
|
continue;
|
||
|
#endif
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
11 years ago
|
/**
|
||
|
* Free Xinerama screen info.
|
||
|
*/
|
||
|
static inline void
|
||
|
free_xinerama_info(session_t *ps) {
|
||
|
#ifdef CONFIG_XINERAMA
|
||
|
if (ps->xinerama_scr_regs) {
|
||
|
for (int i = 0; i < ps->xinerama_nscrs; ++i)
|
||
|
free_region(ps, &ps->xinerama_scr_regs[i]);
|
||
|
free(ps->xinerama_scr_regs);
|
||
|
}
|
||
|
cxfree(ps->xinerama_scrs);
|
||
|
ps->xinerama_scrs = NULL;
|
||
|
ps->xinerama_nscrs = 0;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Check whether a paint_t contains enough data.
|
||
|
*/
|
||
|
static inline bool
|
||
|
paint_isvalid(session_t *ps, const paint_t *ppaint) {
|
||
12 years ago
|
// Don't check for presence of Pixmap here, because older X Composite doesn't
|
||
|
// provide it
|
||
|
if (!ppaint)
|
||
12 years ago
|
return false;
|
||
|
|
||
11 years ago
|
if (bkend_use_xrender(ps) && !ppaint->pict)
|
||
12 years ago
|
return false;
|
||
|
|
||
|
#ifdef CONFIG_VSYNC_OPENGL
|
||
12 years ago
|
if (BKEND_GLX == ps->o.backend && !glx_tex_binded(ppaint->ptex, None))
|
||
12 years ago
|
return false;
|
||
|
#endif
|
||
|
|
||
|
return true;
|
||
|
}
|
||
11 years ago
|
|
||
12 years ago
|
/**
|
||
12 years ago
|
* Bind texture in paint_t if we are using GLX backend.
|
||
12 years ago
|
*/
|
||
|
static inline bool
|
||
11 years ago
|
paint_bind_tex_real(session_t *ps, paint_t *ppaint,
|
||
12 years ago
|
unsigned wid, unsigned hei, unsigned depth, bool force) {
|
||
12 years ago
|
#ifdef CONFIG_VSYNC_OPENGL
|
||
11 years ago
|
if (!ppaint->pixmap)
|
||
|
return false;
|
||
12 years ago
|
|
||
11 years ago
|
if (force || !glx_tex_binded(ppaint->ptex, ppaint->pixmap))
|
||
|
return glx_bind_pixmap(ps, &ppaint->ptex, ppaint->pixmap, wid, hei, depth);
|
||
12 years ago
|
#endif
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
11 years ago
|
static inline bool
|
||
|
paint_bind_tex(session_t *ps, paint_t *ppaint,
|
||
|
unsigned wid, unsigned hei, unsigned depth, bool force) {
|
||
|
if (BKEND_GLX == ps->o.backend)
|
||
|
return paint_bind_tex_real(ps, ppaint, wid, hei, depth, force);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Free data in a reg_data_t.
|
||
|
*/
|
||
|
static inline void
|
||
|
free_reg_data(reg_data_t *pregd) {
|
||
|
cxfree(pregd->rects);
|
||
|
pregd->rects = NULL;
|
||
|
pregd->nrects = 0;
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Free paint_t.
|
||
|
*/
|
||
|
static inline void
|
||
|
free_paint(session_t *ps, paint_t *ppaint) {
|
||
|
free_texture(ps, &ppaint->ptex);
|
||
|
free_picture(ps, &ppaint->pict);
|
||
|
free_pixmap(ps, &ppaint->pixmap);
|
||
|
}
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Free w->paint.
|
||
|
*/
|
||
|
static inline void
|
||
|
free_wpaint(session_t *ps, win *w) {
|
||
|
free_paint(ps, &w->paint);
|
||
|
free_fence(ps, &w->fence);
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Destroy all resources in a <code>struct _win</code>.
|
||
|
*/
|
||
12 years ago
|
static inline void
|
||
12 years ago
|
free_win_res(session_t *ps, win *w) {
|
||
|
free_region(ps, &w->extents);
|
||
12 years ago
|
free_paint(ps, &w->paint);
|
||
12 years ago
|
free_region(ps, &w->border_size);
|
||
12 years ago
|
free_paint(ps, &w->shadow_paint);
|
||
12 years ago
|
free_damage(ps, &w->damage);
|
||
|
free_region(ps, &w->reg_ignore);
|
||
|
free(w->name);
|
||
|
free(w->class_instance);
|
||
|
free(w->class_general);
|
||
12 years ago
|
free(w->role);
|
||
12 years ago
|
#ifdef CONFIG_VSYNC_OPENGL_GLSL
|
||
|
free_glx_bc(ps, &w->glx_blur_cache);
|
||
|
#endif
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Free root tile related things.
|
||
|
*/
|
||
|
static inline void
|
||
|
free_root_tile(session_t *ps) {
|
||
|
free_picture(ps, &ps->root_tile_paint.pict);
|
||
|
free_texture(ps, &ps->root_tile_paint.ptex);
|
||
|
if (ps->root_tile_fill)
|
||
|
free_pixmap(ps, &ps->root_tile_paint.pixmap);
|
||
|
ps->root_tile_paint.pixmap = None;
|
||
|
ps->root_tile_fill = false;
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Get current system clock in milliseconds.
|
||
|
*/
|
||
12 years ago
|
static inline time_ms_t
|
||
12 years ago
|
get_time_ms(void) {
|
||
|
struct timeval tv;
|
||
|
|
||
|
gettimeofday(&tv, NULL);
|
||
|
|
||
12 years ago
|
return tv.tv_sec % SEC_WRAP * 1000 + tv.tv_usec / 1000;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Convert time from milliseconds to struct timeval.
|
||
|
*/
|
||
|
static inline struct timeval
|
||
|
ms_to_tv(int timeout) {
|
||
|
return (struct timeval) {
|
||
|
.tv_sec = timeout / MS_PER_SEC,
|
||
|
.tv_usec = timeout % MS_PER_SEC * (US_PER_SEC / MS_PER_SEC)
|
||
|
};
|
||
12 years ago
|
}
|
||
13 years ago
|
|
||
11 years ago
|
/**
|
||
|
* Whether an event is DamageNotify.
|
||
|
*/
|
||
|
static inline bool
|
||
|
isdamagenotify(session_t *ps, const XEvent *ev) {
|
||
|
return ps->damage_event + XDamageNotify == ev->type;
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Create a XTextProperty of a single string.
|
||
|
*/
|
||
|
static inline XTextProperty *
|
||
|
make_text_prop(session_t *ps, char *str) {
|
||
11 years ago
|
XTextProperty *pprop = cmalloc(1, XTextProperty);
|
||
12 years ago
|
|
||
|
if (XmbTextListToTextProperty(ps->dpy, &str, 1, XStringStyle, pprop)) {
|
||
12 years ago
|
cxfree(pprop->value);
|
||
12 years ago
|
free(pprop);
|
||
|
pprop = NULL;
|
||
|
}
|
||
|
|
||
|
return pprop;
|
||
|
}
|
||
|
|
||
11 years ago
|
|
||
|
/**
|
||
|
* Set a single-string text property on a window.
|
||
|
*/
|
||
|
static inline bool
|
||
|
wid_set_text_prop(session_t *ps, Window wid, Atom prop_atom, char *str) {
|
||
|
XTextProperty *pprop = make_text_prop(ps, str);
|
||
|
if (!pprop) {
|
||
|
printf_errf("(\"%s\"): Failed to make text property.", str);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
XSetTextProperty(ps->dpy, wid, pprop, prop_atom);
|
||
|
cxfree(pprop->value);
|
||
|
cxfree(pprop);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
12 years ago
|
run_fade(session_t *ps, win *w, unsigned steps);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
set_fade_callback(session_t *ps, win *w,
|
||
|
void (*callback) (session_t *ps, win *w), bool exec_callback);
|
||
13 years ago
|
|
||
12 years ago
|
/**
|
||
|
* Execute fade callback of a window if fading finished.
|
||
|
*/
|
||
|
static inline void
|
||
12 years ago
|
check_fade_fin(session_t *ps, win *w) {
|
||
12 years ago
|
if (w->fade_callback && w->opacity == w->opacity_tgt) {
|
||
12 years ago
|
// Must be the last line as the callback could destroy w!
|
||
12 years ago
|
set_fade_callback(ps, w, NULL, true);
|
||
12 years ago
|
}
|
||
|
}
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
set_fade_callback(session_t *ps, win *w,
|
||
|
void (*callback) (session_t *ps, win *w), bool exec_callback);
|
||
13 years ago
|
|
||
|
static double
|
||
|
gaussian(double r, double x, double y);
|
||
|
|
||
|
static conv *
|
||
12 years ago
|
make_gaussian_map(double r);
|
||
13 years ago
|
|
||
|
static unsigned char
|
||
|
sum_gaussian(conv *map, double opacity,
|
||
|
int x, int y, int width, int height);
|
||
|
|
||
|
static void
|
||
12 years ago
|
presum_gaussian(session_t *ps, conv *map);
|
||
13 years ago
|
|
||
|
static XImage *
|
||
12 years ago
|
make_shadow(session_t *ps, double opacity, int width, int height);
|
||
13 years ago
|
|
||
12 years ago
|
static bool
|
||
|
win_build_shadow(session_t *ps, win *w, double opacity);
|
||
13 years ago
|
|
||
|
static Picture
|
||
12 years ago
|
solid_picture(session_t *ps, bool argb, double a,
|
||
13 years ago
|
double r, double g, double b);
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Stop listening for events on a particular window.
|
||
|
*/
|
||
|
static inline void
|
||
|
win_ev_stop(session_t *ps, win *w) {
|
||
|
// Will get BadWindow if the window is destroyed
|
||
|
set_ignore_next(ps);
|
||
|
XSelectInput(ps->dpy, w->id, 0);
|
||
|
|
||
|
if (w->client_win) {
|
||
|
set_ignore_next(ps);
|
||
|
XSelectInput(ps->dpy, w->client_win, 0);
|
||
|
}
|
||
|
|
||
|
if (ps->shape_exists) {
|
||
|
set_ignore_next(ps);
|
||
|
XShapeSelectInput(ps->dpy, w->id, 0);
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Get the children of a window.
|
||
|
*
|
||
12 years ago
|
* @param ps current session
|
||
12 years ago
|
* @param w window to check
|
||
|
* @param children [out] an array of child window IDs
|
||
|
* @param nchildren [out] number of children
|
||
|
* @return 1 if successful, 0 otherwise
|
||
|
*/
|
||
12 years ago
|
static inline bool
|
||
|
wid_get_children(session_t *ps, Window w,
|
||
12 years ago
|
Window **children, unsigned *nchildren) {
|
||
|
Window troot, tparent;
|
||
|
|
||
12 years ago
|
if (!XQueryTree(ps->dpy, w, &troot, &tparent, children, nchildren)) {
|
||
12 years ago
|
*nchildren = 0;
|
||
12 years ago
|
return false;
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
return true;
|
||
12 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Check if a window is bounding-shaped.
|
||
|
*/
|
||
12 years ago
|
static inline bool
|
||
|
wid_bounding_shaped(const session_t *ps, Window wid) {
|
||
|
if (ps->shape_exists) {
|
||
|
Bool bounding_shaped = False, clip_shaped = False;
|
||
12 years ago
|
int x_bounding, y_bounding, x_clip, y_clip;
|
||
|
unsigned int w_bounding, h_bounding, w_clip, h_clip;
|
||
|
|
||
12 years ago
|
XShapeQueryExtents(ps->dpy, wid, &bounding_shaped,
|
||
12 years ago
|
&x_bounding, &y_bounding, &w_bounding, &h_bounding,
|
||
|
&clip_shaped, &x_clip, &y_clip, &w_clip, &h_clip);
|
||
|
return bounding_shaped;
|
||
|
}
|
||
12 years ago
|
|
||
|
return false;
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
12 years ago
|
* Determine if a window change affects <code>reg_ignore</code> and set
|
||
|
* <code>reg_ignore_expire</code> accordingly.
|
||
12 years ago
|
*/
|
||
12 years ago
|
static inline void
|
||
12 years ago
|
update_reg_ignore_expire(session_t *ps, const win *w) {
|
||
12 years ago
|
if (w->to_paint && WMODE_SOLID == w->mode)
|
||
12 years ago
|
ps->reg_ignore_expire = true;
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Check whether a window has WM frames.
|
||
|
*/
|
||
12 years ago
|
static inline bool __attribute__((const))
|
||
12 years ago
|
win_has_frame(const win *w) {
|
||
12 years ago
|
return w->a.border_width
|
||
|
|| w->top_width || w->left_width || w->right_width || w->bottom_width;
|
||
|
}
|
||
|
|
||
12 years ago
|
static inline void
|
||
11 years ago
|
wid_set_opacity_prop(session_t *ps, Window wid, opacity_t val) {
|
||
|
const unsigned long v = val;
|
||
12 years ago
|
XChangeProperty(ps->dpy, wid, ps->atom_opacity, XA_CARDINAL, 32,
|
||
11 years ago
|
PropModeReplace, (unsigned char *) &v, 1);
|
||
12 years ago
|
}
|
||
|
|
||
|
static inline void
|
||
|
wid_rm_opacity_prop(session_t *ps, Window wid) {
|
||
|
XDeleteProperty(ps->dpy, wid, ps->atom_opacity);
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Dump an drawable's info.
|
||
|
*/
|
||
|
static inline void
|
||
|
dump_drawable(session_t *ps, Drawable drawable) {
|
||
|
Window rroot = None;
|
||
|
int x = 0, y = 0;
|
||
|
unsigned width = 0, height = 0, border = 0, depth = 0;
|
||
|
if (XGetGeometry(ps->dpy, drawable, &rroot, &x, &y, &width, &height,
|
||
|
&border, &depth)) {
|
||
|
printf_dbgf("(%#010lx): x = %u, y = %u, wid = %u, hei = %d, b = %u, d = %u\n", drawable, x, y, width, height, border, depth);
|
||
|
}
|
||
|
else {
|
||
|
printf_dbgf("(%#010lx): Failed\n", drawable);
|
||
|
}
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
win_rounded_corners(session_t *ps, win *w);
|
||
12 years ago
|
|
||
12 years ago
|
/**
|
||
|
* Validate a pixmap.
|
||
|
*
|
||
|
* Detect whether the pixmap is valid with XGetGeometry. Well, maybe there
|
||
|
* are better ways.
|
||
|
*/
|
||
|
static inline bool
|
||
|
validate_pixmap(session_t *ps, Pixmap pxmap) {
|
||
|
if (!pxmap) return false;
|
||
|
|
||
|
Window rroot = None;
|
||
|
int rx = 0, ry = 0;
|
||
|
unsigned rwid = 0, rhei = 0, rborder = 0, rdepth = 0;
|
||
|
return XGetGeometry(ps->dpy, pxmap, &rroot, &rx, &ry,
|
||
|
&rwid, &rhei, &rborder, &rdepth) && rwid && rhei;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Validate pixmap of a window, and destroy pixmap and picture if invalid.
|
||
|
*/
|
||
|
static inline void
|
||
|
win_validate_pixmap(session_t *ps, win *w) {
|
||
|
// Destroy pixmap and picture, if invalid
|
||
|
if (!validate_pixmap(ps, w->paint.pixmap))
|
||
|
free_paint(ps, &w->paint);
|
||
|
}
|
||
12 years ago
|
|
||
12 years ago
|
/**
|
||
|
* Wrapper of c2_match().
|
||
|
*/
|
||
|
static inline bool
|
||
|
win_match(session_t *ps, win *w, c2_lptr_t *condlst, const c2_lptr_t **cache) {
|
||
|
#ifdef CONFIG_C2
|
||
|
return c2_match(ps, w, condlst, cache);
|
||
|
#else
|
||
|
return false;
|
||
|
#endif
|
||
|
}
|
||
12 years ago
|
|
||
12 years ago
|
static bool
|
||
12 years ago
|
condlst_add(session_t *ps, c2_lptr_t **pcondlst, const char *pattern);
|
||
12 years ago
|
|
||
12 years ago
|
static long
|
||
12 years ago
|
determine_evmask(session_t *ps, Window wid, win_evmode_t mode);
|
||
12 years ago
|
|
||
12 years ago
|
/**
|
||
|
* Clear leader cache of all windows.
|
||
|
*/
|
||
|
static void
|
||
|
clear_cache_win_leaders(session_t *ps) {
|
||
|
for (win *w = ps->list; w; w = w->next)
|
||
|
w->cache_leader = None;
|
||
|
}
|
||
13 years ago
|
|
||
12 years ago
|
static win *
|
||
12 years ago
|
find_toplevel2(session_t *ps, Window wid);
|
||
12 years ago
|
|
||
11 years ago
|
/**
|
||
|
* Find matched window.
|
||
|
*/
|
||
|
static inline win *
|
||
|
find_win_all(session_t *ps, const Window wid) {
|
||
|
if (!wid || PointerRoot == wid || wid == ps->root || wid == ps->overlay)
|
||
|
return NULL;
|
||
|
|
||
|
win *w = find_win(ps, wid);
|
||
|
if (!w) w = find_toplevel(ps, wid);
|
||
|
if (!w) w = find_toplevel2(ps, wid);
|
||
|
return w;
|
||
|
}
|
||
|
|
||
12 years ago
|
static Window
|
||
|
win_get_leader_raw(session_t *ps, win *w, int recursions);
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Get the leader of a window.
|
||
|
*
|
||
|
* This function updates w->cache_leader if necessary.
|
||
|
*/
|
||
|
static inline Window
|
||
|
win_get_leader(session_t *ps, win *w) {
|
||
|
return win_get_leader_raw(ps, w, 0);
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Return whether a window group is really focused.
|
||
|
*
|
||
|
* @param leader leader window ID
|
||
|
* @return true if the window group is focused, false otherwise
|
||
|
*/
|
||
|
static inline bool
|
||
|
group_is_focused(session_t *ps, Window leader) {
|
||
|
if (!leader)
|
||
|
return false;
|
||
|
|
||
|
for (win *w = ps->list; w; w = w->next) {
|
||
|
if (win_get_leader(ps, w) == leader && !w->destroyed
|
||
11 years ago
|
&& win_is_focused_real(ps, w))
|
||
12 years ago
|
return true;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
12 years ago
|
static win *
|
||
12 years ago
|
recheck_focus(session_t *ps);
|
||
12 years ago
|
|
||
12 years ago
|
static bool
|
||
|
get_root_tile(session_t *ps);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
paint_root(session_t *ps, XserverRegion reg_paint);
|
||
13 years ago
|
|
||
12 years ago
|
static XserverRegion
|
||
|
win_get_region(session_t *ps, win *w, bool use_offset);
|
||
|
|
||
|
static XserverRegion
|
||
|
win_get_region_noframe(session_t *ps, win *w, bool use_offset);
|
||
|
|
||
13 years ago
|
static XserverRegion
|
||
12 years ago
|
win_extents(session_t *ps, win *w);
|
||
13 years ago
|
|
||
|
static XserverRegion
|
||
12 years ago
|
border_size(session_t *ps, win *w, bool use_offset);
|
||
13 years ago
|
|
||
12 years ago
|
static Window
|
||
12 years ago
|
find_client_win(session_t *ps, Window w);
|
||
12 years ago
|
|
||
13 years ago
|
static void
|
||
12 years ago
|
get_frame_extents(session_t *ps, win *w, Window client);
|
||
13 years ago
|
|
||
12 years ago
|
static win *
|
||
12 years ago
|
paint_preprocess(session_t *ps, win *list);
|
||
12 years ago
|
|
||
12 years ago
|
static void
|
||
|
render(session_t *ps, int x, int y, int dx, int dy, int wid, int hei,
|
||
|
double opacity, bool argb, bool neg,
|
||
12 years ago
|
Picture pict, glx_texture_t *ptex,
|
||
|
XserverRegion reg_paint, const reg_data_t *pcache_reg);
|
||
12 years ago
|
|
||
|
static inline void
|
||
12 years ago
|
win_render(session_t *ps, win *w, int x, int y, int wid, int hei, double opacity, XserverRegion reg_paint, const reg_data_t *pcache_reg, Picture pict) {
|
||
12 years ago
|
const int dx = (w ? w->a.x: 0) + x;
|
||
|
const int dy = (w ? w->a.y: 0) + y;
|
||
|
const bool argb = (w && w->mode == WMODE_ARGB);
|
||
|
const bool neg = (w && w->invert_color);
|
||
|
|
||
|
render(ps, x, y, dx, dy, wid, hei, opacity, argb, neg,
|
||
12 years ago
|
pict, (w ? w->paint.ptex: ps->root_tile_paint.ptex), reg_paint, pcache_reg);
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
static inline void
|
||
12 years ago
|
set_tgt_clip(session_t *ps, XserverRegion reg, const reg_data_t *pcache_reg) {
|
||
12 years ago
|
switch (ps->o.backend) {
|
||
|
case BKEND_XRENDER:
|
||
11 years ago
|
case BKEND_XR_GLX_HYBRID:
|
||
11 years ago
|
XFixesSetPictureClipRegion(ps->dpy, ps->tgt_buffer.pict, 0, 0, reg);
|
||
12 years ago
|
break;
|
||
|
#ifdef CONFIG_VSYNC_OPENGL
|
||
|
case BKEND_GLX:
|
||
12 years ago
|
glx_set_clip(ps, reg, pcache_reg);
|
||
12 years ago
|
break;
|
||
|
#endif
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
static bool
|
||
|
xr_blur_dst(session_t *ps, Picture tgt_buffer,
|
||
|
int x, int y, int wid, int hei, XFixed **blur_kerns,
|
||
|
XserverRegion reg_clip);
|
||
|
|
||
|
/**
|
||
|
* Normalize a convolution kernel.
|
||
|
*/
|
||
|
static inline void
|
||
|
normalize_conv_kern(int wid, int hei, XFixed *kern) {
|
||
|
double sum = 0.0;
|
||
|
for (int i = 0; i < wid * hei; ++i)
|
||
|
sum += XFixedToDouble(kern[i]);
|
||
|
double factor = 1.0 / sum;
|
||
|
for (int i = 0; i < wid * hei; ++i)
|
||
|
kern[i] = XDoubleToFixed(XFixedToDouble(kern[i]) * factor);
|
||
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
12 years ago
|
paint_all(session_t *ps, XserverRegion region, XserverRegion region_real, win *t);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
add_damage(session_t *ps, XserverRegion damage);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
repair_win(session_t *ps, win *w);
|
||
13 years ago
|
|
||
12 years ago
|
static wintype_t
|
||
|
wid_get_prop_wintype(session_t *ps, Window w);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
map_win(session_t *ps, Window id);
|
||
13 years ago
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
finish_map_win(session_t *ps, win *w);
|
||
12 years ago
|
|
||
13 years ago
|
static void
|
||
12 years ago
|
finish_unmap_win(session_t *ps, win *w);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
unmap_callback(session_t *ps, win *w);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
unmap_win(session_t *ps, win *w);
|
||
13 years ago
|
|
||
12 years ago
|
static opacity_t
|
||
12 years ago
|
wid_get_opacity_prop(session_t *ps, Window wid, opacity_t def);
|
||
13 years ago
|
|
||
11 years ago
|
static bool
|
||
|
init_filters(session_t *ps);
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Reread opacity property of a window.
|
||
|
*/
|
||
|
static inline void
|
||
|
win_update_opacity_prop(session_t *ps, win *w) {
|
||
|
w->opacity_prop = wid_get_opacity_prop(ps, w->id, OPAQUE);
|
||
|
if (!ps->o.detect_client_opacity || !w->client_win
|
||
|
|| w->id == w->client_win)
|
||
|
w->opacity_prop_client = OPAQUE;
|
||
|
else
|
||
|
w->opacity_prop_client = wid_get_opacity_prop(ps, w->client_win,
|
||
|
OPAQUE);
|
||
|
}
|
||
|
|
||
13 years ago
|
static double
|
||
12 years ago
|
get_opacity_percent(win *w);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
win_determine_mode(session_t *ps, win *w);
|
||
13 years ago
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
calc_opacity(session_t *ps, win *w);
|
||
13 years ago
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
calc_dim(session_t *ps, win *w);
|
||
12 years ago
|
|
||
12 years ago
|
static Window
|
||
|
wid_get_prop_window(session_t *ps, Window wid, Atom aprop);
|
||
|
|
||
|
static void
|
||
|
win_update_leader(session_t *ps, win *w);
|
||
|
|
||
|
static void
|
||
|
win_set_leader(session_t *ps, win *w, Window leader);
|
||
|
|
||
12 years ago
|
static void
|
||
|
win_update_focused(session_t *ps, win *w);
|
||
12 years ago
|
|
||
12 years ago
|
/**
|
||
|
* Run win_update_focused() on all windows with the same leader window.
|
||
|
*
|
||
|
* @param leader leader window ID
|
||
|
*/
|
||
|
static inline void
|
||
|
group_update_focused(session_t *ps, Window leader) {
|
||
|
if (!leader)
|
||
|
return;
|
||
|
|
||
|
for (win *w = ps->list; w; w = w->next) {
|
||
|
if (win_get_leader(ps, w) == leader && !w->destroyed)
|
||
|
win_update_focused(ps, w);
|
||
|
}
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
static inline void
|
||
12 years ago
|
win_set_focused(session_t *ps, win *w, bool focused);
|
||
12 years ago
|
|
||
11 years ago
|
static void
|
||
|
win_on_focus_change(session_t *ps, win *w);
|
||
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
win_determine_fade(session_t *ps, win *w);
|
||
12 years ago
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
win_update_shape_raw(session_t *ps, win *w);
|
||
12 years ago
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
win_update_shape(session_t *ps, win *w);
|
||
12 years ago
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
win_update_prop_shadow_raw(session_t *ps, win *w);
|
||
12 years ago
|
|
||
|
static void
|
||
12 years ago
|
win_update_prop_shadow(session_t *ps, win *w);
|
||
12 years ago
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
win_determine_shadow(session_t *ps, win *w);
|
||
|
|
||
12 years ago
|
static void
|
||
|
win_determine_invert_color(session_t *ps, win *w);
|
||
|
|
||
|
static void
|
||
|
win_determine_blur_background(session_t *ps, win *w);
|
||
|
|
||
12 years ago
|
static void
|
||
|
win_on_wtype_change(session_t *ps, win *w);
|
||
|
|
||
|
static void
|
||
12 years ago
|
win_on_factor_change(session_t *ps, win *w);
|
||
12 years ago
|
|
||
|
static void
|
||
|
win_upd_run(session_t *ps, win *w, win_upd_t *pupd);
|
||
12 years ago
|
|
||
|
static void
|
||
12 years ago
|
calc_win_size(session_t *ps, win *w);
|
||
12 years ago
|
|
||
|
static void
|
||
12 years ago
|
calc_shadow_geometry(session_t *ps, win *w);
|
||
12 years ago
|
|
||
11 years ago
|
static void
|
||
|
win_upd_wintype(session_t *ps, win *w);
|
||
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
win_mark_client(session_t *ps, win *w, Window client);
|
||
|
|
||
|
static void
|
||
|
win_unmark_client(session_t *ps, win *w);
|
||
|
|
||
|
static void
|
||
|
win_recheck_client(session_t *ps, win *w);
|
||
12 years ago
|
|
||
12 years ago
|
static bool
|
||
12 years ago
|
add_win(session_t *ps, Window id, Window prev);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
restack_win(session_t *ps, win *w, Window new_above);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
configure_win(session_t *ps, XConfigureEvent *ce);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
circulate_win(session_t *ps, XCirculateEvent *ce);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
finish_destroy_win(session_t *ps, Window id);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
destroy_callback(session_t *ps, win *w);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
destroy_win(session_t *ps, Window id);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
damage_win(session_t *ps, XDamageNotifyEvent *de);
|
||
13 years ago
|
|
||
|
static int
|
||
11 years ago
|
xerror(Display *dpy, XErrorEvent *ev);
|
||
13 years ago
|
|
||
|
static void
|
||
12 years ago
|
expose_root(session_t *ps, XRectangle *rects, int nrects);
|
||
13 years ago
|
|
||
12 years ago
|
static Window
|
||
|
wid_get_prop_window(session_t *ps, Window wid, Atom aprop);
|
||
|
|
||
12 years ago
|
static bool
|
||
|
wid_get_name(session_t *ps, Window w, char **name);
|
||
12 years ago
|
|
||
12 years ago
|
static bool
|
||
|
wid_get_role(session_t *ps, Window w, char **role);
|
||
|
|
||
12 years ago
|
static int
|
||
12 years ago
|
win_get_prop_str(session_t *ps, win *w, char **tgt,
|
||
|
bool (*func_wid_get_prop_str)(session_t *ps, Window wid, char **tgt));
|
||
|
|
||
|
static inline int
|
||
|
win_get_name(session_t *ps, win *w) {
|
||
|
int ret = win_get_prop_str(ps, w, &w->name, wid_get_name);
|
||
|
|
||
|
#ifdef DEBUG_WINDATA
|
||
|
printf_dbgf("(%#010lx): client = %#010lx, name = \"%s\", "
|
||
|
"ret = %d\n", w->id, w->client_win, w->name, ret);
|
||
|
#endif
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
static inline int
|
||
|
win_get_role(session_t *ps, win *w) {
|
||
|
int ret = win_get_prop_str(ps, w, &w->role, wid_get_role);
|
||
|
|
||
|
#ifdef DEBUG_WINDATA
|
||
|
printf_dbgf("(%#010lx): client = %#010lx, role = \"%s\", "
|
||
|
"ret = %d\n", w->id, w->client_win, w->role, ret);
|
||
|
#endif
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
12 years ago
|
|
||
12 years ago
|
static bool
|
||
|
win_get_class(session_t *ps, win *w);
|
||
12 years ago
|
|
||
|
#ifdef DEBUG_EVENTS
|
||
13 years ago
|
static int
|
||
|
ev_serial(XEvent *ev);
|
||
|
|
||
12 years ago
|
static const char *
|
||
12 years ago
|
ev_name(session_t *ps, XEvent *ev);
|
||
13 years ago
|
|
||
|
static Window
|
||
12 years ago
|
ev_window(session_t *ps, XEvent *ev);
|
||
13 years ago
|
#endif
|
||
|
|
||
12 years ago
|
static void __attribute__ ((noreturn))
|
||
12 years ago
|
usage(int ret);
|
||
13 years ago
|
|
||
12 years ago
|
static bool
|
||
12 years ago
|
register_cm(session_t *ps);
|
||
12 years ago
|
|
||
13 years ago
|
inline static void
|
||
12 years ago
|
ev_focus_in(session_t *ps, XFocusChangeEvent *ev);
|
||
13 years ago
|
|
||
|
inline static void
|
||
12 years ago
|
ev_focus_out(session_t *ps, XFocusChangeEvent *ev);
|
||
13 years ago
|
|
||
|
inline static void
|
||
12 years ago
|
ev_create_notify(session_t *ps, XCreateWindowEvent *ev);
|
||
13 years ago
|
|
||
|
inline static void
|
||
12 years ago
|
ev_configure_notify(session_t *ps, XConfigureEvent *ev);
|
||
13 years ago
|
|
||
|
inline static void
|
||
12 years ago
|
ev_destroy_notify(session_t *ps, XDestroyWindowEvent *ev);
|
||
13 years ago
|
|
||
|
inline static void
|
||
12 years ago
|
ev_map_notify(session_t *ps, XMapEvent *ev);
|
||
13 years ago
|
|
||
|
inline static void
|
||
12 years ago
|
ev_unmap_notify(session_t *ps, XUnmapEvent *ev);
|
||
13 years ago
|
|
||
|
inline static void
|
||
12 years ago
|
ev_reparent_notify(session_t *ps, XReparentEvent *ev);
|
||
13 years ago
|
|
||
|
inline static void
|
||
12 years ago
|
ev_circulate_notify(session_t *ps, XCirculateEvent *ev);
|
||
13 years ago
|
|
||
|
inline static void
|
||
12 years ago
|
ev_expose(session_t *ps, XExposeEvent *ev);
|
||
13 years ago
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
update_ewmh_active_win(session_t *ps);
|
||
12 years ago
|
|
||
13 years ago
|
inline static void
|
||
12 years ago
|
ev_property_notify(session_t *ps, XPropertyEvent *ev);
|
||
13 years ago
|
|
||
|
inline static void
|
||
12 years ago
|
ev_damage_notify(session_t *ps, XDamageNotifyEvent *ev);
|
||
13 years ago
|
|
||
12 years ago
|
inline static void
|
||
12 years ago
|
ev_shape_notify(session_t *ps, XShapeEvent *ev);
|
||
12 years ago
|
|
||
12 years ago
|
/**
|
||
|
* Get a region of the screen size.
|
||
|
*/
|
||
12 years ago
|
inline static XserverRegion
|
||
12 years ago
|
get_screen_region(session_t *ps) {
|
||
12 years ago
|
XRectangle r;
|
||
|
|
||
|
r.x = 0;
|
||
|
r.y = 0;
|
||
12 years ago
|
r.width = ps->root_width;
|
||
|
r.height = ps->root_height;
|
||
|
return XFixesCreateRegion(ps->dpy, &r, 1);
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
12 years ago
|
* Resize a region.
|
||
12 years ago
|
*/
|
||
|
static inline void
|
||
12 years ago
|
resize_region(session_t *ps, XserverRegion region, short mod) {
|
||
|
if (!mod || !region) return;
|
||
|
|
||
|
int nrects = 0, nnewrects = 0;
|
||
|
XRectangle *newrects = NULL;
|
||
12 years ago
|
XRectangle *rects = XFixesFetchRegion(ps->dpy, region, &nrects);
|
||
12 years ago
|
if (!rects || !nrects)
|
||
|
goto resize_region_end;
|
||
|
|
||
|
// Allocate memory for new rectangle list, because I don't know if it's
|
||
|
// safe to write in the memory Xlib allocates
|
||
|
newrects = calloc(nrects, sizeof(XRectangle));
|
||
|
if (!newrects) {
|
||
|
printf_errf("(): Failed to allocate memory.");
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
// Loop through all rectangles
|
||
|
for (int i = 0; i < nrects; ++i) {
|
||
|
int x1 = max_i(rects[i].x - mod, 0);
|
||
|
int y1 = max_i(rects[i].y - mod, 0);
|
||
|
int x2 = min_i(rects[i].x + rects[i].width + mod, ps->root_width);
|
||
|
int y2 = min_i(rects[i].y + rects[i].height + mod, ps->root_height);
|
||
|
int wid = x2 - x1;
|
||
|
int hei = y2 - y1;
|
||
|
if (wid <= 0 || hei <= 0)
|
||
|
continue;
|
||
|
newrects[nnewrects].x = x1;
|
||
|
newrects[nnewrects].y = y1;
|
||
|
newrects[nnewrects].width = wid;
|
||
|
newrects[nnewrects].height = hei;
|
||
|
++nnewrects;
|
||
|
}
|
||
|
|
||
|
// Set region
|
||
|
XFixesSetRegion(ps->dpy, region, newrects, nnewrects);
|
||
12 years ago
|
|
||
12 years ago
|
resize_region_end:
|
||
|
cxfree(rects);
|
||
|
free(newrects);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Dump a region.
|
||
|
*/
|
||
|
static inline void
|
||
|
dump_region(const session_t *ps, XserverRegion region) {
|
||
|
int nrects = 0;
|
||
|
XRectangle *rects = NULL;
|
||
|
if (!rects && region)
|
||
|
rects = XFixesFetchRegion(ps->dpy, region, &nrects);
|
||
|
|
||
|
printf_dbgf("(%#010lx): %d rects\n", region, nrects);
|
||
|
if (!rects) return;
|
||
|
for (int i = 0; i < nrects; ++i)
|
||
12 years ago
|
printf("Rect #%d: %8d, %8d, %8d, %8d\n", i, rects[i].x, rects[i].y,
|
||
|
rects[i].width, rects[i].height);
|
||
12 years ago
|
putchar('\n');
|
||
|
fflush(stdout);
|
||
12 years ago
|
|
||
12 years ago
|
cxfree(rects);
|
||
12 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Check if a region is empty.
|
||
|
*
|
||
|
* Keith Packard said this is slow:
|
||
|
* http://lists.freedesktop.org/archives/xorg/2007-November/030467.html
|
||
12 years ago
|
*
|
||
|
* @param ps current session
|
||
|
* @param region region to check for
|
||
12 years ago
|
* @param pcache_rects a place to cache the dumped rectangles
|
||
|
* @param ncache_nrects a place to cache the number of dumped rectangles
|
||
12 years ago
|
*/
|
||
12 years ago
|
static inline bool
|
||
12 years ago
|
is_region_empty(const session_t *ps, XserverRegion region,
|
||
12 years ago
|
reg_data_t *pcache_reg) {
|
||
12 years ago
|
int nrects = 0;
|
||
12 years ago
|
XRectangle *rects = XFixesFetchRegion(ps->dpy, region, &nrects);
|
||
12 years ago
|
|
||
12 years ago
|
if (pcache_reg) {
|
||
|
pcache_reg->rects = rects;
|
||
|
pcache_reg->nrects = nrects;
|
||
|
}
|
||
12 years ago
|
else
|
||
|
cxfree(rects);
|
||
|
|
||
12 years ago
|
return !nrects;
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Add a window to damaged area.
|
||
|
*
|
||
12 years ago
|
* @param ps current session
|
||
12 years ago
|
* @param w struct _win element representing the window
|
||
|
*/
|
||
12 years ago
|
static inline void
|
||
12 years ago
|
add_damage_win(session_t *ps, win *w) {
|
||
12 years ago
|
if (w->extents) {
|
||
12 years ago
|
add_damage(ps, copy_region(ps, w->extents));
|
||
12 years ago
|
}
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
#if defined(DEBUG_EVENTS) || defined(DEBUG_RESTACK)
|
||
|
static bool
|
||
12 years ago
|
ev_window_name(session_t *ps, Window wid, char **name);
|
||
12 years ago
|
#endif
|
||
|
|
||
13 years ago
|
inline static void
|
||
12 years ago
|
ev_handle(session_t *ps, XEvent *ev);
|
||
13 years ago
|
|
||
12 years ago
|
static bool
|
||
12 years ago
|
fork_after(session_t *ps);
|
||
13 years ago
|
|
||
12 years ago
|
#ifdef CONFIG_LIBCONFIG
|
||
12 years ago
|
/**
|
||
|
* Wrapper of libconfig's <code>config_lookup_int</code>.
|
||
|
*
|
||
|
* To convert <code>int</code> value <code>config_lookup_bool</code>
|
||
|
* returns to <code>bool</code>.
|
||
|
*/
|
||
12 years ago
|
static inline void
|
||
12 years ago
|
lcfg_lookup_bool(const config_t *config, const char *path,
|
||
|
bool *value) {
|
||
12 years ago
|
int ival;
|
||
|
|
||
|
if (config_lookup_bool(config, path, &ival))
|
||
|
*value = ival;
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Wrapper of libconfig's <code>config_lookup_int</code>.
|
||
|
*
|
||
|
* To deal with the different value types <code>config_lookup_int</code>
|
||
|
* returns in libconfig-1.3 and libconfig-1.4.
|
||
|
*/
|
||
12 years ago
|
static inline int
|
||
|
lcfg_lookup_int(const config_t *config, const char *path, int *value) {
|
||
|
#ifndef CONFIG_LIBCONFIG_LEGACY
|
||
|
return config_lookup_int(config, path, value);
|
||
|
#else
|
||
|
long lval;
|
||
|
int ret;
|
||
|
|
||
|
if ((ret = config_lookup_int(config, path, &lval)))
|
||
|
*value = lval;
|
||
|
|
||
|
return ret;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
12 years ago
|
static FILE *
|
||
|
open_config_file(char *cpath, char **path);
|
||
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
parse_cfg_condlst(session_t *ps, const config_t *pcfg, c2_lptr_t **pcondlst,
|
||
12 years ago
|
const char *name);
|
||
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
parse_config(session_t *ps, struct options_tmp *pcfgtmp);
|
||
12 years ago
|
#endif
|
||
|
|
||
|
static void
|
||
12 years ago
|
get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass);
|
||
12 years ago
|
|
||
13 years ago
|
static void
|
||
12 years ago
|
init_atoms(session_t *ps);
|
||
12 years ago
|
|
||
|
static void
|
||
12 years ago
|
update_refresh_rate(session_t *ps);
|
||
12 years ago
|
|
||
12 years ago
|
static bool
|
||
12 years ago
|
swopti_init(session_t *ps);
|
||
12 years ago
|
|
||
12 years ago
|
static void
|
||
|
swopti_handle_timeout(session_t *ps, struct timeval *ptv);
|
||
|
|
||
12 years ago
|
#ifdef CONFIG_VSYNC_OPENGL
|
||
|
/**
|
||
|
* Ensure we have a GLX context.
|
||
|
*/
|
||
|
static inline bool
|
||
|
ensure_glx_context(session_t *ps) {
|
||
|
// Create GLX context
|
||
|
if (!ps->glx_context)
|
||
12 years ago
|
glx_init(ps, false);
|
||
12 years ago
|
|
||
|
return ps->glx_context;
|
||
|
}
|
||
|
#endif
|
||
|
|
||
12 years ago
|
static bool
|
||
|
vsync_drm_init(session_t *ps);
|
||
12 years ago
|
|
||
|
#ifdef CONFIG_VSYNC_DRM
|
||
|
static int
|
||
12 years ago
|
vsync_drm_wait(session_t *ps);
|
||
12 years ago
|
#endif
|
||
|
|
||
12 years ago
|
static bool
|
||
|
vsync_opengl_init(session_t *ps);
|
||
12 years ago
|
|
||
12 years ago
|
static bool
|
||
|
vsync_opengl_oml_init(session_t *ps);
|
||
|
|
||
12 years ago
|
static bool
|
||
|
vsync_opengl_swc_init(session_t *ps);
|
||
|
|
||
12 years ago
|
static bool
|
||
|
vsync_opengl_mswc_init(session_t *ps);
|
||
|
|
||
12 years ago
|
#ifdef CONFIG_VSYNC_OPENGL
|
||
12 years ago
|
static int
|
||
12 years ago
|
vsync_opengl_wait(session_t *ps);
|
||
12 years ago
|
|
||
|
static int
|
||
|
vsync_opengl_oml_wait(session_t *ps);
|
||
12 years ago
|
|
||
|
static void
|
||
|
vsync_opengl_swc_deinit(session_t *ps);
|
||
|
|
||
|
static void
|
||
|
vsync_opengl_mswc_deinit(session_t *ps);
|
||
12 years ago
|
#endif
|
||
|
|
||
12 years ago
|
static void
|
||
12 years ago
|
vsync_wait(session_t *ps);
|
||
|
|
||
|
static void
|
||
|
init_alpha_picts(session_t *ps);
|
||
12 years ago
|
|
||
12 years ago
|
static bool
|
||
12 years ago
|
init_dbe(session_t *ps);
|
||
12 years ago
|
|
||
|
static void
|
||
12 years ago
|
init_overlay(session_t *ps);
|
||
|
|
||
|
static void
|
||
|
redir_start(session_t *ps);
|
||
|
|
||
|
static void
|
||
|
redir_stop(session_t *ps);
|
||
|
|
||
12 years ago
|
static inline time_ms_t
|
||
|
timeout_get_newrun(const timeout_t *ptmout) {
|
||
12 years ago
|
return ptmout->firstrun + (max_l((ptmout->lastrun + (time_ms_t) (ptmout->interval * TIMEOUT_RUN_TOLERANCE) - ptmout->firstrun) / ptmout->interval, (ptmout->lastrun + (time_ms_t) (ptmout->interval * (1 - TIMEOUT_RUN_TOLERANCE)) - ptmout->firstrun) / ptmout->interval) + 1) * ptmout->interval;
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
static time_ms_t
|
||
|
timeout_get_poll_time(session_t *ps);
|
||
|
|
||
|
static void
|
||
|
timeout_clear(session_t *ps);
|
||
|
|
||
11 years ago
|
static bool
|
||
|
tmout_unredir_callback(session_t *ps, timeout_t *tmout);
|
||
|
|
||
12 years ago
|
static bool
|
||
|
mainloop(session_t *ps);
|
||
|
|
||
11 years ago
|
#ifdef CONFIG_XINERAMA
|
||
|
static void
|
||
|
cxinerama_upd_scrs(session_t *ps);
|
||
|
#endif
|
||
|
|
||
|
/**
|
||
|
* Get the Xinerama screen a window is on.
|
||
|
*
|
||
|
* Return an index >= 0, or -1 if not found.
|
||
|
*/
|
||
|
static inline void
|
||
|
cxinerama_win_upd_scr(session_t *ps, win *w) {
|
||
|
#ifdef CONFIG_XINERAMA
|
||
|
w->xinerama_scr = -1;
|
||
|
for (XineramaScreenInfo *s = ps->xinerama_scrs;
|
||
|
s < ps->xinerama_scrs + ps->xinerama_nscrs; ++s)
|
||
|
if (s->x_org <= w->a.x && s->y_org <= w->a.y
|
||
|
&& s->x_org + s->width >= w->a.x + w->widthb
|
||
|
&& s->y_org + s->height >= w->a.y + w->heightb) {
|
||
|
w->xinerama_scr = s - ps->xinerama_scrs;
|
||
|
return;
|
||
|
}
|
||
|
#endif
|
||
|
}
|
||
|
|
||
11 years ago
|
static void
|
||
|
cxinerama_upd_scrs(session_t *ps);
|
||
|
|
||
12 years ago
|
static session_t *
|
||
|
session_init(session_t *ps_old, int argc, char **argv);
|
||
12 years ago
|
|
||
|
static void
|
||
12 years ago
|
session_destroy(session_t *ps);
|
||
12 years ago
|
|
||
|
static void
|
||
12 years ago
|
session_run(session_t *ps);
|
||
12 years ago
|
|
||
|
static void
|
||
12 years ago
|
reset_enable(int __attribute__((unused)) signum);
|