get multiple screens

This commit is contained in:
nek0 2019-01-30 23:10:00 +01:00
parent a36ddd0cc5
commit a5fc7c2dbe
5 changed files with 34 additions and 15 deletions

View file

@ -26,5 +26,6 @@ executable ibis
, poppler , poppler
, sdl2 , sdl2
, linear , linear
, text
hs-source-dirs: src hs-source-dirs: src
default-language: Haskell2010 default-language: Haskell2010

View file

@ -26,7 +26,9 @@ let
inherit (nixpkgs) pkgs; inherit (nixpkgs) pkgs;
f = { mkDerivation, base, linear, optparse-applicative, poppler, stdenv }: f = { mkDerivation, base, linear, optparse-applicative, poppler, stdenv,
text
}:
mkDerivation { mkDerivation {
pname = "ibis"; pname = "ibis";
version = "0.0.0.0"; version = "0.0.0.0";
@ -34,7 +36,7 @@ let
isLibrary = false; isLibrary = false;
isExecutable = true; isExecutable = true;
executableHaskellDepends = [ base linear sdl2 optparse-applicative executableHaskellDepends = [ base linear sdl2 optparse-applicative
poppler ]; poppler text ];
description = "A pdf presenter"; description = "A pdf presenter";
license = stdenv.lib.licenses.gpl3; license = stdenv.lib.licenses.gpl3;
}; };

View file

@ -1,6 +1,8 @@
module Main where module Main where
import qualified SDL import qualified SDL
import qualified SDL.Raw.Video as SDL (glSetAttribute)
import qualified SDL.Raw.Enum as SDL
import Linear import Linear
@ -8,10 +10,14 @@ import Options.Applicative
import Control.Monad import Control.Monad
import qualified Data.Text as T
-- internal imports -- internal imports
import Util import Util
import Types
main :: IO () main :: IO ()
main = do main = do
opts <- execParser $ info (options <**> helper) opts <- execParser $ info (options <**> helper)
@ -24,16 +30,21 @@ main = do
putStrLn ("Number of displays detected: " ++ show (length disps)) putStrLn ("Number of displays detected: " ++ show (length disps))
putStrLn ("Passed command line options: " ++ show opts) putStrLn ("Passed command line options: " ++ show opts)
-- set Render quality -- set Render quality
SDL.HintrenderScaleQuality SDL.$= SDL.ScaleLinear SDL.HintRenderScaleQuality SDL.$= SDL.ScaleLinear
-- check render quality -- check render quality
renderQuality <- SDL.get SDL.HintRenderScaleQuality renderQuality <- SDL.get SDL.HintRenderScaleQuality
when (renderQuality /= SDL.SclaeLinear) $ when (renderQuality /= SDL.ScaleLinear) $
putErrLn "Linear texture filtering not enabled!" putErrLn "Linear texture filtering not enabled!"
putStrLn "Creating window(s)" putStrLn "Creating window(s)"
wins = map uncurry SDL.CreateWindow $ if length disps > 1 wins <- zip ([0 .. ] :: [Word]) <$> mapM (uncurry SDL.createWindow) (
then zip zip
[ "Ibis - " ++ optFile options [ "Ibis - " <> optFile opts
, "Ibis - " ++ optFile options ++ " - Notes" , "Ibis - " <> optFile opts <> " - Notes"
] ]
( map makeWindowConfig disps (map makeWindowConfig disps)
) )
when (optFullscreen opts) $
mapM_ (flip SDL.setWindowMode SDL.FullscreenDesktop . snd) wins
void $ SDL.glSetAttribute SDL.SDL_GL_SHARE_WITH_CURRENT_CONTEXT 1
contexts <- zip (map fst wins) <$> mapM (SDL.glCreateContext . snd) wins
mapM_ (SDL.showWindow . snd) wins

View file

@ -1,8 +1,10 @@
module Types where module Types where
import qualified Data.Text as T
data Options = Options data Options = Options
{ optFullScreen :: Bool { optFullscreen :: Bool
, optFlipScreens :: Bool , optFlipScreens :: Bool
, optFile :: String , optFile :: T.Text
} }
deriving (Show) deriving (Show)

View file

@ -18,7 +18,7 @@ glWindowConfig = SDL.defaultWindow
} }
putErrLn :: String -> IO () putErrLn :: String -> IO ()
putErrLn s = hputStrLn stderr s putErrLn s = hPutStrLn stderr s
options :: Parser Options options :: Parser Options
options = Options options = Options
@ -39,5 +39,8 @@ options = Options
<> metavar "FILE" <> metavar "FILE"
) )
-- makeWindowConfig :: SDL.Display -> SDL.WindowConfig makeWindowConfig :: SDL.Display -> SDL.WindowConfig
-- makeWindowConfig d = makeWindowConfig d =
glWindowConfig
{ SDL.windowPosition = SDL.Absolute (SDL.displayBoundsPosition d)
}