Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cdepillabout committed Oct 22, 2023
1 parent fc2ece1 commit 8cdff5d
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 27 deletions.
20 changes: 2 additions & 18 deletions src/Termonad/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ import Termonad.Lenses
, lensTerm
, lensWordCharExceptions, lensTMStateWindows, lensTMWindowNotebook
)
import Termonad.Preferences (saveToPreferencesFile)
import Termonad.Preferences (saveToPreferencesFile, showPreferencesDialog)
import Termonad.Term
( createTerm
, relabelTabs
Expand Down Expand Up @@ -186,7 +186,7 @@ import Termonad.Types
, tmStateApp
, tmStateWindows
, tmWindowAppWin
, tmWindowNotebook
, tmWindowNotebook, fontSizeFromFontDescription
)
import Termonad.XML (interfaceText, menuText, preferencesText)
import Termonad.Cli (parseCliArgs, applyCliArgs)
Expand Down Expand Up @@ -276,22 +276,6 @@ modifyFontSizeForAllTerms modFontSizeFunc mvarTMState tmWinId = do
lensTerm
foldMap (\vteTerm -> terminalSetFont vteTerm (Just fontDesc)) terms

fontSizeFromFontDescription :: FontDescription -> IO FontSize
fontSizeFromFontDescription fontDesc = do
currSize <- fontDescriptionGetSize fontDesc
currAbsolute <- fontDescriptionGetSizeIsAbsolute fontDesc
return $ if currAbsolute
then FontSizeUnits $ fromIntegral currSize / fromIntegral SCALE
else
let fontRatio :: Double = fromIntegral currSize / fromIntegral SCALE
in FontSizePoints $ round fontRatio

fontConfigFromFontDescription :: FontDescription -> IO (Maybe FontConfig)
fontConfigFromFontDescription fontDescription = do
fontSize <- fontSizeFromFontDescription fontDescription
maybeFontFamily <- fontDescriptionGetFamily fontDescription
return $ (`FontConfig` fontSize) <$> maybeFontFamily

compareScrolledWinAndTab :: ScrolledWindow -> TMNotebookTab -> Bool
compareScrolledWinAndTab scrollWin flTab =
let ScrolledWindow managedPtrFLTab = tmNotebookTabTermContainer flTab
Expand Down
193 changes: 185 additions & 8 deletions src/Termonad/Preferences.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,197 @@

module Termonad.Preferences
( module Termonad.Preferences.File
, showPreferencesDialog
) where

import Termonad.Prelude

import Termonad.Preferences.File (saveToPreferencesFile, tmConfigFromPreferencesFile)
import GI.Gtk (ComboBoxText(ComboBoxText), comboBoxSetActiveId, comboBoxGetActiveId, comboBoxTextAppend)
import Control.Lens ((^.), (^..), over, set, view, ix)

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-20.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-22.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-20.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-20.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-22.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-20.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-20.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-22.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-22.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-22.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-22.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant

Check warning on line 10 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-20.04

The import of ‘^.., ix’ from module ‘Control.Lens’ is redundant
import Data.FileEmbed (embedFile)

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-20.04

The import of ‘Data.FileEmbed’ is redundant

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-22.04

The import of ‘Data.FileEmbed’ is redundant

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-20.04

The import of ‘Data.FileEmbed’ is redundant

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-20.04

The import of ‘Data.FileEmbed’ is redundant

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-22.04

The import of ‘Data.FileEmbed’ is redundant

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-20.04

The import of ‘Data.FileEmbed’ is redundant

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-20.04

The import of ‘Data.FileEmbed’ is redundant

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-22.04

The import of ‘Data.FileEmbed’ is redundant

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-22.04

The import of ‘Data.FileEmbed’ is redundant

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-22.04

The import of ‘Data.FileEmbed’ is redundant

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-22.04

The import of ‘Data.FileEmbed’ is redundant

Check warning on line 11 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-20.04

The import of ‘Data.FileEmbed’ is redundant
import Data.FocusList (focusList, moveFromToFL, updateFocusFL)

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-20.04

The import of ‘Data.FocusList’ is redundant

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-22.04

The import of ‘Data.FocusList’ is redundant

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-20.04

The import of ‘Data.FocusList’ is redundant

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-20.04

The import of ‘Data.FocusList’ is redundant

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-22.04

