2011-08-21 08:40:08 +02:00
|
|
|
{-# LANGUAGE GeneralizedNewtypeDeriving, ExistentialQuantification #-}
|
2011-07-12 02:56:30 +02:00
|
|
|
|
2011-07-12 16:47:24 +02:00
|
|
|
module Phi.X11 ( XConfig(..)
|
|
|
|
, defaultXConfig
|
2011-07-14 20:21:30 +02:00
|
|
|
, runPhi
|
2011-07-12 02:56:30 +02:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Graphics.X11.Xlib
|
|
|
|
import Graphics.X11.Xlib.Extras
|
|
|
|
import Graphics.X11.Xinerama
|
|
|
|
|
2011-07-13 02:13:01 +02:00
|
|
|
import Graphics.Rendering.Cairo
|
|
|
|
|
2011-07-12 02:56:30 +02:00
|
|
|
import Control.Monad
|
|
|
|
import Data.Maybe
|
|
|
|
import Data.Bits
|
2011-07-13 20:13:04 +02:00
|
|
|
import Data.Char
|
2011-07-12 02:56:30 +02:00
|
|
|
|
2011-07-14 07:34:43 +02:00
|
|
|
import Control.Concurrent
|
|
|
|
import Control.Concurrent.MVar
|
2011-08-21 21:39:26 +02:00
|
|
|
import Control.Monad.State.Strict
|
2011-07-12 16:47:24 +02:00
|
|
|
import Control.Monad.Reader
|
2011-07-12 02:56:30 +02:00
|
|
|
import Control.Monad.Trans
|
|
|
|
|
2011-07-19 12:25:08 +02:00
|
|
|
import System.Exit
|
|
|
|
import System.Posix.Signals
|
2011-07-14 07:34:43 +02:00
|
|
|
import System.Posix.Types
|
|
|
|
|
2011-07-14 06:16:04 +02:00
|
|
|
import Phi.Phi
|
2011-07-14 00:09:20 +02:00
|
|
|
import qualified Phi.Types as Phi
|
2011-07-12 14:41:25 +02:00
|
|
|
import qualified Phi.Panel as Panel
|
2011-07-14 00:09:20 +02:00
|
|
|
import qualified Phi.Widget as Widget
|
2011-08-21 08:47:32 +02:00
|
|
|
import Phi.Widget hiding (Display, handleMessage)
|
2011-07-12 19:09:05 +02:00
|
|
|
import Phi.X11.Atoms
|
2011-07-13 02:13:01 +02:00
|
|
|
import qualified Phi.Bindings.Util as Util
|
2011-07-12 02:56:30 +02:00
|
|
|
|
2011-07-15 09:17:57 +02:00
|
|
|
|
2011-07-14 20:21:30 +02:00
|
|
|
data XConfig = XConfig { phiXScreenInfo :: !(Display -> IO [Rectangle])
|
2011-07-12 16:47:24 +02:00
|
|
|
}
|
2011-07-12 02:56:30 +02:00
|
|
|
|
2011-08-21 19:34:16 +02:00
|
|
|
data PhiState w s c = (Widget.Widget w s c) => PhiState { phiRootImage :: !Surface
|
|
|
|
, phiPanels :: ![PanelState w s c]
|
|
|
|
, phiRepaint :: !Bool
|
|
|
|
, phiShutdown :: !Bool
|
|
|
|
, phiShutdownHold :: !Int
|
2011-08-29 15:10:55 +02:00
|
|
|
, phiWidgetState :: !s
|
2011-08-21 08:47:32 +02:00
|
|
|
}
|
2011-08-21 08:40:08 +02:00
|
|
|
|
2011-08-21 19:34:16 +02:00
|
|
|
data PanelState w s c = (Widget.Widget w s c) => PanelState { panelWindow :: !Window
|
|
|
|
, panelPixmap :: !Pixmap
|
|
|
|
, panelArea :: !Rectangle
|
|
|
|
, panelScreenArea :: !Rectangle
|
2011-08-21 21:39:26 +02:00
|
|
|
, panelWidgetCache :: !c
|
2011-08-21 19:34:16 +02:00
|
|
|
}
|
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
data PhiConfig w s c = PhiConfig { phiPhi :: !Phi
|
|
|
|
, phiPanelConfig :: !Panel.PanelConfig
|
|
|
|
, phiXConfig :: !XConfig
|
|
|
|
, phiAtoms :: !Atoms
|
|
|
|
, phiWidget :: !w
|
|
|
|
}
|
2011-07-12 16:47:24 +02:00
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
newtype PhiReader w s c a = PhiReader (ReaderT (PhiConfig w s c) IO a)
|
|
|
|
deriving (Monad, MonadReader (PhiConfig w s c), MonadIO)
|
2011-07-12 16:47:24 +02:00
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
runPhiReader :: PhiConfig w s c -> PhiReader w s c a -> IO a
|
2011-07-12 16:47:24 +02:00
|
|
|
runPhiReader config (PhiReader a) = runReaderT a config
|
2011-07-12 02:56:30 +02:00
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
newtype PhiX w s c a = PhiX (StateT (PhiState w s c) (PhiReader w s c) a)
|
|
|
|
deriving (Monad, MonadState (PhiState w s c), MonadReader (PhiConfig w s c), MonadIO)
|
2011-07-12 02:56:30 +02:00
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
runPhiX :: PhiConfig w s c -> PhiState w s c -> PhiX w s c a -> IO (a, PhiState w s c)
|
2011-07-14 06:16:04 +02:00
|
|
|
runPhiX config st (PhiX a) = runPhiReader config $ runStateT a st
|
2011-07-12 02:56:30 +02:00
|
|
|
|
2011-07-12 16:47:24 +02:00
|
|
|
defaultXConfig = XConfig { phiXScreenInfo = getScreenInfo
|
|
|
|
}
|
|
|
|
|
2011-08-21 19:34:16 +02:00
|
|
|
runPhi :: (Widget.Widget w s c) => XConfig -> Panel.PanelConfig -> w -> IO ()
|
2011-08-21 08:40:08 +02:00
|
|
|
runPhi xconfig config widget = do
|
2011-07-15 23:54:05 +02:00
|
|
|
xSetErrorHandler
|
|
|
|
|
2011-07-14 20:21:30 +02:00
|
|
|
phi <- initPhi
|
2011-07-19 12:25:08 +02:00
|
|
|
|
|
|
|
installHandler sigTERM (termHandler phi) Nothing
|
|
|
|
installHandler sigINT (termHandler phi) Nothing
|
|
|
|
installHandler sigQUIT (termHandler phi) Nothing
|
|
|
|
|
2011-07-12 02:56:30 +02:00
|
|
|
disp <- openDisplay []
|
2011-07-15 02:51:50 +02:00
|
|
|
|
2011-07-12 19:09:05 +02:00
|
|
|
atoms <- initAtoms disp
|
2011-07-12 02:56:30 +02:00
|
|
|
selectInput disp (defaultRootWindow disp) $ propertyChangeMask.|.structureNotifyMask
|
|
|
|
|
2011-07-14 22:50:03 +02:00
|
|
|
bg <- createImageSurface FormatRGB24 1 1
|
2011-08-29 15:10:55 +02:00
|
|
|
|
|
|
|
dispmvar <- newMVar disp
|
|
|
|
screens <- liftIO $ phiXScreenInfo xconfig disp
|
|
|
|
panelWindows <- mapM (createPanelWindow disp config) screens
|
|
|
|
let dispvar = Widget.Display dispmvar atoms
|
|
|
|
widget' = widget <~> separator 0 (if weight widget > 0 then 0 else 1)
|
|
|
|
screenPanels = zip screens panelWindows
|
|
|
|
|
|
|
|
initialState <- Widget.initWidget widget' phi dispvar screenPanels
|
|
|
|
|
|
|
|
runPhiX
|
|
|
|
PhiConfig { phiPhi = phi
|
|
|
|
, phiXConfig = xconfig
|
|
|
|
, phiPanelConfig = config
|
|
|
|
, phiAtoms = atoms
|
|
|
|
, phiWidget = widget'
|
|
|
|
}
|
|
|
|
PhiState { phiRootImage = bg
|
|
|
|
, phiPanels = []
|
|
|
|
, phiRepaint = True
|
|
|
|
, phiShutdown = False
|
|
|
|
, phiShutdownHold = 0
|
|
|
|
, phiWidgetState = initialState
|
|
|
|
} $ do
|
2011-07-14 22:50:03 +02:00
|
|
|
updateRootImage disp
|
2011-07-12 02:56:30 +02:00
|
|
|
|
2011-07-15 09:17:57 +02:00
|
|
|
Widget.withDisplay dispvar $ \disp -> do
|
2011-08-29 15:10:55 +02:00
|
|
|
panels <- mapM (\(screen, window) -> createPanel disp window screen) screenPanels
|
2011-07-14 22:50:03 +02:00
|
|
|
|
|
|
|
forM_ panels $ \panel -> do
|
|
|
|
setPanelProperties disp panel
|
|
|
|
liftIO $ mapWindow disp (panelWindow panel)
|
|
|
|
|
|
|
|
modify $ \state -> state { phiPanels = panels }
|
|
|
|
|
2011-07-14 07:34:43 +02:00
|
|
|
liftIO $ forkIO $ receiveEvents phi dispvar
|
|
|
|
|
2011-07-14 20:21:30 +02:00
|
|
|
forever $ do
|
2011-07-16 13:21:24 +02:00
|
|
|
available <- messageAvailable phi
|
|
|
|
unless available $ do
|
|
|
|
repaint <- gets phiRepaint
|
|
|
|
when repaint $ do
|
2011-07-19 11:16:50 +02:00
|
|
|
updatePanels dispvar
|
2011-07-16 13:21:24 +02:00
|
|
|
modify $ \state -> state {phiRepaint = False}
|
|
|
|
|
2011-07-15 09:17:57 +02:00
|
|
|
message <- receiveMessage phi
|
2011-07-14 07:34:43 +02:00
|
|
|
handleMessage dispvar message
|
2011-07-19 12:25:08 +02:00
|
|
|
|
|
|
|
case (fromMessage message) of
|
|
|
|
Just Shutdown ->
|
|
|
|
modify $ \state -> state { phiShutdown = True }
|
|
|
|
Just HoldShutdown ->
|
|
|
|
modify $ \state -> state { phiShutdownHold = phiShutdownHold state + 1 }
|
|
|
|
Just ReleaseShutdown ->
|
|
|
|
modify $ \state -> state { phiShutdownHold = phiShutdownHold state - 1 }
|
|
|
|
_ ->
|
|
|
|
return ()
|
|
|
|
|
|
|
|
shutdown <- gets phiShutdown
|
|
|
|
shutdownHold <- gets phiShutdownHold
|
|
|
|
|
|
|
|
when (shutdown && (shutdownHold == 0)) $
|
|
|
|
liftIO $ exitSuccess
|
|
|
|
|
2011-07-12 02:56:30 +02:00
|
|
|
return ()
|
|
|
|
|
|
|
|
|
2011-07-19 12:25:08 +02:00
|
|
|
termHandler :: Phi -> Handler
|
|
|
|
termHandler phi = Catch $ sendMessage phi Shutdown
|
|
|
|
|
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
handleMessage :: (Widget w s c) => Widget.Display -> Message -> PhiX w s c ()
|
2011-07-14 20:21:30 +02:00
|
|
|
handleMessage dispvar m = do
|
2011-08-29 15:10:55 +02:00
|
|
|
w <- asks phiWidget
|
|
|
|
modify $ \state -> state {phiWidgetState = Widget.handleMessage w (phiWidgetState state) m}
|
2011-07-14 20:21:30 +02:00
|
|
|
|
|
|
|
case (fromMessage m) of
|
2011-07-16 13:21:24 +02:00
|
|
|
Just Repaint ->
|
|
|
|
modify $ \state -> state {phiRepaint = True}
|
2011-07-14 20:21:30 +02:00
|
|
|
_ ->
|
|
|
|
case (fromMessage m) of
|
2011-08-29 16:51:02 +02:00
|
|
|
Just event ->
|
|
|
|
Widget.withDisplay dispvar $ flip handleEvent event
|
2011-07-14 20:21:30 +02:00
|
|
|
_ ->
|
|
|
|
return ()
|
2011-07-14 07:34:43 +02:00
|
|
|
|
2011-08-29 16:51:02 +02:00
|
|
|
handleEvent :: (Widget w s c) => Display -> Event -> PhiX w s c ()
|
|
|
|
handleEvent disp PropertyEvent { ev_atom = atom } = do
|
|
|
|
phi <- asks phiPhi
|
|
|
|
atoms <- asks phiAtoms
|
|
|
|
panels <- gets phiPanels
|
|
|
|
|
|
|
|
when (atom == atom_XROOTPMAP_ID atoms || atom == atom_XROOTMAP_ID atoms) $ do
|
|
|
|
updateRootImage disp
|
|
|
|
sendMessage phi ResetBackground
|
|
|
|
sendMessage phi Repaint
|
|
|
|
|
|
|
|
handleEvent disp ConfigureEvent { ev_window = window } | window == defaultRootWindow disp = do
|
|
|
|
phi <- asks phiPhi
|
|
|
|
xconfig <- asks phiXConfig
|
|
|
|
config <- asks phiPanelConfig
|
|
|
|
panels <- gets phiPanels
|
|
|
|
let screens = map panelScreenArea panels
|
|
|
|
screens' <- liftIO $ phiXScreenInfo xconfig disp
|
|
|
|
|
|
|
|
when (screens /= screens') $ do
|
|
|
|
liftIO $ do
|
|
|
|
mapM (freePixmap disp . panelPixmap) panels
|
|
|
|
mapM_ (destroyWindow disp . panelWindow) $ drop (length screens') panels
|
|
|
|
|
|
|
|
let panelsScreens = zip screens' $ map Just panels ++ repeat Nothing
|
|
|
|
|
|
|
|
panels' <- forM panelsScreens $ \(screen, mpanel) ->
|
|
|
|
case mpanel of
|
|
|
|
Just panel -> do
|
|
|
|
let rect = panelBounds config screen
|
|
|
|
win = panelWindow panel
|
|
|
|
|
|
|
|
liftIO $ withRectangle rect $ moveResizeWindow disp win
|
|
|
|
|
|
|
|
panel' <- createPanel disp win screen
|
|
|
|
setPanelProperties disp panel'
|
|
|
|
|
|
|
|
return panel'
|
|
|
|
Nothing -> do
|
|
|
|
win <- liftIO $ createPanelWindow disp config screen
|
|
|
|
panel <- createPanel disp win screen
|
|
|
|
setPanelProperties disp panel
|
|
|
|
liftIO $ mapWindow disp $ panelWindow panel
|
|
|
|
return panel
|
|
|
|
|
|
|
|
modify $ \state -> state { phiPanels = panels' }
|
|
|
|
|
|
|
|
sendMessage phi $ UpdateScreens $ map (\panel -> (panelScreenArea panel, panelWindow panel)) panels'
|
|
|
|
sendMessage phi Repaint
|
|
|
|
|
|
|
|
handleEvent _ _ = return ()
|
|
|
|
|
|
|
|
|
2011-07-14 22:50:03 +02:00
|
|
|
receiveEvents :: Phi -> Widget.Display -> IO ()
|
2011-07-14 07:34:43 +02:00
|
|
|
receiveEvents phi dispvar = do
|
2011-07-14 22:50:03 +02:00
|
|
|
connection <- Widget.withDisplay dispvar $ return . Fd . connectionNumber
|
2011-07-14 07:34:43 +02:00
|
|
|
|
2011-07-14 23:47:38 +02:00
|
|
|
allocaXEvent $ \xevent -> forever $ do
|
2011-07-14 22:50:03 +02:00
|
|
|
handled <- Widget.withDisplay dispvar $ \disp -> do
|
2011-07-14 07:34:43 +02:00
|
|
|
pend <- pending disp
|
|
|
|
if pend /= 0 then
|
|
|
|
do
|
|
|
|
liftIO $ nextEvent disp xevent
|
2011-07-19 11:16:50 +02:00
|
|
|
event <- liftIO $ Util.getEvent disp xevent
|
2011-07-14 07:34:43 +02:00
|
|
|
sendMessage phi event
|
|
|
|
|
|
|
|
return True
|
|
|
|
else return False
|
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
--when (not handled) $ threadWaitRead connection
|
|
|
|
when (not handled) $ threadDelay 40000
|
2011-07-14 07:34:43 +02:00
|
|
|
|
2011-08-21 19:34:16 +02:00
|
|
|
updatePanels :: (Widget w s c) => Widget.Display -> PhiX w s c ()
|
2011-07-19 11:16:50 +02:00
|
|
|
updatePanels dispvar = do
|
2011-08-29 15:10:55 +02:00
|
|
|
w <- asks phiWidget
|
|
|
|
s <- gets phiWidgetState
|
2011-07-14 22:50:03 +02:00
|
|
|
rootImage <- gets phiRootImage
|
2011-07-12 02:56:30 +02:00
|
|
|
panels <- gets phiPanels
|
2011-07-13 02:13:01 +02:00
|
|
|
|
2011-07-14 00:09:20 +02:00
|
|
|
panels' <- forM panels $ \panel -> do
|
2011-07-19 11:16:50 +02:00
|
|
|
let pixmap = panelPixmap panel
|
2011-07-14 22:50:03 +02:00
|
|
|
area = panelArea panel
|
|
|
|
|
2011-08-21 21:39:26 +02:00
|
|
|
(panelSurfaces, cache') <- liftIO $ flip runStateT (panelWidgetCache panel) $
|
2011-08-29 15:10:55 +02:00
|
|
|
(withDimension area $ Widget.render w s 0 0) (panelScreenArea panel)
|
2011-07-19 11:16:50 +02:00
|
|
|
|
|
|
|
Widget.withDisplay dispvar $ \disp -> do
|
|
|
|
let screen = defaultScreen disp
|
|
|
|
visual = defaultVisual disp screen
|
|
|
|
|
2011-07-22 22:36:43 +02:00
|
|
|
xbuffer <- liftIO $ withDimension area $ Util.createXlibSurface disp pixmap visual
|
2011-07-14 00:09:20 +02:00
|
|
|
|
2011-07-22 22:36:43 +02:00
|
|
|
liftIO $ (withDimension area $ withSimilarSurface xbuffer ContentColor) $ \buffer -> do
|
|
|
|
renderWith buffer $ do
|
2011-08-21 19:34:16 +02:00
|
|
|
save
|
|
|
|
translate (-(fromIntegral $ rect_x area)) (-(fromIntegral $ rect_y area))
|
2011-08-29 09:32:31 +02:00
|
|
|
withPatternForSurface rootImage $ \pattern -> do
|
|
|
|
patternSetExtend pattern ExtendRepeat
|
|
|
|
setSource pattern
|
2011-08-21 19:34:16 +02:00
|
|
|
paint
|
|
|
|
restore
|
|
|
|
|
|
|
|
forM_ panelSurfaces $ \(updated, SurfaceSlice x surface) -> do
|
2011-07-22 22:36:43 +02:00
|
|
|
save
|
2011-08-21 19:34:16 +02:00
|
|
|
translate (fromIntegral x) 0
|
|
|
|
withPatternForSurface surface setSource
|
2011-07-22 22:36:43 +02:00
|
|
|
paint
|
|
|
|
restore
|
2011-08-21 19:34:16 +02:00
|
|
|
|
2011-07-22 22:36:43 +02:00
|
|
|
renderWith xbuffer $ do
|
2011-08-21 19:34:16 +02:00
|
|
|
withPatternForSurface buffer setSource
|
|
|
|
paint
|
2011-07-13 02:13:01 +02:00
|
|
|
|
2011-07-22 22:36:43 +02:00
|
|
|
surfaceFinish xbuffer
|
2011-07-19 11:16:50 +02:00
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
-- update window
|
2011-07-19 11:16:50 +02:00
|
|
|
liftIO $ do
|
2011-08-21 19:34:16 +02:00
|
|
|
(withDimension area $ clearArea disp (panelWindow panel) 0 0) True
|
2011-07-19 11:16:50 +02:00
|
|
|
sync disp False
|
2011-07-14 22:50:03 +02:00
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
return $ panel { panelWidgetCache = cache' }
|
2011-07-19 11:16:50 +02:00
|
|
|
|
2011-07-14 00:09:20 +02:00
|
|
|
modify $ \state -> state { phiPanels = panels' }
|
2011-07-12 02:56:30 +02:00
|
|
|
|
|
|
|
|
2011-08-21 19:34:16 +02:00
|
|
|
updateRootImage :: Display -> PhiX w s c ()
|
2011-07-14 22:50:03 +02:00
|
|
|
updateRootImage disp = do
|
2011-07-12 19:09:05 +02:00
|
|
|
atoms <- asks phiAtoms
|
2011-07-14 22:50:03 +02:00
|
|
|
|
2011-07-12 02:56:30 +02:00
|
|
|
let screen = defaultScreen disp
|
2011-07-14 22:50:03 +02:00
|
|
|
visual = defaultVisual disp screen
|
2011-07-12 02:56:30 +02:00
|
|
|
rootwin = defaultRootWindow disp
|
2011-07-15 09:17:57 +02:00
|
|
|
pixmap <- liftM (fromIntegral . fromMaybe 0 . listToMaybe . join . catMaybes) $ forM [atom_XROOTPMAP_ID atoms, atom_XROOTMAP_ID atoms] $
|
|
|
|
\atom -> liftIO $ getWindowProperty32 disp atom rootwin
|
2011-07-22 11:42:22 +02:00
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
(pixmapWidth, pixmapHeight) <- case pixmap of
|
|
|
|
0 -> return (1, 1)
|
|
|
|
_ -> do
|
|
|
|
(_, _, _, pixmapWidth, pixmapHeight, _, _) <- liftIO $ getGeometry disp pixmap
|
|
|
|
return (pixmapWidth, pixmapHeight)
|
2011-07-14 22:50:03 +02:00
|
|
|
|
|
|
|
-- update surface size
|
|
|
|
oldBg <- gets phiRootImage
|
|
|
|
imageWidth <- liftM fromIntegral $ imageSurfaceGetWidth oldBg
|
|
|
|
imageHeight <- liftM fromIntegral $ imageSurfaceGetHeight oldBg
|
2011-08-29 09:32:31 +02:00
|
|
|
when (imageWidth /= pixmapWidth || imageHeight /= pixmapHeight) $ do
|
2011-07-14 22:50:03 +02:00
|
|
|
surfaceFinish oldBg
|
2011-08-29 09:32:31 +02:00
|
|
|
newBg <- liftIO $ createImageSurface FormatRGB24 (fromIntegral pixmapWidth) (fromIntegral pixmapHeight)
|
2011-07-14 22:50:03 +02:00
|
|
|
modify $ \state -> state { phiRootImage = newBg }
|
|
|
|
|
|
|
|
bg <- gets phiRootImage
|
|
|
|
|
2011-07-22 22:36:43 +02:00
|
|
|
case pixmap of
|
|
|
|
0 -> do
|
|
|
|
renderWith bg $ do
|
|
|
|
setSourceRGB 0 0 0
|
|
|
|
paint
|
|
|
|
_ -> do
|
2011-08-29 09:32:31 +02:00
|
|
|
rootSurface <- liftIO $ Util.createXlibSurface disp pixmap visual (fromIntegral pixmapWidth) (fromIntegral pixmapHeight)
|
2011-07-22 22:36:43 +02:00
|
|
|
|
|
|
|
renderWith bg $ withPatternForSurface rootSurface $ \pattern -> do
|
|
|
|
setSource pattern
|
|
|
|
paint
|
|
|
|
|
|
|
|
surfaceFinish rootSurface
|
2011-07-12 02:56:30 +02:00
|
|
|
|
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
createPanel :: (Widget w s c) => Display -> Window -> Rectangle -> PhiX w s c (PanelState w s c)
|
|
|
|
createPanel disp win screenRect = do
|
2011-07-12 16:47:24 +02:00
|
|
|
config <- asks phiPanelConfig
|
2011-08-29 15:10:55 +02:00
|
|
|
w <- asks phiWidget
|
2011-07-13 02:13:01 +02:00
|
|
|
let rect = panelBounds config screenRect
|
2011-08-29 15:10:55 +02:00
|
|
|
screen = defaultScreen disp
|
2011-07-19 11:16:50 +02:00
|
|
|
depth = defaultDepth disp screen
|
|
|
|
|
|
|
|
pixmap <- liftIO $ (withDimension rect $ createPixmap disp win) depth
|
2011-07-19 14:50:04 +02:00
|
|
|
liftIO $ setWindowBackgroundPixmap disp win pixmap
|
2011-07-13 02:13:01 +02:00
|
|
|
|
2011-07-14 20:21:30 +02:00
|
|
|
return PanelState { panelWindow = win
|
2011-07-19 11:16:50 +02:00
|
|
|
, panelPixmap = pixmap
|
2011-07-14 20:21:30 +02:00
|
|
|
, panelArea = rect
|
|
|
|
, panelScreenArea = screenRect
|
2011-08-21 21:39:26 +02:00
|
|
|
, panelWidgetCache = initCache w
|
2011-07-14 20:21:30 +02:00
|
|
|
}
|
2011-07-12 02:56:30 +02:00
|
|
|
|
2011-08-29 15:10:55 +02:00
|
|
|
createPanelWindow :: Display -> Panel.PanelConfig -> Rectangle -> IO Window
|
|
|
|
createPanelWindow disp config screenRect = do
|
2011-07-19 11:16:50 +02:00
|
|
|
let rect = panelBounds config screenRect
|
|
|
|
screen = defaultScreen disp
|
2011-07-12 02:56:30 +02:00
|
|
|
depth = defaultDepth disp screen
|
|
|
|
visual = defaultVisual disp screen
|
|
|
|
colormap = defaultColormap disp screen
|
|
|
|
rootwin = defaultRootWindow disp
|
|
|
|
mask = cWEventMask.|.cWColormap.|.cWBackPixel.|.cWBorderPixel
|
|
|
|
|
2011-08-29 16:51:02 +02:00
|
|
|
allocaSetWindowAttributes $ \attr -> do
|
2011-07-12 02:56:30 +02:00
|
|
|
set_colormap attr colormap
|
|
|
|
set_background_pixel attr 0
|
|
|
|
set_border_pixel attr 0
|
|
|
|
set_event_mask attr exposureMask
|
|
|
|
withRectangle rect (createWindow disp rootwin) 0 depth inputOutput visual mask attr
|
|
|
|
|
|
|
|
|
2011-08-21 19:34:16 +02:00
|
|
|
setPanelProperties :: Display -> PanelState w s c -> PhiX w s c ()
|
2011-07-14 07:34:43 +02:00
|
|
|
setPanelProperties disp panel = do
|
2011-07-12 19:09:05 +02:00
|
|
|
atoms <- asks phiAtoms
|
2011-07-12 02:56:30 +02:00
|
|
|
liftIO $ do
|
|
|
|
storeName disp (panelWindow panel) "Phi"
|
2011-07-13 20:13:04 +02:00
|
|
|
changeProperty8 disp (panelWindow panel) (atom_NET_WM_NAME atoms) (atomUTF8_STRING atoms) propModeReplace $ map (fromIntegral . ord) "Phi"
|
|
|
|
|
2011-07-12 19:09:05 +02:00
|
|
|
changeProperty32 disp (panelWindow panel) (atom_NET_WM_WINDOW_TYPE atoms) aTOM propModeReplace [fromIntegral (atom_NET_WM_WINDOW_TYPE_DOCK atoms)]
|
|
|
|
changeProperty32 disp (panelWindow panel) (atom_NET_WM_DESKTOP atoms) cARDINAL propModeReplace [0xFFFFFFFF]
|
|
|
|
changeProperty32 disp (panelWindow panel) (atom_NET_WM_STATE atoms) aTOM propModeReplace [ fromIntegral (atom_NET_WM_STATE_SKIP_PAGER atoms)
|
|
|
|
, fromIntegral (atom_NET_WM_STATE_SKIP_TASKBAR atoms)
|
|
|
|
, fromIntegral (atom_NET_WM_STATE_STICKY atoms)
|
|
|
|
, fromIntegral (atom_NET_WM_STATE_BELOW atoms)
|
|
|
|
]
|
2011-07-12 02:56:30 +02:00
|
|
|
setWMHints disp (panelWindow panel) WMHints { wmh_flags = fromIntegral inputHintBit
|
|
|
|
, wmh_input = False
|
|
|
|
, wmh_initial_state = 0
|
|
|
|
, wmh_icon_pixmap = 0
|
|
|
|
, wmh_icon_window = 0
|
|
|
|
, wmh_icon_x = 0
|
|
|
|
, wmh_icon_y = 0
|
|
|
|
, wmh_icon_mask = 0
|
|
|
|
, wmh_window_group = 0
|
|
|
|
}
|
2011-07-12 19:09:05 +02:00
|
|
|
changeProperty32 disp (panelWindow panel) (atom_MOTIF_WM_HINTS atoms) (atom_MOTIF_WM_HINTS atoms) propModeReplace [ 2, 0, 0, 0, 0 ]
|
2011-07-13 02:13:01 +02:00
|
|
|
|
|
|
|
Util.setClassHint disp (panelWindow panel) ClassHint { resName = "phi", resClass = "Phi" }
|
|
|
|
|
2011-07-14 07:34:43 +02:00
|
|
|
setStruts disp panel
|
2011-07-12 02:56:30 +02:00
|
|
|
|
|
|
|
|
2011-08-21 19:34:16 +02:00
|
|
|
setStruts :: Display -> PanelState w s c -> PhiX w s c ()
|
2011-07-14 07:34:43 +02:00
|
|
|
setStruts disp panel = do
|
2011-07-12 19:09:05 +02:00
|
|
|
atoms <- asks phiAtoms
|
2011-07-12 16:47:24 +02:00
|
|
|
config <- asks phiPanelConfig
|
2011-07-12 02:56:30 +02:00
|
|
|
let rootwin = defaultRootWindow disp
|
2011-07-12 16:47:24 +02:00
|
|
|
position = Panel.panelPosition config
|
2011-07-12 02:56:30 +02:00
|
|
|
area = panelArea panel
|
|
|
|
(_, _, _, _, rootHeight, _, _) <- liftIO $ getGeometry disp rootwin
|
|
|
|
|
2011-07-12 14:41:25 +02:00
|
|
|
let struts = [makeStruts i | i <- [0..11]]
|
|
|
|
where
|
|
|
|
makeTopStruts 2 = (fromIntegral $ rect_y area) + (fromIntegral $ rect_height area)
|
|
|
|
makeTopStruts 8 = (fromIntegral $ rect_x area)
|
|
|
|
makeTopStruts 9 = (fromIntegral $ rect_x area) + (fromIntegral $ rect_width area) - 1
|
|
|
|
makeTopStruts _ = 0
|
|
|
|
|
|
|
|
makeBottomStruts 3 = (fromIntegral rootHeight) - (fromIntegral $ rect_y area)
|
|
|
|
makeBottomStruts 10 = (fromIntegral $ rect_x area)
|
|
|
|
makeBottomStruts 11 = (fromIntegral $ rect_x area) + (fromIntegral $ rect_width area) - 1
|
|
|
|
makeBottomStruts _ = 0
|
|
|
|
|
|
|
|
makeStruts = case position of
|
2011-07-14 00:09:20 +02:00
|
|
|
Phi.Top -> makeTopStruts
|
|
|
|
Phi.Bottom -> makeBottomStruts
|
2011-07-12 02:56:30 +02:00
|
|
|
|
|
|
|
liftIO $ do
|
2011-07-12 19:09:05 +02:00
|
|
|
changeProperty32 disp (panelWindow panel) (atom_NET_WM_STRUT atoms) cARDINAL propModeReplace $ take 4 struts
|
|
|
|
changeProperty32 disp (panelWindow panel) (atom_NET_WM_STRUT_PARTIAL atoms) cARDINAL propModeReplace struts
|
2011-07-12 02:56:30 +02:00
|
|
|
|
|
|
|
|
2011-07-12 16:47:24 +02:00
|
|
|
panelBounds :: Panel.PanelConfig -> Rectangle -> Rectangle
|
|
|
|
panelBounds config screenBounds = case Panel.panelPosition config of
|
2011-07-14 00:09:20 +02:00
|
|
|
Phi.Top -> screenBounds { rect_height = fromIntegral $ Panel.panelSize config }
|
|
|
|
Phi.Bottom -> screenBounds { rect_height = fromIntegral $ Panel.panelSize config,
|
2011-07-12 16:47:24 +02:00
|
|
|
rect_y = (rect_y screenBounds) + (fromIntegral $ rect_height screenBounds) - (fromIntegral $ Panel.panelSize config) }
|
2011-07-12 02:56:30 +02:00
|
|
|
|
2011-07-13 02:13:01 +02:00
|
|
|
withRectangle :: (Num x, Num y, Num w, Num h) => Rectangle -> (x -> y -> w -> h -> a) -> a
|
2011-07-12 02:56:30 +02:00
|
|
|
withRectangle r = withDimension r . withPosition r
|
|
|
|
|
2011-07-13 02:13:01 +02:00
|
|
|
withPosition :: (Num x, Num y) => Rectangle -> (x -> y -> a) -> a
|
|
|
|
withPosition r f = f (fromIntegral $ rect_x r) (fromIntegral $ rect_y r)
|
2011-07-12 02:56:30 +02:00
|
|
|
|
2011-07-13 02:13:01 +02:00
|
|
|
withDimension :: (Num w, Num h) => Rectangle -> (w -> h -> a) -> a
|
|
|
|
withDimension r f = f (fromIntegral $ rect_width r) (fromIntegral $ rect_height r)
|