From 334e2cc5f4f3145aef2215cfa90ec13d4c1937f7 Mon Sep 17 00:00:00 2001 From: David Maciejak Date: Sat, 13 Sep 2014 15:55:03 +0800 Subject: [PATCH] wmaker: improve windows listing in switchpanel This patch is updating makeWindowListArray function, as it crosses the whole window focused list each time we don't have to bother on checking previous and then next focused windows, so saving some cycles here. Signed-off-by: Carlos R. Mafra --- src/switchpanel.c | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/src/switchpanel.c b/src/switchpanel.c index 6ced6eb2..da0bac07 100644 --- a/src/switchpanel.c +++ b/src/switchpanel.c @@ -358,41 +358,22 @@ static void drawTitle(WSwitchPanel *panel, int idecks, const char *title) free(ntitle); } -static WMArray *makeWindowListArray(WWindow *curwin, int include_unmapped, Bool class_only) +static WMArray *makeWindowListArray(WScreen *scr, int include_unmapped, Bool class_only) { WMArray *windows = WMCreateArray(10); - int fl; - WWindow *wwin; + WWindow *wwin = scr->focused_window; - for (fl = 0; fl < 2; fl++) { - for (wwin = curwin; wwin; wwin = wwin->prev) { - if (((!fl && canReceiveFocus(wwin) > 0) || (fl && canReceiveFocus(wwin) < 0)) && - (wwin->flags.mapped || wwin->flags.shaded || include_unmapped)) { - if (class_only) - if (!sameWindowClass(wwin, curwin)) - continue; - - if (!WFLAGP(wwin, skip_switchpanel)) - WMAddToArray(windows, wwin); - } - } - wwin = curwin; - /* start over from the beginning of the list */ - while (wwin->next) - wwin = wwin->next; - - for (wwin = curwin; wwin && wwin != curwin; wwin = wwin->prev) { - if (((!fl && canReceiveFocus(wwin) > 0) || (fl && canReceiveFocus(wwin) < 0)) && - (wwin->flags.mapped || wwin->flags.shaded || include_unmapped)) { - if (class_only) - if (!sameWindowClass(wwin, curwin)) + while (wwin) { + if ((canReceiveFocus(wwin) != 0) && + (wwin->flags.mapped || wwin->flags.shaded || include_unmapped)) { + if (class_only) + if (!sameWindowClass(scr->focused_window, wwin)) continue; - if (!WFLAGP(wwin, skip_switchpanel)) + if (!WFLAGP(wwin, skip_switchpanel)) WMAddToArray(windows, wwin); - } } + wwin = wwin->prev; } - return windows; } @@ -416,7 +397,7 @@ WSwitchPanel *wInitSwitchPanel(WScreen *scr, WWindow *curwin, Bool class_only) WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr)); panel->scr = scr; - panel->windows = makeWindowListArray(curwin, wPreferences.swtileImage != NULL, class_only); + panel->windows = makeWindowListArray(scr, wPreferences.swtileImage != NULL, class_only); count = WMGetArrayItemCount(panel->windows); if (count) panel->flags = makeWindowFlagsArray(count); @@ -623,7 +604,7 @@ WWindow *wSwitchPanelSelectNext(WSwitchPanel *panel, int back, int ignore_minimi else panel->current++; - panel->current= (count + panel->current) % count; + panel->current = (count + panel->current) % count; wwin = WMGetFromArray(panel->windows, panel->current); if (!class_only)