The import of ‘Data.FocusList’ is redundant

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-20.04

The import of ‘Data.FocusList’ is redundant

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-20.04

The import of ‘Data.FocusList’ is redundant

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-22.04

The import of ‘Data.FocusList’ is redundant

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-22.04

The import of ‘Data.FocusList’ is redundant

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-22.04

The import of ‘Data.FocusList’ is redundant

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-22.04

The import of ‘Data.FocusList’ is redundant

Check warning on line 12 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-20.04

The import of ‘Data.FocusList’ is redundant
import qualified Data.List as List
import Termonad.Types (TMState, TMNotebookTab, TMWindowId, cursorBlinkMode, wordCharExceptions, scrollbackLen, boldIsBright, ConfigOptions (enableSixel, allowBold))
import Data.Sequence (findIndexR)

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-20.04

The import of ‘Data.Sequence’ is redundant

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-22.04

The import of ‘Data.Sequence’ is redundant

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-20.04

The import of ‘Data.Sequence’ is redundant

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-20.04

The import of ‘Data.Sequence’ is redundant

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-22.04

The import of ‘Data.Sequence’ is redundant

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-20.04

The import of ‘Data.Sequence’ is redundant

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-20.04

The import of ‘Data.Sequence’ is redundant

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-22.04

The import of ‘Data.Sequence’ is redundant

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-22.04

The import of ‘Data.Sequence’ is redundant

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-22.04

The import of ‘Data.Sequence’ is redundant

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-22.04

The import of ‘Data.Sequence’ is redundant

Check warning on line 14 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-20.04

The import of ‘Data.Sequence’ is redundant
import qualified Data.Text as Text
import Control.Lens ((^.))
import Termonad.Lenses (lensTMStateFontDesc, lensTMNotebookTabTerm, lensTerm, lensTMNotebookTabTermContainer, lensTMStateConfig, lensOptions, lensShowScrollbar)
import GI.Vte (terminalSetFont, terminalSetCursorBlinkMode, terminalSetWordCharExceptions, terminalSetScrollbackLines, terminalSetBoldIsBright, terminalSetAllowBold)
import Termonad.Gtk (terminalSetEnableSixelIfExists)
import Termonad.Term (showScrollbarToPolicy)
import Data.Text.Encoding (encodeUtf8)

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-20.04

The import of ‘Data.Text.Encoding’ is redundant

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-22.04

The import of ‘Data.Text.Encoding’ is redundant

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-20.04

The import of ‘Data.Text.Encoding’ is redundant

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-20.04

The import of ‘Data.Text.Encoding’ is redundant

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-22.04

The import of ‘Data.Text.Encoding’ is redundant

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-20.04

The import of ‘Data.Text.Encoding’ is redundant

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-20.04

The import of ‘Data.Text.Encoding’ is redundant

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-22.04

The import of ‘Data.Text.Encoding’ is redundant

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-22.04

The import of ‘Data.Text.Encoding’ is redundant

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-22.04

The import of ‘Data.Text.Encoding’ is redundant

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-22.04

The import of ‘Data.Text.Encoding’ is redundant

Check warning on line 16 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-20.04

The import of ‘Data.Text.Encoding’ is redundant
import GI.Gdk (castTo, managedForeignPtr, screenGetDefault)

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-20.04

The import of ‘GI.Gdk’ is redundant

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-22.04

The import of ‘GI.Gdk’ is redundant

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-20.04

The import of ‘GI.Gdk’ is redundant

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-20.04

The import of ‘GI.Gdk’ is redundant

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-22.04

The import of ‘GI.Gdk’ is redundant

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-20.04

The import of ‘GI.Gdk’ is redundant

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-20.04

The import of ‘GI.Gdk’ is redundant

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-22.04

The import of ‘GI.Gdk’ is redundant

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-22.04

The import of ‘GI.Gdk’ is redundant

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-22.04

The import of ‘GI.Gdk’ is redundant

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-22.04

The import of ‘GI.Gdk’ is redundant

Check warning on line 17 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-20.04

The import of ‘GI.Gdk’ is redundant
import GI.Gio

Check warning on line 18 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-22.04

The import of ‘GI.Gio’ is redundant

Check warning on line 18 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-22.04

The import of ‘GI.Gio’ is redundant

Check warning on line 18 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-22.04

The import of ‘GI.Gio’ is redundant

