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
, sdl2
, linear
, text
hs-source-dirs: src
default-language: Haskell2010

View file

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

View file

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

View file

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