From 5b398dea2394ead35fd838c8f9b957bac44f6d2c Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 4 Feb 2019 20:33:45 +0100 Subject: [PATCH] change window title on function flip --- src/Events.hs | 22 ++++++++++++++++------ src/Main.hs | 1 + src/Types.hs | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Events.hs b/src/Events.hs index 66e74f8..fc86bf1 100644 --- a/src/Events.hs +++ b/src/Events.hs @@ -2,6 +2,8 @@ module Events where import qualified SDL +import qualified Data.Text as T + import Linear import Control.Concurrent.MVar @@ -31,12 +33,20 @@ handlePayload run state (SDL.KeyboardEvent (SDL.KeyboardEventData _ SDL.Pressed return () | SDL.keysymKeycode sym == SDL.KeycodeF12 || SDL.keysymKeycode sym == SDL.KeycodeF = modifyMVar_ state $ \st -> do - return st - { stPresentationWindow = - if length (stWindows st) > 1 && stPresentationWindow st == 0 - then 1 - else 0 - } + let st2 = st + { stPresentationWindow = + if length (stWindows st) > 1 && stPresentationWindow st == 0 + then 1 + else 0 + } + mapM_ (\(ident, win) -> do + let title = "Ibis - " `T.append` stFilename st2 + if ident == stPresentationWindow st2 + then SDL.windowTitle win SDL.$= title + else SDL.windowTitle win SDL.$= title `T.append` " - Notes" + ) + (stWindows st2) + return st2 -- catch all other events handlePayload _ _ _ = return () diff --git a/src/Main.hs b/src/Main.hs index 3b9ace0..dc7b2ab 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -102,6 +102,7 @@ main = do state <- newMVar ( State 1 + (optFile opts) (last $ map fst wins) time wins diff --git a/src/Types.hs b/src/Types.hs index b4eb5e0..ced0299 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -20,6 +20,7 @@ data Options = Options data State = State { stCurrentPage :: Word + , stFilename :: T.Text , stPresentationWindow :: Word , stStartTime :: UTCTime , stWindows :: [(Word, SDL.Window)]