Check warning on line 18 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-22.04

The import of ‘GI.Gio’ is redundant

Check warning on line 18 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-22.04

The import of ‘GI.Gio’ is redundant

Check warning on line 18 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-22.04

The import of ‘GI.Gio’ is redundant
( ApplicationFlags(ApplicationFlagsFlagsNone)
, MenuModel(MenuModel)
, actionMapAddAction
, applicationQuit
, applicationRun
, onApplicationActivate
, onApplicationStartup
, onSimpleActionActivate
, simpleActionNew
)
import GI.Gtk

Check warning on line 29 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-22.04

The import of ‘Application, ApplicationWindow, ApplicationWindow,

Check warning on line 29 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack.yaml / ubuntu-22.04

The import of ‘Application, ApplicationWindow, ApplicationWindow,

Check warning on line 29 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-22.04

The import of ‘Application, ApplicationWindow, ApplicationWindow,

Check warning on line 29 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.7 / ubuntu-22.04

The import of ‘Application, ApplicationWindow, ApplicationWindow,

Check warning on line 29 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-nightly.yaml / ubuntu-22.04

The import of ‘Application, ApplicationWindow, ApplicationWindow,

Check warning on line 29 in src/Termonad/Preferences.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-22.04

The import of ‘Application, ApplicationWindow, ApplicationWindow,
( Application
, ApplicationWindow(ApplicationWindow)
, Box(Box)
, CheckButton(CheckButton)
, ComboBoxText(ComboBoxText)
, Dialog(Dialog)
, Entry(Entry)
, FontButton(FontButton)
, Label(Label)
, PolicyType(PolicyTypeAutomatic)
, PositionType(PositionTypeRight)
, ResponseType(ResponseTypeAccept, ResponseTypeNo, ResponseTypeYes)
, ScrolledWindow(ScrolledWindow)
, SpinButton(SpinButton)
, pattern STYLE_PROVIDER_PRIORITY_APPLICATION
, aboutDialogNew
, adjustmentNew
, applicationAddWindow
, applicationGetActiveWindow
, applicationSetAccelsForAction
, applicationSetMenubar
, applicationWindowSetShowMenubar
, boxPackStart
, builderNewFromString
, builderSetApplication
, comboBoxGetActiveId
, comboBoxSetActiveId
, comboBoxTextAppend
, containerAdd
, cssProviderLoadFromData
, cssProviderNew
, dialogAddButton
, dialogGetContentArea
, dialogNew
, dialogResponse
, dialogRun
, entryBufferGetText
, entryBufferSetText
, entryGetText
, entryNew
, fontChooserSetFontDesc
, fontChooserGetFontDesc
, getEntryBuffer
, gridAttachNextTo
, gridNew
, labelNew
, notebookGetNPages
, notebookNew
, notebookSetShowBorder
, onEntryActivate
, onNotebookPageRemoved
, onNotebookPageReordered
, onNotebookSwitchPage
, onWidgetDeleteEvent
, scrolledWindowSetPolicy
, setWidgetMargin
, spinButtonGetValueAsInt
, spinButtonSetAdjustment
, spinButtonSetValue
, styleContextAddProviderForScreen
, toggleButtonGetActive
, toggleButtonSetActive
, widgetDestroy
, widgetGrabFocus
, widgetSetCanFocus
, widgetSetVisible
, widgetShow
, widgetShowAll
, windowPresent
, windowSetDefaultIcon
, windowSetTitle
, windowSetTransientFor
)
import qualified GI.Gtk as Gtk
import GI.Pango
( FontDescription
, pattern SCALE
, fontDescriptionGetFamily
, fontDescriptionGetSize
, fontDescriptionGetSizeIsAbsolute
, fontDescriptionNew
, fontDescriptionSetFamily
, fontDescriptionSetSize
, fontDescriptionSetAbsoluteSize
)
import GI.Vte
( CursorBlinkMode(..)
, catchRegexError
, regexNewForSearch
, terminalCopyClipboard
, terminalPasteClipboard
, terminalSearchFindNext
, terminalSearchFindPrevious
, terminalSearchSetRegex
, terminalSearchSetWrapAround
, terminalSetBoldIsBright
, terminalSetCursorBlinkMode
, terminalSetFont
, terminalSetScrollbackLines
, terminalSetWordCharExceptions
, terminalSetAllowBold
)
import System.Environment (getExecutablePath)
import System.FilePath (takeFileName)
import System.IO.Error (doesNotExistErrorType, ioeGetErrorType, ioeGetFileName, tryIOError)
import Termonad.Gtk (appNew, imgToPixbuf, objFromBuildUnsafe, terminalSetEnableSixelIfExists)
import Termonad.Keys (handleKeyPress)
import Termonad.Lenses
( lensBoldIsBright
, lensEnableSixel
, lensAllowBold
, lensConfirmExit
, lensCursorBlinkMode
, lensFontConfig
, lensOptions
, lensShowMenu
, lensShowScrollbar
, lensShowTabBar
, lensScrollbackLen
, lensTMNotebookTabTermContainer
, lensTMNotebookTabs
, lensTMNotebookTabTerm
, lensTMStateApp
, lensTMStateConfig
, lensTMStateFontDesc
, lensTerm
, lensWordCharExceptions, lensTMStateWindows, lensTMWindowNotebook
)
import Termonad.Preferences.File (saveToPreferencesFile, tmConfigFromPreferencesFile)
import Termonad.Term
( createTerm
, relabelTabs
, termNextPage
, termPrevPage
, termExitFocused
, setShowTabs
, showScrollbarToPolicy
)
import Termonad.Types
( ConfigOptions(..)
, FontConfig(..)
, FontSize(FontSizePoints, FontSizeUnits)
, ShowScrollbar(..)
, ShowTabBar(..)
, TMConfig
, TMNotebookTab
, TMState
, TMState'
, TMWindowId
, getFocusedTermFromState
, getTMNotebookFromTMState
, getTMNotebookFromTMState'
, getTMWindowFromTMState'
, modFontSize
, newEmptyTMState
, tmNotebook
, tmNotebookTabTermContainer
, tmNotebookTabs
, tmStateApp
, tmStateWindows
, tmWindowAppWin
, tmWindowNotebook, fontConfigFromFontDescription
)
import Termonad.XML (interfaceText, menuText, preferencesText)
import Termonad.Cli (parseCliArgs, applyCliArgs)
import Termonad.IdMap (keysIdMap)

