Skip to content

Commit

Permalink
more style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Sep 13, 2012
1 parent 5bcbf87 commit 0064894
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
45 changes: 28 additions & 17 deletions src/compton.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,9 @@ long determine_evmask(Display *dpy, Window wid, enum win_evmode_t mode) {

if (WIN_EVMODE_FRAME == mode || find_win(dpy, wid)) {
evmask |= PropertyChangeMask;
if (track_focus)
evmask |= FocusChangeMask;
if (track_focus) evmask |= FocusChangeMask;
}

if (WIN_EVMODE_CLIENT == mode || find_client_win(dpy, wid)) {
evmask |= PropertyChangeMask;
}
Expand All @@ -739,7 +739,8 @@ find_win(Display *dpy, Window id) {
* @param w window ID
* @return struct _win object of the found window, NULL if not found
*/
win *find_toplevel(Display *dpy, Window id) {
static win *
find_toplevel(Display *dpy, Window id) {
win *w;

for (w = list; w; w = w->next) {
Expand All @@ -757,11 +758,12 @@ win *find_toplevel(Display *dpy, Window id) {
* @param w window ID
* @return struct _win object of the found window, NULL if not found
*/
win *find_toplevel2(Display *dpy, Window wid) {
static win *
find_toplevel2(Display *dpy, Window wid) {
win *w = NULL;

// We traverse through its ancestors to find out the frame
while(wid && wid != root && !(w = find_win(dpy, wid))) {
while (wid && wid != root && !(w = find_win(dpy, wid))) {
Window troot;
Window parent;
Window *tchildren;
Expand All @@ -770,14 +772,14 @@ win *find_toplevel2(Display *dpy, Window wid) {
// XQueryTree probably fails if you run compton when X is somehow
// initializing (like add it in .xinitrc). In this case
// just leave it alone.
if(!XQueryTree(dpy, wid, &troot, &parent, &tchildren,
if (!XQueryTree(dpy, wid, &troot, &parent, &tchildren,
&tnchildren)) {
wid = 0;
break;
}

if (tchildren)
XFree(tchildren);
if (tchildren) XFree(tchildren);

wid = parent;
}

Expand All @@ -791,7 +793,8 @@ win *find_toplevel2(Display *dpy, Window wid) {
* @param dpy display to use
* @return struct _win of currently focused window, NULL if not found
*/
win *recheck_focus(Display *dpy) {
static win *
recheck_focus(Display *dpy) {
// Determine the currently focused window so we can apply appropriate
// opacity on it
Window wid = 0;
Expand All @@ -801,8 +804,9 @@ win *recheck_focus(Display *dpy) {
XGetInputFocus(dpy, &wid, &revert_to);

// Fallback to the old method if find_toplevel() fails
if (!(w = find_toplevel(dpy, wid)))
if (!(w = find_toplevel(dpy, wid))) {
w = find_toplevel2(dpy, wid);
}

// And we set the focus state and opacity here
if (w) {
Expand Down Expand Up @@ -964,21 +968,25 @@ border_size(Display *dpy, win *w) {
return border;
}

Window find_client_win(Display *dpy, Window w) {
if (win_has_attr(dpy, w, atom_client_attr))
static Window
find_client_win(Display *dpy, Window w) {
if (win_has_attr(dpy, w, atom_client_attr)) {
return w;
}

Window *children;
unsigned int nchildren;
unsigned int i;
Window ret = 0;

if(!win_get_children(dpy, w, &children, &nchildren))
if (!win_get_children(dpy, w, &children, &nchildren)) {
return 0;
}

for (i = 0; i < nchildren; ++i)
for (i = 0; i < nchildren; ++i) {
if ((ret = find_client_win(dpy, children[i])))
break;
}

XFree(children);

Expand Down Expand Up @@ -1471,8 +1479,9 @@ map_win(Display *dpy, Window id,
* XSelectInput() is called too late. We have to recheck the focused
* window here.
*/
if (track_focus)
if (track_focus) {
recheck_focus(dpy);
}

calc_opacity(dpy, w, True);
calc_dim(dpy, w);
Expand Down Expand Up @@ -1804,10 +1813,11 @@ add_win(Display *dpy, Window id, Window prev, Bool override_redirect) {
Window cw = find_client_win(dpy, new->id);
if (cw) {
new->client_win = cw;
if (frame_opacity)
if (frame_opacity) {
get_frame_extents(dpy, cw,
&new->left_width, &new->right_width,
&new->top_width, &new->bottom_width);
}
XSelectInput(dpy, cw, determine_evmask(dpy, id, WIN_EVMODE_CLIENT));
}
}
Expand Down Expand Up @@ -3019,8 +3029,9 @@ main(int argc, char **argv) {

XFree(children);

if (track_focus)
if (track_focus) {
recheck_focus(dpy);
}

XUngrabServer(dpy);

Expand Down
21 changes: 15 additions & 6 deletions src/compton.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ print_timestamp(void) {
* @param atom atom of attribute to check
* @return 1 if it has the attribute, 0 otherwise
*/
static inline Bool win_has_attr(Display *dpy, Window w, Atom atom) {
static inline Bool
win_has_attr(Display *dpy, Window w, Atom atom) {
Atom type = None;
int format;
unsigned long nitems, after;
Expand All @@ -266,8 +267,7 @@ static inline Bool win_has_attr(Display *dpy, Window w, Atom atom) {
if (Success == XGetWindowProperty(dpy, w, atom, 0, 0, False,
AnyPropertyType, &type, &format, &nitems, &after, &data)) {
XFree(data);
if (type)
return True;
if (type) return True;
}

return False;
Expand All @@ -282,7 +282,8 @@ static inline Bool win_has_attr(Display *dpy, Window w, Atom atom) {
* @param nchildren [out] number of children
* @return 1 if successful, 0 otherwise
*/
static inline Bool win_get_children(Display *dpy, Window w,
static inline Bool
win_get_children(Display *dpy, Window w,
Window **children, unsigned *nchildren) {
Window troot, tparent;

Expand Down Expand Up @@ -361,6 +362,12 @@ find_win(Display *dpy, Window id);
static win *
find_toplevel(Display *dpy, Window id);

static win *
find_toplevel2(Display *dpy, Window wid);

static win *
recheck_focus(Display *dpy);

static Picture
root_tile_f(Display *dpy);

Expand All @@ -373,9 +380,11 @@ win_extents(Display *dpy, win *w);
static XserverRegion
border_size(Display *dpy, win *w);

Window find_client_win(Display *dpy, Window w);
static Window
find_client_win(Display *dpy, Window w);

Window find_client_win2(Display *dpy, Window w);
static Window
find_client_win2(Display *dpy, Window w);

static void
get_frame_extents(Display *dpy, Window w,
Expand Down

0 comments on commit 0064894

Please sign in to comment.