Misc: Clean up
- Add 4 helper free functions that free XserverRegion, Damage, Picture, and Pixmap. - Rename w->shadow to w->shadow_pict. Add a bool member w->shadow to prepare for a future change.
This commit is contained in:
parent
4293a4626a
commit
64d53f6534
139
src/compton.c
139
src/compton.c
|
@ -278,13 +278,11 @@ run_fades(Display *dpy) {
|
|||
|
||||
determine_mode(dpy, w);
|
||||
|
||||
if (w->shadow) {
|
||||
XRenderFreePicture(dpy, w->shadow);
|
||||
w->shadow = None;
|
||||
if (w->shadow_pict) {
|
||||
XRenderFreePicture(dpy, w->shadow_pict);
|
||||
w->shadow_pict = None;
|
||||
|
||||
if (w->extents != None) {
|
||||
XFixesDestroyRegion(dpy, w->extents);
|
||||
}
|
||||
free_region(dpy, &w->extents);
|
||||
|
||||
/* rebuild the shadow */
|
||||
w->extents = win_extents(dpy, w);
|
||||
|
@ -900,18 +898,18 @@ win_extents(Display *dpy, win *w) {
|
|||
w->shadow_dx = shadow_offset_x;
|
||||
w->shadow_dy = shadow_offset_y;
|
||||
|
||||
if (!w->shadow) {
|
||||
if (!w->shadow_pict) {
|
||||
double opacity = shadow_opacity;
|
||||
|
||||
if (w->mode != WINDOW_SOLID) {
|
||||
opacity = opacity * ((double)w->opacity) / ((double)OPAQUE);
|
||||
opacity = opacity * get_opacity_percent(dpy, w);
|
||||
}
|
||||
|
||||
if (HAS_FRAME_OPACITY(w)) {
|
||||
opacity = opacity * frame_opacity;
|
||||
}
|
||||
|
||||
w->shadow = shadow_picture(
|
||||
w->shadow_pict = shadow_picture(
|
||||
dpy, opacity, w->alpha_pict,
|
||||
w->a.width + w->a.border_width * 2,
|
||||
w->a.height + w->a.border_width * 2,
|
||||
|
@ -1114,15 +1112,9 @@ paint_all(Display *dpy, XserverRegion region) {
|
|||
#endif
|
||||
|
||||
if (clip_changed) {
|
||||
win_free_border_size(dpy, w);
|
||||
if (w->extents) {
|
||||
XFixesDestroyRegion(dpy, w->extents);
|
||||
w->extents = None;
|
||||
}
|
||||
if (w->border_clip) {
|
||||
XFixesDestroyRegion(dpy, w->border_clip);
|
||||
w->border_clip = None;
|
||||
}
|
||||
free_region(dpy, &w->border_size);
|
||||
free_region(dpy, &w->extents);
|
||||
free_region(dpy, &w->border_clip);
|
||||
}
|
||||
|
||||
if (!w->border_size) {
|
||||
|
@ -1190,7 +1182,7 @@ paint_all(Display *dpy, XserverRegion region) {
|
|||
|
||||
if (win_type_shadow[w->window_type]) {
|
||||
XRenderComposite(
|
||||
dpy, PictOpOver, cshadow_picture, w->shadow,
|
||||
dpy, PictOpOver, cshadow_picture, w->shadow_pict,
|
||||
root_buffer, 0, 0, 0, 0,
|
||||
w->a.x + w->shadow_dx, w->a.y + w->shadow_dy,
|
||||
w->shadow_width, w->shadow_height);
|
||||
|
@ -1198,7 +1190,7 @@ paint_all(Display *dpy, XserverRegion region) {
|
|||
|
||||
if (w->opacity != OPAQUE && !w->alpha_pict) {
|
||||
w->alpha_pict = solid_picture(
|
||||
dpy, False, (double)w->opacity / OPAQUE, 0, 0, 0);
|
||||
dpy, False, get_opacity_percent(dpy, w), 0, 0, 0);
|
||||
}
|
||||
|
||||
if (HAS_FRAME_OPACITY(w) && !w->alpha_border_pict) {
|
||||
|
@ -1269,8 +1261,7 @@ paint_all(Display *dpy, XserverRegion region) {
|
|||
}
|
||||
}
|
||||
|
||||
XFixesDestroyRegion(dpy, w->border_clip);
|
||||
w->border_clip = None;
|
||||
free_region(dpy, &w->border_clip);
|
||||
}
|
||||
|
||||
XFixesDestroyRegion(dpy, region);
|
||||
|
@ -1533,29 +1524,13 @@ finish_unmap_win(Display *dpy, win *w) {
|
|||
}
|
||||
|
||||
#if HAS_NAME_WINDOW_PIXMAP
|
||||
if (w->pixmap) {
|
||||
XFreePixmap(dpy, w->pixmap);
|
||||
w->pixmap = None;
|
||||
}
|
||||
free_pixmap(dpy, &w->pixmap);
|
||||
#endif
|
||||
|
||||
if (w->picture) {
|
||||
set_ignore(dpy, NextRequest(dpy));
|
||||
XRenderFreePicture(dpy, w->picture);
|
||||
w->picture = None;
|
||||
}
|
||||
|
||||
win_free_border_size(dpy, w);
|
||||
|
||||
if (w->shadow) {
|
||||
XRenderFreePicture(dpy, w->shadow);
|
||||
w->shadow = None;
|
||||
}
|
||||
|
||||
if (w->border_clip) {
|
||||
XFixesDestroyRegion(dpy, w->border_clip);
|
||||
w->border_clip = None;
|
||||
}
|
||||
free_picture(dpy, &w->picture);
|
||||
free_region(dpy, &w->border_size);
|
||||
free_picture(dpy, &w->shadow_pict);
|
||||
free_region(dpy, &w->border_clip);
|
||||
|
||||
clip_changed = True;
|
||||
}
|
||||
|
@ -1586,7 +1561,7 @@ unmap_win(Display *dpy, Window id, Bool fade) {
|
|||
|
||||
#if HAS_NAME_WINDOW_PIXMAP
|
||||
if (w->pixmap && fade && win_type_fade[w->window_type]) {
|
||||
set_fade(dpy, w, w->opacity * 1.0 / OPAQUE, 0.0,
|
||||
set_fade(dpy, w, get_opacity_percent(dpy, w), 0.0,
|
||||
fade_out_step, unmap_callback, False, True);
|
||||
} else
|
||||
#endif
|
||||
|
@ -1615,7 +1590,7 @@ get_opacity_prop(Display *dpy, win *w, opacity_t def) {
|
|||
|
||||
static double
|
||||
get_opacity_percent(Display *dpy, win *w) {
|
||||
return w->opacity * 1.0 / OPAQUE;
|
||||
return ((double) w->opacity) / OPAQUE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1625,20 +1600,8 @@ determine_mode(Display *dpy, win *w) {
|
|||
|
||||
/* if trans prop == -1 fall back on previous tests */
|
||||
|
||||
if (w->alpha_pict) {
|
||||
XRenderFreePicture(dpy, w->alpha_pict);
|
||||
w->alpha_pict = None;
|
||||
}
|
||||
|
||||
if (w->alpha_border_pict) {
|
||||
XRenderFreePicture(dpy, w->alpha_border_pict);
|
||||
w->alpha_border_pict = None;
|
||||
}
|
||||
|
||||
if (w->shadow_pict) {
|
||||
XRenderFreePicture(dpy, w->shadow_pict);
|
||||
w->shadow_pict = None;
|
||||
}
|
||||
free_picture(dpy, &w->alpha_pict);
|
||||
free_picture(dpy, &w->alpha_border_pict);
|
||||
|
||||
if (w->a.class == InputOnly) {
|
||||
format = 0;
|
||||
|
@ -1668,13 +1631,11 @@ set_opacity(Display *dpy, win *w, opacity_t opacity) {
|
|||
w->opacity = opacity;
|
||||
determine_mode(dpy, w);
|
||||
|
||||
if (w->shadow) {
|
||||
XRenderFreePicture(dpy, w->shadow);
|
||||
w->shadow = None;
|
||||
if (w->shadow_pict) {
|
||||
XRenderFreePicture(dpy, w->shadow_pict);
|
||||
w->shadow_pict = None;
|
||||
|
||||
if (w->extents != None) {
|
||||
XFixesDestroyRegion(dpy, w->extents);
|
||||
}
|
||||
free_region(dpy, &w->extents);
|
||||
|
||||
/* rebuild the shadow */
|
||||
w->extents = win_extents(dpy, w);
|
||||
|
@ -1815,10 +1776,10 @@ add_win(Display *dpy, Window id, Window prev, Bool override_redirect) {
|
|||
|
||||
new->alpha_pict = None;
|
||||
new->alpha_border_pict = None;
|
||||
new->shadow = False;
|
||||
new->shadow_pict = None;
|
||||
new->border_size = None;
|
||||
new->extents = None;
|
||||
new->shadow = None;
|
||||
new->shadow_dx = 0;
|
||||
new->shadow_dy = 0;
|
||||
new->shadow_width = 0;
|
||||
|
@ -1957,20 +1918,10 @@ configure_win(Display *dpy, XConfigureEvent *ce) {
|
|||
|
||||
if (w->a.width != ce->width || w->a.height != ce->height) {
|
||||
#if HAS_NAME_WINDOW_PIXMAP
|
||||
if (w->pixmap) {
|
||||
XFreePixmap(dpy, w->pixmap);
|
||||
w->pixmap = None;
|
||||
if (w->picture) {
|
||||
XRenderFreePicture(dpy, w->picture);
|
||||
w->picture = None;
|
||||
}
|
||||
}
|
||||
free_pixmap(dpy, &w->pixmap);
|
||||
free_picture(dpy, &w->picture);
|
||||
#endif
|
||||
|
||||
if (w->shadow) {
|
||||
XRenderFreePicture(dpy, w->shadow);
|
||||
w->shadow = None;
|
||||
}
|
||||
free_picture(dpy, &w->shadow_pict);
|
||||
}
|
||||
|
||||
w->a.width = ce->width;
|
||||
|
@ -2016,32 +1967,10 @@ finish_destroy_win(Display *dpy, Window id) {
|
|||
finish_unmap_win(dpy, w);
|
||||
*prev = w->next;
|
||||
|
||||
if (w->alpha_pict) {
|
||||
XRenderFreePicture(dpy, w->alpha_pict);
|
||||
w->alpha_pict = None;
|
||||
}
|
||||
|
||||
if (w->alpha_border_pict) {
|
||||
XRenderFreePicture(dpy, w->alpha_border_pict);
|
||||
w->alpha_border_pict = None;
|
||||
}
|
||||
|
||||
if (w->shadow_pict) {
|
||||
XRenderFreePicture(dpy, w->shadow_pict);
|
||||
w->shadow_pict = None;
|
||||
}
|
||||
|
||||
/* fix leak, from freedesktop repo */
|
||||
if (w->shadow) {
|
||||
XRenderFreePicture(dpy, w->shadow);
|
||||
w->shadow = None;
|
||||
}
|
||||
|
||||
if (w->damage != None) {
|
||||
set_ignore(dpy, NextRequest(dpy));
|
||||
XDamageDestroy(dpy, w->damage);
|
||||
w->damage = None;
|
||||
}
|
||||
free_picture(dpy, &w->alpha_pict);
|
||||
free_picture(dpy, &w->alpha_border_pict);
|
||||
free_picture(dpy, &w->shadow_pict);
|
||||
free_damage(dpy, &w->damage);
|
||||
|
||||
cleanup_fade(dpy, w);
|
||||
free(w);
|
||||
|
|
|
@ -97,10 +97,10 @@ typedef struct _win {
|
|||
Picture picture;
|
||||
Picture alpha_pict;
|
||||
Picture alpha_border_pict;
|
||||
Picture shadow_pict;
|
||||
XserverRegion border_size;
|
||||
XserverRegion extents;
|
||||
Picture shadow;
|
||||
Bool shadow;
|
||||
Picture shadow_pict;
|
||||
int shadow_dx;
|
||||
int shadow_dy;
|
||||
int shadow_width;
|
||||
|
@ -159,6 +159,8 @@ extern Atom atom_client_attr;
|
|||
// inline functions must be made static to compile correctly under clang:
|
||||
// http://clang.llvm.org/compatibility.html#inline
|
||||
|
||||
// Helper functions
|
||||
|
||||
/**
|
||||
* Normalize an int value to a specific range.
|
||||
*
|
||||
|
@ -255,6 +257,50 @@ print_timestamp(void) {
|
|||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Destroy a <code>XserverRegion</code>.
|
||||
*/
|
||||
inline static void
|
||||
free_region(Display *dpy, XserverRegion *p) {
|
||||
if (*p) {
|
||||
XFixesDestroyRegion(dpy, *p);
|
||||
*p = None;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a <code>Picture</code>.
|
||||
*/
|
||||
inline static void
|
||||
free_picture(Display *dpy, Picture *p) {
|
||||
if (*p) {
|
||||
XRenderFreePicture(dpy, *p);
|
||||
*p = None;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a <code>Pixmap</code>.
|
||||
*/
|
||||
inline static void
|
||||
free_pixmap(Display *dpy, Pixmap *p) {
|
||||
if (*p) {
|
||||
XFreePixmap(dpy, *p);
|
||||
*p = None;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a <code>Damage</code>.
|
||||
*/
|
||||
inline static void
|
||||
free_damage(Display *dpy, Damage *p) {
|
||||
if (*p) {
|
||||
XDamageDestroy(dpy, *p);
|
||||
*p = None;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a window has a specific attribute.
|
||||
*
|
||||
|
@ -544,18 +590,6 @@ ev_damage_notify(XDamageNotifyEvent *ev);
|
|||
inline static void
|
||||
ev_shape_notify(XShapeEvent *ev);
|
||||
|
||||
/**
|
||||
* Destory the cached border_size of a window.
|
||||
*/
|
||||
inline static void
|
||||
win_free_border_size(Display *dpy, win *w) {
|
||||
if (w->border_size) {
|
||||
set_ignore(dpy, NextRequest(dpy));
|
||||
XFixesDestroyRegion(dpy, w->border_size);
|
||||
w->border_size = None;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a region of the screen size.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue