On 20.01.2014 22:32, Fabienne Ducroquet wrote: > Le lundi 20 janvier 2014, Uli Schlachter a écrit : >> Hi, >> >> Ah, ok. So the "k < n" was replaced with "k ~= n" which should do the >> same thing. > > I’m not sure why I changed that but it should do the same thing. > >> Also, this now also changes wa.width or wa.height in cases where it >> previously wouldn't have... Why? > > That’s what I tried to explain in the commit message: with the previous > code, for instance for the third window the width was divided by two and > wa.height stayed the same, but it should not: if the total height > available is 1001 pixels, the height of the second window should be 500 > pixels, and 501 for the third (or the reverse). It’s not possible to > find the height of the third window from the height of the second window > because if the height of the second window is 500 pixels, the total > height could be either 1000 or 1001 pixels. That’s why I store the size > of the previous window (and I initialized old_height at 2 * wa.height so > that the case k == 1 would not be different from the others). > >> >>> if k % 4 == 0 and _spiral then >>> wa.x = wa.x - wa.width >>> - elseif k % 2 == 0 or >>> - (k % 4 == 3 and k < n and _spiral) then >>> - wa.x = wa.x + wa.width >>> + elseif k % 2 == 0 then >>> + wa.x = wa.x + old_width >>> + elseif k % 4 == 3 and k < n and _spiral then >>> + wa.x = wa.x + math.ceil(old_width / 2) >>> end >> >> The last case of the old code needs to be split into two... >> Before we had wa.width, now we have old_width or ceil(old_width / 2). That's >> definitely not the same value as before, so this must be changing something >> else. >> >> Is this fixup for the previous hunk's "this now also changes [..] in cases >> where >> it previously wouldn't have"? If yes, then this makes this code definitely >> harder to understand and I have no clue why this is actually correct. >> >> Since I don't understand what you are doing, I cannot really give any good >> suggestions. Perhaps it would help to add some comments that explains some of >> the cases (e.g. k%2==0 => we are splitting the available space horizontally) >> and >> then also explains why these specific fixups are needed? > > You need to draw pictures of the layouts with 2 to at least 5 or > 6 windows to understand what’s happening, I’m not sure comments would > help: I can repeat what I’m doing but to understand why I’m doing it you > have to look at the pictures (this was already true before). > > For the dwindle layout it’s rather simple: > – If k is odd wa.x does not change. > – If k is even wa.x has to be augmented by the width of the previous > window, so old_width. With the old code old_width and wa.width would > have been equal. > > For the spiral layout: > – If k % 4 == 1 wa.x does not change. > – If k % 4 == 3 and it’s not the last window, wa.x has to be augmented > by the width of the following window. The previous code used wa.width > because it considered that the third and fourth windows had the same > width for instance. At that point in the code we have > wa.width == math.floor(old_width / 2), the width of the following window > will be the remaining width i.e. math.ceil(old_width / 2). > – If k % 4 == 0 wa.x has to be diminished by the width of the current > window. > – If k % 4 == 2 wa.x has to be augmented by the width of the previous > window, same thing as for k even in the dwindle layout. > > Note that the order of the conditions matters: k % 2 == 0 is equivalent > to (k % 2 == 0 and not _spiral) or (k % 4 == 2 and _spiral), because the > case k % 4 == 0 and _spiral is already treated. > > For wa.y the reasoning is similar.
Sold! commit 94a8c725968535fd74fe399846f193ecc6ce4c29 -- Bruce Schneier can read and understand Perl programs. -- To unsubscribe, send mail to [email protected].
