metabrush/app/Main.hs

73 lines
1.6 KiB
Haskell
Raw Permalink Normal View History

2021-04-21 15:08:33 +00:00
{-# LANGUAGE OverloadedStrings #-}
2020-08-05 20:23:16 +00:00
2020-08-04 06:15:06 +00:00
module Main
( main )
where
2020-08-05 20:23:16 +00:00
-- base
2020-08-06 03:06:18 +00:00
import Control.Monad
2024-09-08 15:04:41 +00:00
( void, when )
import Data.Maybe
( isNothing )
import System.Environment
( lookupEnv, setEnv )
2020-08-05 20:23:16 +00:00
import System.Exit
2021-04-21 15:08:33 +00:00
( ExitCode(..), exitSuccess, exitWith )
import GHC.Conc
2021-04-21 15:08:33 +00:00
( getNumProcessors, setNumCapabilities )
2020-08-05 20:23:16 +00:00
-- code-page
import System.IO.CodePage
( withCP65001 )
2021-04-21 15:08:33 +00:00
-- gi-gio
import qualified GI.Gio as GIO
2020-08-10 14:38:27 +00:00
2021-04-21 15:08:33 +00:00
-- gi-gobject
import qualified GI.GObject as GObject
2021-02-24 21:45:08 +00:00
2020-08-04 06:15:06 +00:00
-- gi-gtk
import qualified GI.Gtk as GTK
-- MetaBrush
2021-04-21 15:08:33 +00:00
import MetaBrush.Application
( runApplication )
2020-08-04 06:15:06 +00:00
--------------------------------------------------------------------------------
main :: IO ()
main = withCP65001 do
2020-08-04 06:15:06 +00:00
procs <- getNumProcessors
let
caps :: Int
caps
| procs >= 6
= procs - 2
| procs >= 2
= procs - 1
| otherwise
= procs
setNumCapabilities caps
2024-09-08 15:04:41 +00:00
-- Set GDK_SCALE = 2 by default,
-- unless GDK_SCALE is already set.
mbGdkScale <- lookupEnv "GDK_SCALE"
when (isNothing mbGdkScale) $
setEnv "GDK_SCALE" "2"
setEnv "GSK_RENDERER" "vulkan"
2020-08-10 14:38:27 +00:00
---------------------------------------------------------
2021-04-21 15:08:33 +00:00
-- Run GTK application
2020-08-04 06:15:06 +00:00
2021-04-21 15:08:33 +00:00
application <- GTK.applicationNew ( Just "com.calligraphy.MetaBrush" ) [ GIO.ApplicationFlagsNonUnique ]
GIO.applicationRegister application ( Nothing @GIO.Cancellable )
void $ GIO.onApplicationActivate application ( runApplication application )
exitCode <- GIO.applicationRun application Nothing
GObject.objectUnref application
2020-08-05 20:23:16 +00:00
2021-04-21 15:08:33 +00:00
case exitCode of
0 -> exitSuccess
_ -> exitWith ( ExitFailure $ fromIntegral exitCode )