summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Jeffrey <[email protected]>2012-09-13 00:58:05 -0500
committerChristopher Jeffrey <[email protected]>2012-09-13 10:00:57 -0500
commitf092885f476fb740adc9a539baac48df11bace8e (patch)
treecad7a2c5cd205d862fa03eb7f4aff80ee1d958b6
parent2f63377d4edae923c0ede939fd2915f4e063a0be (diff)
downloadtdebase-f092885f476fb740adc9a539baac48df11bace8e.tar.gz
tdebase-f092885f476fb740adc9a539baac48df11bace8e.zip
stay consistent with code style
-rw-r--r--compton.c130
-rw-r--r--compton.h74
2 files changed, 129 insertions, 75 deletions
diff --git a/compton.c b/compton.c
index 6ec0e1744..cfddd431a 100644
--- a/compton.c
+++ b/compton.c
@@ -572,8 +572,9 @@ make_shadow(Display *dpy, double opacity,
0, sheight);
int y;
- for (y = ystart; y < yend; y++)
+ for (y = ystart; y < yend; y++) {
memset(&data[y * swidth + xstart], 0, xrange);
+ }
}
return ximage;
@@ -1148,9 +1149,10 @@ paint_all(Display *dpy, XserverRegion region) {
None, root_buffer, 0, 0, 0, 0,
x, y, wid, hei);
- if (w->dim)
+ if (w->dim) {
XRenderComposite(dpy, PictOpOver, dim_picture, None,
root_buffer, 0, 0, 0, 0, x, y, wid, hei);
+ }
}
if (!w->border_clip) {
@@ -1169,6 +1171,7 @@ paint_all(Display *dpy, XserverRegion region) {
XFixesSetPictureClipRegion(dpy,
root_buffer, 0, 0, region);
+
paint_root(dpy);
for (w = t; w; w = w->prev_trans) {
@@ -1250,9 +1253,10 @@ paint_all(Display *dpy, XserverRegion region) {
l, t, l, t, x + l, y + t, wid - l - r, hei - t - b);
}
- if (w->dim)
+ if (w->dim) {
XRenderComposite(dpy, PictOpOver, dim_picture, None,
root_buffer, 0, 0, 0, 0, x, y, wid, hei);
+ }
}
XFixesDestroyRegion(dpy, w->border_clip);
@@ -1569,7 +1573,8 @@ unmap_win(Display *dpy, Window id, Bool fade) {
finish_unmap_win(dpy, w);
}
-opacity_t get_opacity_prop(Display *dpy, win *w, opacity_t def) {
+static opacity_t
+get_opacity_prop(Display *dpy, win *w, opacity_t def) {
Atom actual;
int format;
unsigned long n, left;
@@ -1635,13 +1640,14 @@ determine_mode(Display *dpy, win *w) {
add_damage_win(dpy, w);
}
-void set_opacity(Display *dpy, win *w, opacity_t opacity) {
+static void
+set_opacity(Display *dpy, win *w, opacity_t opacity) {
// Do nothing if the opacity does not change
- if (w->opacity == opacity)
- return;
+ if (w->opacity == opacity) return;
w->opacity = opacity;
determine_mode(dpy, w);
+
if (w->shadow) {
XRenderFreePicture(dpy, w->shadow);
w->shadow = None;
@@ -1675,40 +1681,45 @@ void set_opacity(Display *dpy, win *w, opacity_t opacity) {
* @param refetch_prop whether _NET_WM_OPACITY of the window needs to be
* refetched
*/
-void calc_opacity(Display *dpy, win *w, Bool refetch_prop) {
+static void
+calc_opacity(Display *dpy, win *w, Bool refetch_prop) {
opacity_t opacity;
// Do nothing for unmapped window, calc_opacity() will be called
// when it's mapped
// I suppose I need not to check for IsUnviewable here?
- if (IsViewable != w->a.map_state)
- return;
+ if (IsViewable != w->a.map_state) return;
// Do not refetch the opacity window attribute unless necessary, this
// is probably an expensive operation in some cases
- if (refetch_prop)
+ if (refetch_prop) {
w->opacity_prop = get_opacity_prop(dpy, w, OPAQUE);
+ }
if (OPAQUE == (opacity = w->opacity_prop)) {
- if (OPAQUE != win_type_opacity[w->window_type])
+ if (OPAQUE != win_type_opacity[w->window_type]) {
opacity = win_type_opacity[w->window_type] * OPAQUE;
+ }
}
// Respect inactive_opacity in some cases
if (inactive_opacity && IS_NORMAL_WIN(w) && False == w->focused
- && (OPAQUE == opacity || inactive_opacity_override))
+ && (OPAQUE == opacity || inactive_opacity_override)) {
opacity = inactive_opacity;
+ }
set_opacity(dpy, w, opacity);
}
-void calc_dim(Display *dpy, win *w) {
+static void
+calc_dim(Display *dpy, win *w) {
Bool dim;
- if (inactive_dim && IS_NORMAL_WIN(w) && !(w->focused))
+ if (inactive_dim && IS_NORMAL_WIN(w) && !(w->focused)) {
dim = True;
- else
+ } else {
dim = False;
+ }
if (dim != w->dim) {
w->dim = dim;
@@ -1846,17 +1857,22 @@ restack_win(Display *dpy, win *w, Window new_above) {
Bool to_free;
win* c = list;
- printf("restack_win(%#010lx, %#010lx): Window stack modified. Current stack:\n", w->id, new_above);
+ printf("restack_win(%#010lx, %#010lx): "
+ "Window stack modified. Current stack:\n", w->id, new_above);
+
for (; c; c = c->next) {
window_name = "(Failed to get title)";
- if (root == c->id)
+
+ if (root == c->id) {
window_name = "(Root window)";
- else
+ } else {
to_free = window_get_name(c->id, &window_name);
+ }
+
desc = "";
- if (c->destroyed)
- desc = "(D) ";
+ if (c->destroyed) desc = "(D) ";
printf("%#010lx \"%s\" %s-> ", c->id, window_name, desc);
+
if (to_free) {
XFree(window_name);
window_name = NULL;
@@ -1891,8 +1907,10 @@ configure_win(Display *dpy, XConfigureEvent *ce) {
w->queue_configure = *ce;
restack_win(dpy, w, ce->above);
} else {
- if (!(w->need_configure))
+ if (!(w->need_configure)) {
restack_win(dpy, w, ce->above);
+ }
+
w->need_configure = False;
#if CAN_DO_USABLE
@@ -1900,8 +1918,9 @@ configure_win(Display *dpy, XConfigureEvent *ce) {
#endif
{
damage = XFixesCreateRegion(dpy, 0, 0);
- if (w->extents != None)
+ if (w->extents != None) {
XFixesCopyRegion(dpy, damage, w->extents);
+ }
}
w->a.x = ce->x;
@@ -2198,7 +2217,8 @@ expose_root(Display *dpy, Window root, XRectangle *rects, int nrects) {
}
#if defined(DEBUG_EVENTS) || defined(DEBUG_RESTACK)
-static int window_get_name(Window w, char **name) {
+static int
+window_get_name(Window w, char **name) {
Atom prop = XInternAtom(dpy, "_NET_WM_NAME", False);
Atom utf8_type = XInternAtom(dpy, "UTF8_STRING", False);
Atom actual_type;
@@ -2209,16 +2229,20 @@ static int window_get_name(Window w, char **name) {
Status ret;
set_ignore(dpy, NextRequest(dpy));
+
if (Success != (ret = XGetWindowProperty(dpy, w, prop, 0L, (long) BUFSIZ,
False, utf8_type, &actual_type, &actual_format, &nitems,
&leftover, (unsigned char **) &data))) {
- if (BadWindow == ret)
- return 0;
+ if (BadWindow == ret) return 0;
+
set_ignore(dpy, NextRequest(dpy));
printf("Window %#010lx: _NET_WM_NAME unset, falling back to WM_NAME.\n", w);
- if (!XFetchName(dpy, w, &data))
+
+ if (!XFetchName(dpy, w, &data)) {
return 0;
+ }
}
+
// if (actual_type == utf8_type && actual_format == 8)
*name = (char *) data;
return 1;
@@ -2264,9 +2288,13 @@ ev_name(XEvent *ev) {
if (ev->type == damage_event + XDamageNotify) {
return "Damage";
}
- if (shape_exists && ev->type == shape_event)
+
+ if (shape_exists && ev->type == shape_event) {
return "ShapeNotify";
+ }
+
sprintf(buf, "Event %d", ev->type);
+
return buf;
}
}
@@ -2297,8 +2325,11 @@ ev_window(XEvent *ev) {
if (ev->type == damage_event + XDamageNotify) {
return ((XDamageNotifyEvent *)ev)->drawable;
}
- if (shape_exists && ev->type == shape_event)
+
+ if (shape_exists && ev->type == shape_event) {
return ((XShapeEvent *) ev)->window;
+ }
+
return 0;
}
}
@@ -2311,6 +2342,7 @@ ev_window(XEvent *ev) {
inline static void
ev_focus_in(XFocusChangeEvent *ev) {
win *w = find_win(dpy, ev->window);
+ if (!w) return;
// To deal with events sent from windows just destroyed
if (!w)
@@ -2333,6 +2365,7 @@ ev_focus_out(XFocusChangeEvent *ev) {
}
win *w = find_win(dpy, ev->window);
+ if (!w) return;
// To deal with events sent from windows just destroyed
if (!w)
@@ -2351,7 +2384,10 @@ ev_create_notify(XCreateWindowEvent *ev) {
inline static void
ev_configure_notify(XConfigureEvent *ev) {
#ifdef DEBUG_EVENTS
- printf("{ send_event: %d, above: %#010lx, override_redirect: %d }\n", ev->send_event, ev->above, ev->override_redirect);
+ printf("{ send_event: %d, "
+ " above: %#010lx, "
+ " override_redirect: %d }\n",
+ ev->send_event, ev->above, ev->override_redirect);
#endif
configure_win(dpy, ev);
}
@@ -2454,8 +2490,10 @@ ev_damage_notify(XDamageNotifyEvent *ev) {
damage_win(dpy, ev);
}
-static void ev_shape_notify(XShapeEvent *ev) {
+inline static void
+ev_shape_notify(XShapeEvent *ev) {
win *w = find_win(dpy, ev->window);
+ if (!w) return;
/*
* Empty border_size may indicated an
@@ -2472,12 +2510,10 @@ static void ev_shape_notify(XShapeEvent *ev) {
// Mark the new border_size as damaged
add_damage(dpy, copy_region(dpy, w->border_size));
}
-
}
inline static void
ev_handle(XEvent *ev) {
-
#ifdef DEBUG_EVENTS
Window w;
char *window_name;
@@ -2491,17 +2527,21 @@ ev_handle(XEvent *ev) {
#ifdef DEBUG_EVENTS
w = ev_window(ev);
window_name = "(Failed to get title)";
+
if (w) {
- if (root == w)
+ if (root == w) {
window_name = "(Root window)";
- else
+ } else {
to_free = (Bool) window_get_name(w, &window_name);
+ }
}
+
if (ev->type != damage_event + XDamageNotify) {
print_timestamp();
printf("event %10.10s serial %#010x window %#010lx \"%s\"\n",
ev_name(ev), ev_serial(ev), w, window_name);
}
+
if (to_free) {
XFree(window_name);
window_name = NULL;
@@ -2611,8 +2651,7 @@ usage() {
"--inactive-opacity-override\n"
" Inactive opacity set by -i overrides value of _NET_WM_OPACITY.\n"
"--inactive-dim value\n"
- " Dim inactive windows. (0.0 - 1.0, defaults to 0)\n"
- );
+ " Dim inactive windows. (0.0 - 1.0, defaults to 0)\n");
exit(1);
}
@@ -2835,8 +2874,9 @@ main(int argc, char **argv) {
break;
case 'i':
inactive_opacity = (normalize_d(atof(optarg)) * OPAQUE);
- if (OPAQUE == inactive_opacity)
+ if (OPAQUE == inactive_opacity) {
inactive_opacity = 0;
+ }
break;
case 'e':
frame_opacity = normalize_d(atof(optarg));
@@ -2871,8 +2911,9 @@ main(int argc, char **argv) {
}
// Determine whether we need to track focus changes
- if (inactive_opacity || inactive_dim)
+ if (inactive_opacity || inactive_dim) {
track_focus = True;
+ }
dpy = XOpenDisplay(display);
if (!dpy) {
@@ -2918,8 +2959,9 @@ main(int argc, char **argv) {
exit(1);
}
- if (!XShapeQueryExtension(dpy, &shape_event, &shape_error))
+ if (!XShapeQueryExtension(dpy, &shape_event, &shape_error)) {
shape_exists = False;
+ }
register_cm(scr);
@@ -2943,15 +2985,17 @@ main(int argc, char **argv) {
// Generates another Picture for shadows if the color is modified by
// user
- if (!shadow_red && !shadow_green && !shadow_blue)
+ if (!shadow_red && !shadow_green && !shadow_blue) {
cshadow_picture = black_picture;
- else
+ } else {
cshadow_picture = solid_picture(dpy, True, 1,
shadow_red, shadow_green, shadow_blue);
+ }
// Generates a picture for inactive_dim
- if (inactive_dim)
+ if (inactive_dim) {
dim_picture = solid_picture(dpy, True, inactive_dim, 0, 0, 0);
+ }
all_damage = None;
clip_changed = True;
diff --git a/compton.h b/compton.h
index f4bccd4b5..83671a682 100644
--- a/compton.h
+++ b/compton.h
@@ -161,12 +161,10 @@ extern Atom atom_client_attr;
* @param max maximum value
* @return normalized value
*/
-static inline double normalize_i_range(int i, int min, int max) {
- if (i > max)
- return max;
- if (i < min)
- return min;
-
+static inline double
+normalize_i_range(int i, int min, int max) {
+ if (i > max) return max;
+ if (i < min) return min;
return i;
}
@@ -175,12 +173,10 @@ static inline double normalize_i_range(int i, int min, int max) {
*
* @param d double value to normalize
*/
-static inline double normalize_d(double d) {
- if (d > 1.0)
- return 1.0;
- if (d < 0.0)
- return 0.0;
-
+static inline double
+normalize_d(double d) {
+ if (d > 1.0) return 1.0;
+ if (d < 0.0) return 0.0;
return d;
}
@@ -191,11 +187,12 @@ static inline double normalize_d(double d) {
* @param count amount of elements in the array
* @param wid window ID to search for
*/
-static inline Bool array_wid_exists(const Window *arr,
- int count, Window wid) {
+static inline Bool
+array_wid_exists(const Window *arr, int count, Window wid) {
while (count--) {
- if (arr[count] == wid)
+ if (arr[count] == wid) {
return True;
+ }
}
return False;
@@ -210,15 +207,17 @@ static inline Bool array_wid_exists(const Window *arr,
* Subtract the `struct timeval' values X and Y,
* storing the result in RESULT.
* Return 1 if the difference is negative, otherwise 0. */
-int timeval_subtract (result, x, y)
- struct timeval *result, *x, *y;
-{
+static int
+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) {
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
y->tv_usec -= 1000000 * nsec;
y->tv_sec += nsec;
}
+
if (x->tv_usec - y->tv_usec > 1000000) {
int nsec = (x->tv_usec - y->tv_usec) / 1000000;
y->tv_usec += 1000000 * nsec;
@@ -239,11 +238,11 @@ int timeval_subtract (result, x, y)
*
* Used for debugging.
*/
-static inline void print_timestamp(void) {
+static inline void
+print_timestamp(void) {
struct timeval tm, diff;
- if (gettimeofday(&tm, NULL))
- return;
+ if (gettimeofday(&tm, NULL)) return;
timeval_subtract(&diff, &tm, &time_start);
printf("[ %5ld.%02ld ] ", diff.tv_sec, diff.tv_usec / 10000);
@@ -416,7 +415,7 @@ unmap_callback(Display *dpy, win *w);
static void
unmap_win(Display *dpy, Window id, Bool fade);
-opacity_t
+static opacity_t
get_opacity_prop(Display *dpy, win *w, opacity_t def);
static double
@@ -425,11 +424,14 @@ get_opacity_percent(Display *dpy, win *w);
static void
determine_mode(Display *dpy, win *w);
-void set_opacity(Display *dpy, win *w, opacity_t opacity);
+static void
+set_opacity(Display *dpy, win *w, opacity_t opacity);
-void calc_opacity(Display *dpy, win *w, Bool refetch_prop);
+static void
+calc_opacity(Display *dpy, win *w, Bool refetch_prop);
-void calc_dim(Display *dpy, win *w);
+static void
+calc_dim(Display *dpy, win *w);
static void
add_win(Display *dpy, Window id, Window prev, Bool override_redirect);
@@ -464,7 +466,8 @@ static void
expose_root(Display *dpy, Window root, XRectangle *rects, int nrects);
#if defined(DEBUG_EVENTS) || defined(DEBUG_RESTACK)
-static int window_get_name(Window w, char **name);
+static int
+window_get_name(Window w, char **name);
#endif
#ifdef DEBUG_EVENTS
@@ -520,10 +523,14 @@ ev_property_notify(XPropertyEvent *ev);
inline static void
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) {
+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);
@@ -534,7 +541,8 @@ inline static void win_free_border_size(Display *dpy, win *w) {
/**
* Get a region of the screen size.
*/
-inline static XserverRegion get_screen_region(Display *dpy) {
+inline static XserverRegion
+get_screen_region(Display *dpy) {
XRectangle r;
r.x = 0;
@@ -547,8 +555,8 @@ inline static XserverRegion get_screen_region(Display *dpy) {
/**
* Copies a region
*/
-inline static XserverRegion copy_region(Display *dpy,
- XserverRegion oldregion) {
+inline static XserverRegion
+copy_region(Display *dpy, XserverRegion oldregion) {
XserverRegion region = XFixesCreateRegion(dpy, NULL, 0);
XFixesCopyRegion(dpy, region, oldregion);
@@ -562,9 +570,11 @@ inline static XserverRegion copy_region(Display *dpy,
* @param dpy display in use
* @param w struct _win element representing the window
*/
-static inline void add_damage_win(Display *dpy, win *w) {
- if (w->extents)
+static inline void
+add_damage_win(Display *dpy, win *w) {
+ if (w->extents) {
add_damage(dpy, copy_region(dpy, w->extents));
+ }
}
inline static void