diff options
author | Vito Caputo <vcaputo@gnugeneration.com> | 2017-03-12 13:11:40 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@gnugeneration.com> | 2017-03-14 19:41:48 -0700 |
commit | bc04055653fe64c4e8e109beedf96dd608007a3b (patch) | |
tree | aaf60b45a56f9d5765f6dcf6afa89bd62b9d46e2 | |
parent | 2373a54d2d52961a841dace71b505d2c20f5c040 (diff) |
*: trivial code formatting cleanups
I'm no longer fond of combining one-line conditional statements on
the same line as their conditional expression.
-rw-r--r-- | src/clickety.c | 27 | ||||
-rw-r--r-- | src/composite.c | 36 | ||||
-rw-r--r-- | src/context.c | 14 | ||||
-rw-r--r-- | src/desktop.c | 32 | ||||
-rw-r--r-- | src/key.c | 23 | ||||
-rw-r--r-- | src/launch.c | 3 | ||||
-rw-r--r-- | src/overlays.c | 60 | ||||
-rw-r--r-- | src/screen.c | 22 | ||||
-rw-r--r-- | src/vwm.c | 9 | ||||
-rw-r--r-- | src/window.c | 37 | ||||
-rw-r--r-- | src/xevent.c | 23 | ||||
-rw-r--r-- | src/xwindow.c | 48 |
12 files changed, 222 insertions, 112 deletions
diff --git a/src/clickety.c b/src/clickety.c index edfa123..7d69354 100644 --- a/src/clickety.c +++ b/src/clickety.c @@ -63,8 +63,11 @@ static void compute_resize(XEvent *terminus, XWindowAttributes *new) width_inc = vwin->hints->width_inc; height_inc = vwin->hints->height_inc; VWM_TRACE("window size hints exist and resize increments are w=%i h=%i", width_inc, height_inc); - if (!width_inc) width_inc = 1; - if (!height_inc) height_inc = 1; + if (!width_inc) + width_inc = 1; + + if (!height_inc) + height_inc = 1; } } @@ -99,12 +102,16 @@ static void compute_resize(XEvent *terminus, XWindowAttributes *new) /* constrain the width and height of the window according to the minimums */ if (new->width < min_width) { - if (clickety.orig.x != new->x) new->x -= (min_width - new->width); + if (clickety.orig.x != new->x) + new->x -= (min_width - new->width); + new->width = min_width; } if (new->height < min_height) { - if (clickety.orig.y != new->y) new->y -= (min_height - new->height); + if (clickety.orig.y != new->y) + new->y -= (min_height - new->height); + new->height = min_height; } } @@ -114,7 +121,8 @@ void vwm_clickety_motion(vwm_t *vwm, Window win, XMotionEvent *motion) { XWindowChanges changes = { .border_width = WINDOW_BORDER_WIDTH }; - if (!clickety.vwin) return; + if (!clickety.vwin) + return; /* TODO: verify win matches clickety.vwin? */ switch (clickety.mode) { @@ -150,7 +158,8 @@ void vwm_clickety_released(vwm_t *vwm, Window win, XButtonPressedEvent *terminus { XWindowChanges changes = { .border_width = WINDOW_BORDER_WIDTH }; - if (!clickety.vwin) return; + if (!clickety.vwin) + return; switch (clickety.mode) { case VWM_ADJUST_MOVE: @@ -192,9 +201,11 @@ int vwm_clickety_pressed(vwm_t *vwm, Window win, XButtonPressedEvent *impetus) vwm_window_t *vwin; /* verify the window still exists */ - if (!XGetWindowAttributes(VWM_XDISPLAY(vwm), win, &clickety.orig)) goto _fail; + if (!XGetWindowAttributes(VWM_XDISPLAY(vwm), win, &clickety.orig)) + goto _fail; - if (!(vwin = vwm_win_lookup(vwm, win))) goto _fail; + if (!(vwin = vwm_win_lookup(vwm, win))) + goto _fail; if (impetus->state & WM_GRAB_MODIFIER) { diff --git a/src/composite.c b/src/composite.c index 3f55863..a8c0f5d 100644 --- a/src/composite.c +++ b/src/composite.c @@ -60,7 +60,8 @@ static void unbind_namewindow(vwm_t *vwm, vwm_xwindow_t *xwin) void vwm_composite_xwin_create(vwm_t *vwm, vwm_xwindow_t *xwin) { - if (!compositing_mode) return; + if (!compositing_mode) + return; bind_namewindow(vwm, xwin); xwin->damage = XDamageCreate(VWM_XDISPLAY(vwm), xwin->id, XDamageReportNonEmpty); @@ -68,7 +69,8 @@ void vwm_composite_xwin_create(vwm_t *vwm, vwm_xwindow_t *xwin) void vwm_composite_xwin_destroy(vwm_t *vwm, vwm_xwindow_t *xwin) { - if (!compositing_mode) return; + if (!compositing_mode) + return; unbind_namewindow(vwm, xwin); XDamageDestroy(VWM_XDISPLAY(vwm), xwin->damage); @@ -95,15 +97,18 @@ void vwm_composite_damage_win(vwm_t *vwm, vwm_xwindow_t *xwin) xwin->attrs.width + xwin->attrs.border_width * 2, xwin->attrs.height + xwin->attrs.border_width * 2 }; - if (!compositing_mode) return; + if (!compositing_mode) + return; region = XFixesCreateRegion(VWM_XDISPLAY(vwm), &rect, 1); vwm_composite_damage_add(vwm, region); } -void vwm_composite_handle_configure(vwm_t *vwm, vwm_xwindow_t *xwin, XWindowAttributes *new_attrs) { - if (!compositing_mode) return; +void vwm_composite_handle_configure(vwm_t *vwm, vwm_xwindow_t *xwin, XWindowAttributes *new_attrs) +{ + if (!compositing_mode) + return; /* damage the old and new window areas */ XserverRegion region; @@ -123,8 +128,10 @@ void vwm_composite_handle_configure(vwm_t *vwm, vwm_xwindow_t *xwin, XWindowAttr } -void vwm_composite_handle_map(vwm_t *vwm, vwm_xwindow_t *xwin) { - if (!compositing_mode) return; +void vwm_composite_handle_map(vwm_t *vwm, vwm_xwindow_t *xwin) +{ + if (!compositing_mode) + return; vwm_composite_damage_win(vwm, xwin); unbind_namewindow(vwm, xwin); @@ -154,7 +161,8 @@ void vwm_composite_damage_event(vwm_t *vwm, XDamageNotifyEvent *ev) /* used in response to screen configuration changes... */ void vwm_composite_invalidate_root(vwm_t *vwm) { - if (!compositing_mode) return; + if (!compositing_mode) + return; if (root_picture) XRenderFreePicture(VWM_XDISPLAY(vwm), root_picture); root_picture = None; @@ -164,7 +172,8 @@ void vwm_composite_invalidate_root(vwm_t *vwm) void vwm_composite_repaint_needed(vwm_t *vwm) { - if (!compositing_mode) return; + if (!compositing_mode) + return; repaint_needed = 1; } @@ -179,7 +188,8 @@ void vwm_composite_paint_all(vwm_t *vwm) static XserverRegion undamage_region = None; /* if there's no damage to repaint, short-circuit, this happens when compositing for overlays is disabled. */ - if (!compositing_mode || (combined_damage == None && !repaint_needed)) return; + if (!compositing_mode || (combined_damage == None && !repaint_needed)) + return; repaint_needed = 0; @@ -203,7 +213,8 @@ void vwm_composite_paint_all(vwm_t *vwm) list_for_each_entry_prev(xwin, &vwm->xwindows, xwindows) { XRectangle r; - if (!vwm_xwin_is_mapped(vwm, xwin)) continue; /* if !mapped skip */ + if (!vwm_xwin_is_mapped(vwm, xwin)) + continue; /* if !mapped skip */ /* Everything mapped next goes through an occlusion check. * Since the composite extension stops delivery of VisibilityNotify events for redirected windows, @@ -254,7 +265,8 @@ void vwm_composite_paint_all(vwm_t *vwm) list_for_each_entry_prev(xwin, &vwm->xwindows, xwindows) { XRectangle r; - if (!vwm_xwin_is_mapped(vwm, xwin) || xwin->occluded) continue; /* if !mapped or occluded skip */ + if (!vwm_xwin_is_mapped(vwm, xwin) || xwin->occluded) + continue; /* if !mapped or occluded skip */ /* these coordinates + dimensions incorporate the border (since XCompositeNameWindowPixmap is being used) */ r.x = xwin->attrs.x; diff --git a/src/context.c b/src/context.c index 70494cf..2e41a7c 100644 --- a/src/context.c +++ b/src/context.c @@ -35,7 +35,8 @@ int vwm_context_focus(vwm_t *vwm, vwm_context_t desired_context) vwm_window_t *vwin; case VWM_CONTEXT_SHELF: - if (desired_context == VWM_CONTEXT_SHELF) break; + if (desired_context == VWM_CONTEXT_SHELF) + break; /* desired == DESKTOP && focused == SHELF */ @@ -45,7 +46,9 @@ int vwm_context_focus(vwm_t *vwm, vwm_context_t desired_context) /* map the focused desktop, from the top of the stack down */ list_for_each_entry_prev(xwin, &vwm->xwindows, xwindows) { - if (!(vwin = xwin->managed)) continue; + if (!(vwin = xwin->managed)) + continue; + if (vwin->desktop == vwm->focused_desktop && !vwin->shelved) { VWM_TRACE("Mapping desktop window \"%s\"", xwin->name); vwm_win_map(vwm, vwin); @@ -62,7 +65,8 @@ int vwm_context_focus(vwm_t *vwm, vwm_context_t desired_context) case VWM_CONTEXT_DESKTOP: /* unmap everything, map the shelf */ - if (desired_context == VWM_CONTEXT_DESKTOP) break; + if (desired_context == VWM_CONTEXT_DESKTOP) + break; /* desired == SHELF && focused == DESKTOP */ @@ -70,7 +74,9 @@ int vwm_context_focus(vwm_t *vwm, vwm_context_t desired_context) if (vwm->focused_shelf) { /* unmap everything on the current desktop */ list_for_each_entry(xwin, &vwm->xwindows, xwindows) { - if (!(vwin = xwin->managed)) continue; + if (!(vwin = xwin->managed)) + continue; + if (vwin->desktop == vwm->focused_desktop) { VWM_TRACE("Unmapping desktop window \"%s\"", xwin->name); vwm_win_unmap(vwm, vwin); diff --git a/src/desktop.c b/src/desktop.c index 2b5548a..7ddfc6f 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -49,15 +49,21 @@ int vwm_desktop_focus(vwm_t *vwm, vwm_desktop_t *desktop) /* unmap the windows on the currently focused desktop, map those on the newly focused one */ list_for_each_entry(xwin, &vwm->xwindows, xwindows) { - if (!(vwin = xwin->managed) || vwin->shelved) continue; - if (vwin->desktop == vwm->focused_desktop) vwm_win_unmap(vwm, vwin); + if (!(vwin = xwin->managed) || vwin->shelved) + continue; + + if (vwin->desktop == vwm->focused_desktop) + vwm_win_unmap(vwm, vwin); } XFlush(VWM_XDISPLAY(vwm)); list_for_each_entry_prev(xwin, &vwm->xwindows, xwindows) { - if (!(vwin = xwin->managed) || vwin->shelved) continue; - if (vwin->desktop == desktop) vwm_win_map(vwm, vwin); + if (!(vwin = xwin->managed) || vwin->shelved) + continue; + + if (vwin->desktop == desktop) + vwm_win_map(vwm, vwin); } vwm->focused_desktop = desktop; @@ -75,7 +81,8 @@ int vwm_desktop_focus(vwm_t *vwm, vwm_desktop_t *desktop) } /* return next MRU desktop relative to the supplied desktop */ -vwm_desktop_t * vwm_desktop_next_mru(vwm_t *vwm, vwm_desktop_t *desktop) { +vwm_desktop_t * vwm_desktop_next_mru(vwm_t *vwm, vwm_desktop_t *desktop) +{ list_head_t *next; /* this dance is necessary because the list head @ vwm->desktops_mru has no vwm_desktop_t container, @@ -92,20 +99,20 @@ vwm_desktop_t * vwm_desktop_next_mru(vwm_t *vwm, vwm_desktop_t *desktop) { } /* return next desktop spatially relative to the supplied desktop, no wrap-around */ -vwm_desktop_t * vwm_desktop_next(vwm_t *vwm, vwm_desktop_t *desktop) { - if (desktop->desktops.next != &vwm->desktops) { +vwm_desktop_t * vwm_desktop_next(vwm_t *vwm, vwm_desktop_t *desktop) +{ + if (desktop->desktops.next != &vwm->desktops) desktop = list_entry(desktop->desktops.next, vwm_desktop_t, desktops); - } return desktop; } /* return previous desktop spatially relative to the supplied desktop, no wrap-around */ -vwm_desktop_t * vwm_desktop_prev(vwm_t *vwm, vwm_desktop_t *desktop) { - if (desktop->desktops.prev != &vwm->desktops) { +vwm_desktop_t * vwm_desktop_prev(vwm_t *vwm, vwm_desktop_t *desktop) +{ + if (desktop->desktops.prev != &vwm->desktops) desktop = list_entry(desktop->desktops.prev, vwm_desktop_t, desktops); - } return desktop; } @@ -140,7 +147,8 @@ void vwm_desktop_destroy(vwm_t *vwm, vwm_desktop_t *desktop) /* silently refuse to destroy a desktop having windows (for now) */ /* there's _always_ a focused window on a desktop having mapped windows */ /* also silently refuse to destroy the last desktop (for now) */ - if (desktop->focused_window || (desktop->desktops.next == desktop->desktops.prev)) return; + if (desktop->focused_window || (desktop->desktops.next == desktop->desktops.prev)) + return; /* focus the MRU desktop that isn't this one if we're the focused desktop */ if (desktop == vwm->focused_desktop) { @@ -31,14 +31,16 @@ static int key_is_grabbed; /* flag for tracking keyboard grab state */ /* Poll the keyboard state to see if _any_ keys are pressed */ -static int keys_pressed(vwm_t *vwm) { +static int keys_pressed(vwm_t *vwm) +{ int i; char state[32]; XQueryKeymap(VWM_XDISPLAY(vwm), state); for (i = 0; i < sizeof(state); i++) { - if (state[i]) return 1; + if (state[i]) + return 1; } return 0; @@ -67,10 +69,12 @@ void vwm_key_released(vwm_t *vwm, Window win, XKeyReleasedEvent *keyrelease) } /* make the focused window the most recently used */ - if ((vwin = vwm_win_focused(vwm))) vwm_win_mru(vwm, vwin); + if ((vwin = vwm_win_focused(vwm))) + vwm_win_mru(vwm, vwin); /* make the focused desktop the most recently used */ - if (vwm->focused_context == VWM_CONTEXT_DESKTOP && vwm->focused_desktop) vwm_desktop_mru(vwm, vwm->focused_desktop); + if (vwm->focused_context == VWM_CONTEXT_DESKTOP && vwm->focused_desktop) + vwm_desktop_mru(vwm, vwm->focused_desktop); break; @@ -122,7 +126,9 @@ void vwm_key_pressed(vwm_t *vwm, Window win, XKeyPressedEvent *keypress) #undef launcher case XK_Alt_L: /* transaction abort */ case XK_Alt_R: - if (key_is_grabbed) key_is_grabbed++; + if (key_is_grabbed) + key_is_grabbed++; + VWM_TRACE("aborting with origin %p", vwm->focused_origin); break; @@ -150,7 +156,8 @@ void vwm_key_pressed(vwm_t *vwm, Window win, XKeyPressedEvent *keypress) if (keypress->state & ShiftMask) { /* migrate the focused window with the desktop focus to the most recently used desktop */ - if (vwin) vwm_win_migrate(vwm, vwin, next_desktop); + if (vwin) + vwm_win_migrate(vwm, vwin, next_desktop); } else { vwm_desktop_focus(vwm, next_desktop); } @@ -291,7 +298,9 @@ void vwm_key_pressed(vwm_t *vwm, Window win, XKeyPressedEvent *keypress) break; case XK_s: /* shelve focused window */ - if (vwin && !vwin->shelved) vwm_win_shelve(vwm, vwin); + if (vwin && !vwin->shelved) + vwm_win_shelve(vwm, vwin); + break; case XK_bracketleft: /* reconfigure the focused window to occupy the left or top half of the screen or left quarters on repeat */ diff --git a/src/launch.c b/src/launch.c index 123e850..ed4064b 100644 --- a/src/launch.c +++ b/src/launch.c @@ -39,7 +39,8 @@ void vwm_launch(vwm_t *vwm, char **argv, vwm_launch_mode_t mode) setpriority(PRIO_PROCESS, getpid(), vwm->priority + LAUNCHED_RELATIVE_PRIORITY); execvp(argv[0], argv); } - if (mode == VWM_LAUNCH_MODE_BG) exit(0); + if (mode == VWM_LAUNCH_MODE_BG) + exit(0); } wait(NULL); /* TODO: could wait for the specific pid, particularly in FG mode ... */ } diff --git a/src/overlays.c b/src/overlays.c index e994dca..15f351c 100644 --- a/src/overlays.c +++ b/src/overlays.c @@ -361,7 +361,8 @@ static void argv2xtext(vmon_proc_t *proc, XTextItem *items, int max_items, int * /* helper for counting number of existing descendants subtrees */ -static int count_rows(vmon_proc_t *proc) { +static int count_rows(vmon_proc_t *proc) +{ int count = 1; /* XXX maybe suppress proc->is_new? */ vmon_proc_t *child; @@ -380,19 +381,23 @@ static int count_rows(vmon_proc_t *proc) { /* helper for detecting if any children/threads in the process heirarchy rooted @ proc are new/stale this sample */ -static int proc_heirarchy_changed(vmon_proc_t *proc) { +static int proc_heirarchy_changed(vmon_proc_t *proc) +{ vmon_proc_t *child; - if (proc->children_changed || proc->threads_changed) return 1; + if (proc->children_changed || proc->threads_changed) + return 1; if (!proc->is_thread) { list_for_each_entry(child, &proc->threads, threads) { - if (proc_heirarchy_changed(child)) return 1; + if (proc_heirarchy_changed(child)) + return 1; } } list_for_each_entry(child, &proc->children, siblings) { - if (proc_heirarchy_changed(child)) return 1; + if (proc_heirarchy_changed(child)) + return 1; } return 0; @@ -411,8 +416,11 @@ static void draw_bars(vwm_overlays_t *overlays, vwm_overlay_t *overlay, int row, /* round up to 1 pixel when the scaled result is a fraction less than 1, * I want to at least see 1 pixel blips for the slightest cpu utilization */ - if (a_fraction && !a_height) a_height = 1; - if (b_fraction && !b_height) b_height = 1; + if (a_fraction && !a_height) + a_height = 1; + + if (b_fraction && !b_height) + b_height = 1; /* draw the two bars for this sample at the current phase in the graphs, note the first is ceiling-based, second floor-based */ XRenderFillRectangle(xserver->display, PictOpSrc, overlay->grapha_picture, &overlay_visible_color, @@ -443,7 +451,8 @@ static void draw_heirarchy_row(vwm_overlays_t *overlays, vwm_overlay_t *overlay, !BITTEST(proc_stat->changed, VMON_PROC_STAT_WCHAN) && !BITTEST(proc_stat->changed, VMON_PROC_STAT_PID) && !BITTEST(proc_stat->changed, VMON_PROC_STAT_STATE) && - !BITTEST(proc_stat->changed, VMON_PROC_STAT_ARGV)) return; + !BITTEST(proc_stat->changed, VMON_PROC_STAT_ARGV)) + return; /* TODO: make the columns interactively configurable @ runtime */ if (!proc->is_new) { @@ -519,13 +528,15 @@ static void draw_heirarchy_row(vwm_overlays_t *overlays, vwm_overlay_t *overlay, /* find the last sibling (this has to be done due to the potential for stale siblings at the tail, and we'd rather not repeatedly check for it) */ list_for_each_entry(sibling, &proc->parent->children, siblings) { - if (!sibling->is_stale) last_sibling = sibling; + if (!sibling->is_stale) + last_sibling = sibling; } /* now look for siblings with non-stale children to determine if a tee is needed, ignoring the last sibling */ list_for_each_entry(sibling, &proc->parent->children, siblings) { /* skip stale siblings, they aren't interesting as they're invisible, and the last sibling has no bearing on wether we tee or not. */ - if (sibling->is_stale || sibling == last_sibling) continue; + if (sibling->is_stale || sibling == last_sibling) + continue; /* if any of the other siblings have children which are not stale, put a tee in front of our name, but ignore stale children */ list_for_each_entry(child, &sibling->children, siblings) { @@ -747,7 +758,8 @@ static void draw_overlay(vwm_overlays_t *overlays, vwm_overlay_t *overlay, vmon_ } (*row)++; - if (!overlay->redraw_needed) heirarchy_changed = proc_heirarchy_changed(proc); + if (!overlay->redraw_needed) + heirarchy_changed = proc_heirarchy_changed(proc); draw_overlay_rest(overlays, overlay, proc, depth, row, heirarchy_changed); @@ -764,7 +776,8 @@ static void maintain_overlay(vwm_overlays_t *overlays, vwm_overlay_t *overlay) vwm_xserver_t *xserver = overlays->xserver; int row = 0, depth = 0; - if (!overlay->monitor || !overlay->monitor->stores[VMON_STORE_PROC_STAT]) return; + if (!overlay->monitor || !overlay->monitor->stores[VMON_STORE_PROC_STAT]) + return; /* TODO: * A side effect of responding to window resizes in this function is there's a latency proportional to the current sample_interval. @@ -849,7 +862,8 @@ int vwm_overlay_set_visible_size(vwm_overlays_t *overlays, vwm_overlay_t *overla { vwm_xserver_t *xserver = overlays->xserver; - if (width != overlay->visible_width || height != overlay->visible_height) overlay->redraw_needed = 1; + if (width != overlay->visible_width || height != overlay->visible_height) + overlay->redraw_needed = 1; /* TODO error handling: if a create failed but we had an overlay, free whatever we created and leave it be, succeed. * if none existed it's a hard error and we must propagate it. */ @@ -989,9 +1003,12 @@ void vwm_overlay_compose(vwm_overlays_t *overlays, vwm_overlay_t *overlay, Xserv vwm_xserver_t *xserver = overlays->xserver; int height; - if (!overlay->width || !overlay->height) return; + if (!overlay->width || !overlay->height) + return; + + if (overlay->gen_last_composed == overlay->monitor->generation) + return; /* noop if no sampling occurred since last compose */ - if (overlay->gen_last_composed == overlay->monitor->generation) return; /* noop if no sampling occurred since last compose */ overlay->gen_last_composed = overlay->monitor->generation; /* remember this generation */ //VWM_TRACE("composing %p", overlay); @@ -1054,7 +1071,8 @@ void vwm_overlay_render(vwm_overlays_t *overlays, vwm_overlay_t *overlay, Pictur { vwm_xserver_t *xserver = overlays->xserver; - if (!overlay->width || !overlay->height) return; + if (!overlay->width || !overlay->height) + return; /* draw the monitoring overlay atop dest, note we stay within the window borders here. */ XRenderComposite(xserver->display, PictOpOver, overlay->picture, None, dest, @@ -1067,13 +1085,15 @@ void vwm_overlay_render(vwm_overlays_t *overlays, vwm_overlay_t *overlay, Pictur void vwm_overlays_rate_increase(vwm_overlays_t *overlays) { - if (overlays->sampling_interval + 1 < sizeof(sampling_intervals) / sizeof(sampling_intervals[0])) overlays->sampling_interval++; + if (overlays->sampling_interval + 1 < sizeof(sampling_intervals) / sizeof(sampling_intervals[0])) + overlays->sampling_interval++; } void vwm_overlays_rate_decrease(vwm_overlays_t *overlays) { - if (overlays->sampling_interval >= 0) overlays->sampling_interval--; + if (overlays->sampling_interval >= 0) + overlays->sampling_interval--; } @@ -1109,7 +1129,8 @@ int vwm_overlays_update(vwm_overlays_t *overlays, int *desired_delay) this_delta >= (sampling_intervals[overlays->sampling_interval] * 1.5)) { overlays->contiguous_drops++; /* require > 1 contiguous drops before lowering the rate, tolerates spurious one-off stalls */ - if (overlays->contiguous_drops > 2) overlays->sampling_interval--; + if (overlays->contiguous_drops > 2) + overlays->sampling_interval--; } else overlays->contiguous_drops = 0; /* age the sys-wide sample data into "last" variables, before the new sample overwrites them. */ @@ -1138,7 +1159,6 @@ int vwm_overlays_update(vwm_overlays_t *overlays, int *desired_delay) overlays->prev_sampling_interval = overlays->sampling_interval; } - /* TODO: make some effort to compute how long to sleep, but this is perfectly fine for now. */ *desired_delay = overlays->sampling_interval != -1 ? sampling_intervals[overlays->sampling_interval] * 300.0 : -1; diff --git a/src/screen.c b/src/screen.c index 4136d95..b09356e 100644 --- a/src/screen.c +++ b/src/screen.c @@ -61,7 +61,8 @@ const vwm_screen_t * vwm_screen_find(vwm_t *vwm, vwm_screen_rel_t rel, ...) faux.width = WidthOfScreen(DefaultScreenOfDisplay(VWM_XDISPLAY(vwm))); faux.height = HeightOfScreen(DefaultScreenOfDisplay(VWM_XDISPLAY(vwm))); - if (!vwm->xinerama_screens) goto _out; + if (!vwm->xinerama_screens) + goto _out; #define for_each_screen(_tmp) \ for (i = 0, _tmp = vwm->xinerama_screens; i < vwm->xinerama_screens_cnt; _tmp = &vwm->xinerama_screens[++i]) @@ -108,10 +109,17 @@ const vwm_screen_t * vwm_screen_find(vwm_t *vwm, vwm_screen_rel_t rel, ...) short x1 = MAXSHORT, y1 = MAXSHORT, x2 = MINSHORT, y2 = MINSHORT; /* find the smallest x_org and y_org, the highest x_org + width and y_org + height, those are the two corners of the total rect */ for_each_screen(scr) { - if (scr->x_org < x1) x1 = scr->x_org; - if (scr->y_org < y1) y1 = scr->y_org; - if (scr->x_org + scr->width > x2) x2 = scr->x_org + scr->width; - if (scr->y_org + scr->height > y2) y2 = scr->y_org + scr->height; + if (scr->x_org < x1) + x1 = scr->x_org; + + if (scr->y_org < y1) + y1 = scr->y_org; + + if (scr->x_org + scr->width > x2) + x2 = scr->x_org + scr->width; + + if (scr->y_org + scr->height > y2) + y2 = scr->y_org + scr->height; } faux.x_org = x1; faux.y_org = y1; @@ -135,7 +143,9 @@ int vwm_screen_is_empty(vwm_t *vwm, const vwm_screen_t *scr) int is_empty = 1; list_for_each_entry(xwin, &vwm->xwindows, xwindows) { - if (!xwin->mapped) continue; + if (!xwin->mapped) + continue; + if (!xwin->managed || (xwin->managed->desktop == vwm->focused_desktop && !xwin->managed->shelved && !xwin->managed->configuring)) { /* XXX: it may make more sense to see what %age of the screen is overlapped by windows, and consider it empty if < some % */ /* This is just seeing if any window is predominantly within the specified screen, the rationale being if you had a focusable @@ -278,7 +278,8 @@ void vwm_process_event(vwm_t *vwm) default: if (event.type == randr_event + RRScreenChangeNotify) { VWM_TRACE("rrscreenchangenotify"); - if (vwm->xinerama_screens) XFree(vwm->xinerama_screens); + if (vwm->xinerama_screens) + XFree(vwm->xinerama_screens); vwm->xinerama_screens = XineramaQueryScreens(VWM_XDISPLAY(vwm), &vwm->xinerama_screens_cnt); vwm_composite_invalidate_root(vwm); @@ -311,12 +312,14 @@ int main(int argc, char *argv[]) do { int delay; - if (vwm_overlays_update(vwm->overlays, &delay)) vwm_composite_repaint_needed(vwm); + if (vwm_overlays_update(vwm->overlays, &delay)) + vwm_composite_repaint_needed(vwm); XFlush(VWM_XDISPLAY(vwm)); if (!XPending(VWM_XDISPLAY(vwm))) { - if (poll(&pfd, 1, delay) == 0) break; + if (poll(&pfd, 1, delay) == 0) + break; } vwm_process_event(vwm); diff --git a/src/window.c b/src/window.c index fa62841..fcd82c5 100644 --- a/src/window.c +++ b/src/window.c @@ -34,6 +34,7 @@ void vwm_win_unmap(vwm_t *vwm, vwm_window_t *vwin) VWM_TRACE("inhibited unmap of \"%s\", not mapped by client", vwin->xwindow->name); return; } + VWM_TRACE("Unmapping \"%s\"", vwin->xwindow->name); vwin->unmapping = 1; XUnmapWindow(VWM_XDISPLAY(vwm), vwin->xwindow->id); @@ -47,6 +48,7 @@ void vwm_win_map(vwm_t *vwm, vwm_window_t *vwin) VWM_TRACE("inhibited map of \"%s\", not mapped by client", vwin->xwindow->name); return; } + VWM_TRACE("Mapping \"%s\"", vwin->xwindow->name); vwin->mapping = 1; XMapWindow(VWM_XDISPLAY(vwm), vwin->xwindow->id); @@ -87,7 +89,8 @@ vwm_window_t * vwm_win_focused(vwm_t *vwm) break; case VWM_CONTEXT_DESKTOP: - if (vwm->focused_desktop) vwin = vwm->focused_desktop->focused_window; + if (vwm->focused_desktop) + vwin = vwm->focused_desktop->focused_window; break; default: @@ -107,7 +110,8 @@ void vwm_win_autoconf(vwm_t *vwm, vwm_window_t *vwin, vwm_screen_rel_t rel, vwm_ XWindowChanges changes = { .border_width = WINDOW_BORDER_WIDTH }; /* remember the current configuration as the "client" configuration if it's not an autoconfigured one. */ - if (vwin->autoconfigured == VWM_WIN_AUTOCONF_NONE) vwin->client = vwin->xwindow->attrs; + if (vwin->autoconfigured == VWM_WIN_AUTOCONF_NONE) + vwin->client = vwin->xwindow->attrs; scr = vwm_screen_find(vwm, rel, vwin->xwindow); /* XXX FIXME: this becomes a bug when vwm_screen_find() uses non-xwin va_args */ va_start(ap, conf); @@ -246,7 +250,8 @@ _retry: visited_mask = 0; list_for_each_entry(next, &vwin->windows_mru, windows_mru) { /* searching for the next mapped window in this context, using vwin->windows as the head */ - if (&next->windows_mru == &vwm->windows_mru) continue; /* XXX: skip the containerless head, we're leveraging the circular list implementation */ + if (&next->windows_mru == &vwm->windows_mru) + continue; /* XXX: skip the containerless head, we're leveraging the circular list implementation */ if ((vwin->shelved && next->shelved) || ((!vwin->shelved && !next->shelved && next->desktop == vwin->desktop) && @@ -255,9 +260,11 @@ _retry: (fence == VWM_FENCE_VIOLATE && vwm_screen_find(vwm, VWM_SCREEN_REL_XWIN, next->xwindow) != scr) || (fence == VWM_FENCE_MASKED_VIOLATE && (next_scr = vwm_screen_find(vwm, VWM_SCREEN_REL_XWIN, next->xwindow)) != scr && !((1UL << next_scr->screen_number) & vwm->fence_mask)) - ))) break; + ))) + break; - if (fence == VWM_FENCE_MASKED_VIOLATE && next_scr && next_scr != scr) visited_mask |= (1UL << next_scr->screen_number); + if (fence == VWM_FENCE_MASKED_VIOLATE && next_scr && next_scr != scr) + visited_mask |= (1UL << next_scr->screen_number); } if (fence == VWM_FENCE_TRY_RESPECT && next == vwin) { @@ -306,17 +313,16 @@ _retry: void vwm_win_shelve(vwm_t *vwm, vwm_window_t *vwin) { /* already shelved, NOOP */ - if (vwin->shelved) return; + if (vwin->shelved) + return; /* shelving focused window, focus the next window */ - if (vwin == vwin->desktop->focused_window) { + if (vwin == vwin->desktop->focused_window) vwm_win_mru(vwm, vwm_win_focus_next(vwm, vwin, VWM_FENCE_RESPECT)); - } - if (vwin == vwin->desktop->focused_window) { + if (vwin == vwin->desktop->focused_window) /* TODO: we can probably put this into vwm_win_focus_next() and have it always handled there... */ vwin->desktop->focused_window = NULL; - } vwin->shelved = 1; vwm_win_mru(vwm, vwin); @@ -365,8 +371,11 @@ vwm_xwindow_t * vwm_win_unmanage(vwm_t *vwm, vwm_window_t *vwin) vwm_win_unfocus(vwm, vwin); list_del(&vwin->windows_mru); - if (vwin == vwm->console) vwm->console = NULL; - if (vwin == vwm->focused_origin) vwm->focused_origin = NULL; + if (vwin == vwm->console) + vwm->console = NULL; + + if (vwin == vwm->focused_origin) + vwm->focused_origin = NULL; vwin->xwindow->managed = NULL; @@ -446,9 +455,11 @@ vwm_window_t * vwm_win_manage_xwin(vwm_t *vwm, vwm_xwindow_t *xwin) _fail: if (vwin) { - if (vwin->hints) XFree(vwin->hints); + if (vwin->hints) + XFree(vwin->hints); free(vwin); } + return NULL; } diff --git a/src/xevent.c b/src/xevent.c index 1d79ae6..4a76ea2 100644 --- a/src/xevent.c +++ b/src/xevent.c @@ -70,9 +70,8 @@ void vwm_xevent_handle_destroy_notify(vwm_t *vwm, XDestroyWindowEvent *ev) { vwm_xwindow_t *xwin; - if ((xwin = vwm_xwin_lookup(vwm, ev->window))) { + if ((xwin = vwm_xwin_lookup(vwm, ev->window))) vwm_xwin_destroy(vwm, xwin); - } } @@ -92,10 +91,9 @@ void vwm_xevent_handle_configure_request(vwm_t *vwm, XConfigureRequestEvent *ev) if ((xwin = vwm_xwin_lookup(vwm, ev->window)) && xwin->managed && - xwin->managed->autoconfigured == VWM_WIN_AUTOCONF_ALL) { + xwin->managed->autoconfigured == VWM_WIN_AUTOCONF_ALL) /* this is to allow auto-allscreen to succeed in getting a borderless window configured */ change_mask &= ~CWBorderWidth; - } XConfigureWindow(VWM_XDISPLAY(vwm), ev->window, change_mask, &changes); } @@ -110,7 +108,8 @@ void vwm_xevent_handle_configure_notify(vwm_t *vwm, XConfigureEvent *ev) vwm_xwin_restack(vwm, xwin, ev->above); XGetWindowAttributes(VWM_XDISPLAY(vwm), ev->window, &attrs); vwm_composite_handle_configure(vwm, xwin, &attrs); - if (xwin->overlay) vwm_overlay_set_visible_size(vwm->overlays, xwin->overlay, attrs.width, attrs.height); + if (xwin->overlay) + vwm_overlay_set_visible_size(vwm->overlays, xwin->overlay, attrs.width, attrs.height); VWM_TRACE("pre x=%i y=%i w=%i h=%i\n", xwin->attrs.x, xwin->attrs.y, xwin->attrs.width, xwin->attrs.height); xwin->attrs = attrs; @@ -155,9 +154,8 @@ void vwm_xevent_handle_map_notify(vwm_t *vwm, XMapEvent *ev) * which unless the window's an override_redirect is incorrect. * So implicitly manage the window if it's not managed and !override_redirect, since it's now mapped. */ - if (!xwin->managed && !xwin->attrs.override_redirect) { + if (!xwin->managed && !xwin->attrs.override_redirect) xwin->managed = vwm_win_manage_xwin(vwm, xwin); - } if (xwin->managed && xwin->managed->mapping) { VWM_TRACE("swallowed vwm-induced MapNotify"); @@ -200,8 +198,12 @@ void vwm_xevent_handle_map_request(vwm_t *vwm, XMapRequestEvent *ev) domap = 0; } - if (classhint->res_class) XFree(classhint->res_class); - if (classhint->res_name) XFree(classhint->res_name); + if (classhint->res_class) + XFree(classhint->res_class); + + if (classhint->res_name) + XFree(classhint->res_name); + XFree(classhint); } @@ -271,7 +273,8 @@ void vwm_xevent_handle_property_notify(vwm_t *vwm, XPropertyEvent *ev) if ((xwin = vwm_xwin_lookup(vwm, ev->window)) && ev->atom == vwm->wm_pid_atom && - ev->state == PropertyNewValue) vwm_xwin_setup_overlay(vwm, xwin); + ev->state == PropertyNewValue) + vwm_xwin_setup_overlay(vwm, xwin); } diff --git a/src/xwindow.c b/src/xwindow.c index 8dd2937..ada7845 100644 --- a/src/xwindow.c +++ b/src/xwindow.c @@ -73,11 +73,13 @@ int vwm_xwin_is_mapped(vwm_t *vwm, vwm_xwindow_t *xwin) if (xwin->managed) { switch (vwm->focused_context) { case VWM_CONTEXT_SHELF: - if (vwm->focused_shelf == xwin->managed) ret = xwin->mapped; + if (vwm->focused_shelf == xwin->managed) + ret = xwin->mapped; break; case VWM_CONTEXT_DESKTOP: - if (vwm->focused_desktop == xwin->managed->desktop && !xwin->managed->shelved) ret = xwin->mapped; + if (vwm->focused_desktop == xwin->managed->desktop && !xwin->managed->shelved) + ret = xwin->mapped; break; default: @@ -106,7 +108,8 @@ static int vwm_xwin_get_pid(vwm_t *vwm, vwm_xwindow_t *xwin) int pid; if (XGetWindowProperty(VWM_XDISPLAY(vwm), xwin->id, vwm->wm_pid_atom, 0, 1, False, XA_CARDINAL, - &type, &fmt, &nitems, &nbytes, (unsigned char **)&foo) != Success || !foo) return -1; + &type, &fmt, &nitems, &nbytes, (unsigned char **)&foo) != Success || !foo) + return -1; pid = *foo; XFree(foo); @@ -124,7 +127,8 @@ void vwm_xwin_setup_overlay(vwm_t *vwm, vwm_xwindow_t *xwin) if (!xwin->attrs.override_redirect) { int pid = vwm_xwin_get_pid(vwm, xwin); - if (pid != -1) xwin->overlay = vwm_overlay_create(vwm->overlays, pid, xwin->attrs.width, xwin->attrs.height); + if (pid != -1) + xwin->overlay = vwm_overlay_create(vwm->overlays, pid, xwin->attrs.width, xwin->attrs.height); } } @@ -145,10 +149,12 @@ vwm_xwindow_t * vwm_xwin_create(vwm_t *vwm, Window win, vwm_grab_mode_t grabbed) } /* verify the window still exists */ - if (!XGetWindowAttributes(VWM_XDISPLAY(vwm), win, &attrs)) goto _out_grabbed; + if (!XGetWindowAttributes(VWM_XDISPLAY(vwm), win, &attrs)) + goto _out_grabbed; /* don't create InputOnly windows */ - if (attrs.class == InputOnly) goto _out_grabbed; + if (attrs.class == InputOnly) + goto _out_grabbed; if (!(xwin = (vwm_xwindow_t *)calloc(1, sizeof(vwm_xwindow_t)))) { VWM_PERROR("Failed to allocate xwin"); @@ -174,12 +180,15 @@ vwm_xwindow_t * vwm_xwin_create(vwm_t *vwm, Window win, vwm_grab_mode_t grabbed) list_add_tail(&xwin->xwindows, &vwm->xwindows); /* created windows are always placed on the top of the stacking order */ #ifdef HONOR_OVERRIDE_REDIRECT - if (!attrs.override_redirect && xwin->mapped) vwm_win_manage_xwin(vwm, xwin); + if (!attrs.override_redirect && xwin->mapped) + vwm_win_manage_xwin(vwm, xwin); #else - if (xwin->mapped) vwm_win_manage_xwin(vwm, xwin); + if (xwin->mapped) + vwm_win_manage_xwin(vwm, xwin); #endif _out_grabbed: - if (!grabbed) XUngrabServer(VWM_XDISPLAY(vwm)); + if (!grabbed) + XUngrabServer(VWM_XDISPLAY(vwm)); return xwin; } @@ -192,13 +201,16 @@ void vwm_xwin_destroy(vwm_t *vwm, vwm_xwindow_t *xwin) XGrabServer(VWM_XDISPLAY(vwm)); XSync(VWM_XDISPLAY(vwm), False); - if (xwin->managed) vwm_win_unmanage(vwm, xwin->managed); + if (xwin->managed) + vwm_win_unmanage(vwm, xwin->managed); list_del(&xwin->xwindows); - if (xwin->name) XFree(xwin->name); + if (xwin->name) + XFree(xwin->name); - if (xwin->overlay) vwm_overlay_destroy(vwm->overlays, xwin->overlay); + if (xwin->overlay) + vwm_overlay_destroy(vwm->overlays, xwin->overlay); vwm_composite_xwin_destroy(vwm, xwin); @@ -258,21 +270,25 @@ int vwm_xwin_create_existing(vwm_t *vwm) XQueryTree(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), &root, &parent, &children, &n_children); for (i = 0; i < n_children; i++) { - if (children[i] == None) continue; + if (children[i] == None) + continue; - if ((vwm_xwin_create(vwm, children[i], VWM_GRABBED) == NULL)) goto _fail_grabbed; + if ((vwm_xwin_create(vwm, children[i], VWM_GRABBED) == NULL)) + goto _fail_grabbed; } XUngrabServer(VWM_XDISPLAY(vwm)); - if (children) XFree(children); + if (children) + XFree(children); return 1; _fail_grabbed: XUngrabServer(VWM_XDISPLAY(vwm)); - if (children) XFree(children); + if (children) + XFree(children); return 0; } |