[xmonad] Strange workspace switching bug in my config
Leo Alekseyev
dnquark at gmail.com
Tue May 15 16:54:38 CEST 2012
On Tue, May 15, 2012 at 10:49 AM, Leo Alekseyev <dnquark at gmail.com> wrote:
> On Tue, May 15, 2012 at 7:20 AM, Norbert Zeh <nzeh at cs.dal.ca> wrote:
>> wagnerdm at seas.upenn.edu [2012.05.14 2219 -0400]:
>>> Quoting Leo Alekseyev <dnquark at gmail.com>:
>>>
>>> >On Sun, May 13, 2012 at 8:45 AM, Norbert Zeh <nzeh at cs.dal.ca> wrote:
>>> >>>myWorkspaces = ["1:terminals", "2:emacs", "3:web", "4", "5", "6",
>>> >>>"7","8","9","0"] ++ map (\x -> show x ++ "SCR") ([1..9]++[0])
>>> >>>.....
>>> >>>
>>> >>>zeroSub 0 = 10
>>> >>>zeroSub x = x
>>> >>>
>>> >>>jumpToMain = gets windowset >>= \W.StackSet { W.current = W.Screen {
>>> >>>W.workspace = w } } -> withNthWorkspace W.greedyView (-1+(zeroSub $
>>> >>>read [head(W.tag w)]))
>>> >>>jumpToScratch = gets windowset >>= \W.StackSet { W.current = W.Screen
>>> >>>{ W.workspace = w } } -> withNthWorkspace W.greedyView (9+(zeroSub $
>>> >>>read [head(W.tag w)]))
>>> >>
>>> >>The math here looks all wrong, and I'm surprised that it worked
>>> >>at all before.
>>>
>>> The math looks fine to me, and in fact your suggestion:
>>>
>>> >>What you want, I think, is the following:
>>> >>
>>> >>jumpToMain = gets (W.tag . W.workspace . W.current . windowset)
>>> >> >>= W.greedyView . toMain
>>> >> where
>>> >> toMain ws = [head ws]
>>> >>
>>> >>jumpToScratch = gets (W.tag . W.workspace . W.current . windowset)
>>> >> >>= W.greedyView . toScratch
>>> >> where
>>> >> toScratch ws | length ws == 1 = ws ++ "SCR"
>>> >> | otherwise = ws
>>>
>>> is the one that looks dodgy to me. Notice that his main workspace
>>> names are things like "3:web", but the SCR-version is just "3SCR"!
>>> In fact, I would humbly suggest that this paragraph:
>>
>> Oops. I overlooked that the primary workspaces were not just numbered. My bad.
>> I still don't get the math in the original code snippet. zeroSub has an effect
>> only when its argument is 0. So, for any starting workspace except "0" or
>> "0SCR", say its number is x, the above code goes to workspace x-1 or x+9. It
>> should, however, go to workspace x-10 or x+10 and that conditionally on whether
>> the main/scratch workspace is already visible. What is it I don't understand
>> here?
>
> My original understanding was this: I have an array of workspaces like so:
> [1, 2, ...9, 0, 1SCR, 2SCR, ... 0SCR]
>
> When I want to go from e.g. 2 to 2SCR, I want element 11 in this
> 0-indexed array. So, I get the head of the tag, I assume /read/
> converts it to an integer, and I add 9 to it, and hope that
> withNthWorkspace on the 11th array element will do the right thing.
> By that logic, to go from 2SCR back to 2, I need to subtract 11 to get
> element 1 of the array. However, when I originally wrote that code,
> this didn't work right, and I put in random numbers until for some
> reason putting in 1 worked. (Yes, programming by coincidence and
> all.)
>
> Speaking of programming by coincidence, I changed the numbers to +10
> and -0, and things started working. Then I logged in and out, and now
> I'm back to off-by-one, but in a different direction, i.e. 2 takes me
> to 3SCR and going back takes me to 4, etc... I put in my old code,
> and now things work again, but if history is any indication, it will
> break some time later today or tomorrow.
>
> I'm clearly misunderstanding something about how workspace switching works...
What I said above about subtracting 11 is of course wrong: by my
logic, I read in the head of the tag "2SCR", i.e. "2", get an int,
subtract 1, and go to element 1 of the workspace array, which should
have workspace 1. So my math is consistent with my mental model of
how workspace switching works. (Why do I have to realize this 3
seconds after I hit send? :P)
More information about the xmonad
mailing list