mirror of
https://github.com/xmonad/xmonad.git
synced 2025-08-04 14:11:55 -07:00
Constrain layout messages to be members of a Message class
Using Typeables as the only constraint on layout messages is a bit scary, as a user can send arbitrary values to layoutMsg, whether they make sense or not: there's basically no type feedback on the values you supply to layoutMsg. Folloing Simon Marlow's dynamically extensible exceptions paper, we use an existential type, and a Message type class, to constrain valid arguments to layoutMsg to be valid members of Message. That is, a user writes some data type for messages their layout algorithm accepts: data MyLayoutEvent = Zoom | Explode | Flaming3DGlassEffect deriving (Typeable) and they then add this to the set of valid message types: instance Message MyLayoutEvent Done. We also reimplement the dynamic type check while we're here, to just directly use 'cast', rather than expose a raw fromDynamic/toDyn. With this, I'm much happier about out dynamically extensible layout event subsystem.
This commit is contained in:
@@ -154,8 +154,8 @@ keys = M.fromList $
|
||||
, ((modMask, xK_j ), raise GT)
|
||||
, ((modMask, xK_k ), raise LT)
|
||||
|
||||
, ((modMask, xK_h ), layoutMsg Shrink)
|
||||
, ((modMask, xK_l ), layoutMsg Expand)
|
||||
, ((modMask, xK_h ), sendMessage Shrink)
|
||||
, ((modMask, xK_l ), sendMessage Expand)
|
||||
|
||||
, ((modMask .|. shiftMask, xK_c ), kill)
|
||||
|
||||
|
Reference in New Issue
Block a user