From a5fc7c2dbe1db45869e820cd93e77c559a86fe51 Mon Sep 17 00:00:00 2001 From: nek0 Date: Wed, 30 Jan 2019 23:10:00 +0100 Subject: [PATCH] get multiple screens --- ibis.cabal | 1 + shell.nix | 6 ++++-- src/Main.hs | 27 +++++++++++++++++++-------- src/Types.hs | 6 ++++-- src/Util.hs | 9 ++++++--- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/ibis.cabal b/ibis.cabal index 547facb..529e891 100644 --- a/ibis.cabal +++ b/ibis.cabal @@ -26,5 +26,6 @@ executable ibis , poppler , sdl2 , linear + , text hs-source-dirs: src default-language: Haskell2010 diff --git a/shell.nix b/shell.nix index 7350768..2338bff 100644 --- a/shell.nix +++ b/shell.nix @@ -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; }; diff --git a/src/Main.hs b/src/Main.hs index 14e502c..3e0e7d7 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -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 diff --git a/src/Types.hs b/src/Types.hs index 67dc265..3ac586c 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -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) diff --git a/src/Util.hs b/src/Util.hs index f230669..7855f74 100644 --- a/src/Util.hs +++ b/src/Util.hs @@ -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) + }