mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-14 11:45:54 -07:00
Decoration.hs: added automatic font managment
newDecoration now takes also a fontname to set fonts in decorations that use them. If an empty string is send the the default Xorg fonts will be loaded.
This commit is contained in:
@@ -33,9 +33,9 @@ import Operations ( UnDoLayout(UnDoLayout) )
|
|||||||
-- You can use this module for writing other extensions.
|
-- You can use this module for writing other extensions.
|
||||||
-- See, for instance, "XMonadContrib.Tabbed"
|
-- See, for instance, "XMonadContrib.Tabbed"
|
||||||
|
|
||||||
newDecoration :: Window -> Rectangle -> Int -> Pixel -> Pixel
|
newDecoration :: Window -> Rectangle -> Int -> Pixel -> Pixel -> String
|
||||||
-> (Display -> Window -> GC -> X ()) -> X () -> X Window
|
-> (Display -> Window -> GC -> FontStruct -> X ()) -> X () -> X Window
|
||||||
newDecoration decfor (Rectangle x y w h) th fg bg draw click = do
|
newDecoration decfor (Rectangle x y w h) th fg bg fn draw click = do
|
||||||
d <- asks display
|
d <- asks display
|
||||||
rt <- asks theRoot
|
rt <- asks theRoot
|
||||||
win <- io $ createSimpleWindow d rt x y w h (fromIntegral th) fg bg
|
win <- io $ createSimpleWindow d rt x y w h (fromIntegral th) fg bg
|
||||||
@@ -52,8 +52,8 @@ newDecoration decfor (Rectangle x y w h) th fg bg draw click = do
|
|||||||
handle_event (ButtonEvent {ev_window = thisw,ev_event_type = t})
|
handle_event (ButtonEvent {ev_window = thisw,ev_event_type = t})
|
||||||
| t == buttonPress && thisw == win = click
|
| t == buttonPress && thisw == win = click
|
||||||
handle_event (AnyEvent {ev_window = thisw, ev_event_type = t})
|
handle_event (AnyEvent {ev_window = thisw, ev_event_type = t})
|
||||||
| thisw == win && t == expose = withGC win draw
|
| thisw == win && t == expose = withGC win fn draw
|
||||||
| thisw == decfor && t == propertyNotify = withGC win draw
|
| thisw == decfor && t == propertyNotify = withGC win fn draw
|
||||||
handle_event _ = return ()
|
handle_event _ = return ()
|
||||||
|
|
||||||
addLayoutMessageHook hook
|
addLayoutMessageHook hook
|
||||||
@@ -61,7 +61,13 @@ newDecoration decfor (Rectangle x y w h) th fg bg draw click = do
|
|||||||
return win
|
return win
|
||||||
|
|
||||||
-- FIXME: withGC should use bracket (but can't, unless draw is an IO thing)
|
-- FIXME: withGC should use bracket (but can't, unless draw is an IO thing)
|
||||||
withGC :: Drawable -> (Display -> Drawable -> GC -> X ()) -> X ()
|
withGC :: Drawable -> String -> (Display -> Drawable -> GC -> FontStruct -> X ()) -> X ()
|
||||||
withGC w f = withDisplay $ \d -> do gc <- io $ createGC d w
|
withGC w fn f = withDisplay $ \d -> do gc <- io $ createGC d w
|
||||||
f d w gc
|
let fontname = if fn == ""
|
||||||
io $ freeGC d gc
|
then "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
|
||||||
|
else fn
|
||||||
|
font <- io $ loadQueryFont d fontname
|
||||||
|
io $ setFont d gc (fontFromFontStruct font)
|
||||||
|
f d w gc font
|
||||||
|
io $ freeGC d gc
|
||||||
|
io $ freeFont d font
|
||||||
|
Reference in New Issue
Block a user