<table><tr><td style="">zzag added a reviewer: KWin.<br />zzag added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D24044">View Revision</a></tr></table><br /><div><div><p>What about simplifying it a bit as well? e.g.</p>
<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="js" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);"><span style="color: #aa4000">function</span> <span style="color: #004012">minimizeAllWindows</span><span class="p">()</span> <span class="p">{</span>
<span style="color: #aa4000">var</span> <span style="color: #004012">allClients</span> <span style="color: #aa2211">=</span> <span style="color: #004012">workspace</span><span class="p">.</span><span style="color: #004012">clientList</span><span class="p">();</span>
<span style="color: #aa4000">var</span> <span style="color: #004012">relevantClients</span> <span style="color: #aa2211">=</span> <span class="p">[];</span>
<span style="color: #aa4000">var</span> <span style="color: #004012">minimize</span> <span style="color: #aa2211">=</span> <span style="color: #000a65">false</span><span class="p">;</span>
<span style="color: #aa4000">for</span> <span class="p">(</span><span style="color: #aa4000">var</span> <span style="color: #004012">i</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span> <span style="color: #004012">i</span> <span style="color: #aa2211"><</span> <span style="color: #004012">allClients</span><span class="p">.</span><span style="color: #004012">length</span><span class="p">;</span> <span style="color: #aa2211">++</span><span style="color: #004012">i</span><span class="p">)</span> <span class="p">{</span>
<span style="color: #aa4000">if</span> <span class="p">(</span><span style="color: #aa2211">!</span><span style="color: #004012">isRelevant</span><span class="p">(</span><span style="color: #004012">allClients</span><span class="p">[</span><span style="color: #004012">i</span><span class="p">]))</span> <span class="p">{</span>
<span style="color: #aa4000">continue</span><span class="p">;</span>
<span class="p">}</span>
<span style="color: #aa4000">if</span> <span class="p">(</span><span style="color: #aa2211">!</span><span style="color: #004012">allClients</span><span class="p">[</span><span style="color: #004012">i</span><span class="p">].</span><span style="color: #004012">minimized</span><span class="p">)</span> <span class="p">{</span>
<span style="color: #004012">minimize</span> <span style="color: #aa2211">=</span> <span style="color: #000a65">true</span><span class="p">;</span>
<span class="p">}</span>
<span style="color: #004012">relevantClients</span><span class="p">.</span><span style="color: #004012">push</span><span class="p">(</span><span style="color: #004012">allClients</span><span class="p">[</span><span style="color: #004012">i</span><span class="p">]);</span>
<span class="p">}</span>
<span style="color: #aa4000">for</span> <span class="p">(</span><span style="color: #aa4000">var</span> <span style="color: #004012">i</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span> <span style="color: #004012">i</span> <span style="color: #aa2211"><</span> <span style="color: #004012">relevantClients</span><span class="p">.</span><span style="color: #004012">length</span><span class="p">;</span> <span style="color: #aa2211">++</span><span style="color: #004012">i</span><span class="p">)</span> <span class="p">{</span>
<span style="color: #aa4000">var</span> <span style="color: #004012">wasMinimizedByScript</span> <span style="color: #aa2211">=</span> <span style="color: #004012">relevantClients</span><span class="p">[</span><span style="color: #004012">i</span><span class="p">].</span><span style="color: #004012">minimizedByScript</span><span class="p">;</span>
<span style="color: #aa4000">delete</span> <span style="color: #004012">relevantClients</span><span class="p">[</span><span style="color: #004012">i</span><span class="p">].</span><span style="color: #004012">minimizedByScript</span><span class="p">;</span>
<span style="color: #aa4000">if</span> <span class="p">(</span><span style="color: #004012">minimize</span><span class="p">)</span> <span class="p">{</span>
<span style="color: #aa4000">if</span> <span class="p">(</span><span style="color: #004012">relevantClients</span><span class="p">[</span><span style="color: #004012">i</span><span class="p">].</span><span style="color: #004012">minimized</span><span class="p">)</span> <span class="p">{</span>
<span style="color: #aa4000">continue</span><span class="p">;</span>
<span class="p">}</span>
<span style="color: #004012">relevantClients</span><span class="p">[</span><span style="color: #004012">i</span><span class="p">].</span><span style="color: #004012">minimized</span> <span style="color: #aa2211">=</span> <span style="color: #000a65">true</span><span class="p">;</span>
<span style="color: #004012">relevantClients</span><span class="p">[</span><span style="color: #004012">i</span><span class="p">].</span><span style="color: #004012">minimizedByScript</span> <span style="color: #aa2211">=</span> <span style="color: #000a65">true</span><span class="p">;</span>
<span class="p">}</span> <span style="color: #aa4000">else</span> <span class="p">{</span>
<span style="color: #aa4000">if</span> <span class="p">(</span><span style="color: #aa2211">!</span><span style="color: #004012">wasMinimizedByScript</span><span class="p">)</span> <span class="p">{</span>
<span style="color: #aa4000">continue</span><span class="p">;</span>
<span class="p">}</span>
<span style="color: #004012">relevantClients</span><span class="p">[</span><span style="color: #004012">i</span><span class="p">].</span><span style="color: #004012">minimized</span> <span style="color: #aa2211">=</span> <span style="color: #000a65">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span></pre></div>
<p>(I didn't test this script though)</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R108 KWin</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D24044">https://phabricator.kde.org/D24044</a></div></div><br /><div><strong>To: </strong>smerkov, colomar, KWin<br /><strong>Cc: </strong>zzag, kwin, LeGast00n, The-Feren-OS-Dev, sbergeron, jraleigh, fbampaloukas, GB_2, mkulinski, ragreen, jackyalcine, iodelay, crozbo, bwowk, ZrenBot, ngraham, alexeymin, himcesjf, lesliezhai, ali-mohamed, hardening, romangg, jensreuterberg, abetts, sebas, apol, mart<br /></div>