-- | Fill a combo box with ids and labels
--
Expand Down
19 changes: 18 additions & 1 deletion src/Termonad/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import GI.Gtk
, notebookGetNthPage
, notebookGetNPages
)
import GI.Pango (FontDescription)
import GI.Pango (FontDescription, fontDescriptionGetSize, fontDescriptionGetSizeIsAbsolute, pattern SCALE, fontDescriptionGetFamily)
import GI.Vte (Terminal, CursorBlinkMode(..))
import Termonad.Gtk (widgetEq)
import Termonad.IdMap (IdMap, IdMapKey, singletonIdMap, lookupIdMap)
Expand Down Expand Up @@ -332,6 +332,17 @@ modFontSize i (FontSizeUnits oldUnits) =
let newUnits = oldUnits + fromIntegral i
in FontSizeUnits $ if newUnits < 1 then oldUnits else newUnits

fontSizeFromFontDescription :: FontDescription -> IO FontSize
fontSizeFromFontDescription fontDesc = do
currSize <- fontDescriptionGetSize fontDesc
currAbsolute <- fontDescriptionGetSizeIsAbsolute fontDesc
pure $
if currAbsolute
then FontSizeUnits $ fromIntegral currSize / fromIntegral SCALE
else
let fontRatio :: Double = fromIntegral currSize / fromIntegral SCALE
in FontSizePoints $ round fontRatio

-- | Settings for the font to be used in Termonad.
data FontConfig = FontConfig
{ fontFamily :: !Text
Expand All @@ -351,6 +362,12 @@ defaultFontConfig =
, fontSize = defaultFontSize
}

fontConfigFromFontDescription :: FontDescription -> IO (Maybe FontConfig)
fontConfigFromFontDescription fontDescription = do
fontSize <- fontSizeFromFontDescription fontDescription
maybeFontFamily <- fontDescriptionGetFamily fontDescription
return $ (`FontConfig` fontSize) <$> maybeFontFamily

-- | This data type represents an option that can either be 'Set' or 'Unset'.
--
-- This data type is used in situations where leaving an option unset results
Expand Down

0 comments on commit 8cdff5d

Please sign in to comment.