Reputation: 31
In hooks, key binding and so on, one can compare a window property to a string, but I would also like to be able to compare window properties to lists.
My concrete use case, using XMonad.Actions.PerWindowKeys, is in simplified form that in addition to something like this, which works fine (open termite if focused window is xterm, otherwise kill focused window):
, ((modMask, xK_e), bindFirst [(className =? "xterm", spawn "termite") , (pure True, kill)])
I would like to be able to do something roughly like this (open termite if focused window is either st or xterm, otherwise kill focused window – which doesn't work:
, ((modMask, xK_e), bindFirst [(className =? ["st", "xterm"], spawn "termite") , (pure True, kill)])
The className check fails with:
Couldn't match type ‘[Char]’ with ‘Char’
Expected type: String
Actual type: [[Char]]
I initially thought this would be pretty easy to solve (and it probably is...), but being a Haskell noob, I've spent a few hours on it already without success.
=? seems to really expect a string only and I could not find a way to modify the arguments in a way that would make it accept them, even with extensive consultation of source from contrib. I was also not able to find any alternative function in contrib that to my understanding does what I want.
One idea I had was bringing in the elem function to check if any element of the array matches the class name, but that failed because elem returns "normal" bools, while =? appears to be working with specific Query Bools, and I could not figure out any way of bringing those together into one function.
Upvotes: 1
Views: 189
Reputation: 10695
Here's how you can do it:
, ((modMask, xK_e), bindFirst [(className =? "st" <||> className =? "xterm", spawn "termite") , (pure True, kill)])
To avoid some duplication you can define a custom operator that does the multiple comparisons:
(=??) :: Eq a => Query a -> [a] -> Query Bool
q =?? [] = pure False
q =?? (x:xs) = q =? x <||> (q =?? xs)
Then you can use that like so:
, ((modMask, xK_e), bindFirst [(className =?? ["st", "xterm"], spawn "termite") , (pure True, kill)])
Upvotes: 1