Skip to content

Commit 4423878

Browse files
committed
Wrap terminalSetEnableSixel in CPP because it doesn't exist in previous vte versions
1 parent 2bb6780 commit 4423878

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

Setup.hs

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ createVteVersionCPPOpts
104104
createVteVersionCPPOpts vers =
105105
catMaybes
106106
[ if vers >= mkVersion [0,44] then Just "-DVTE_VERSION_GEQ_0_44" else Nothing
107+
, if vers >= mkVersion [0,63] then Just "-DVTE_VERSION_GEQ_0_63" else Nothing
107108
]
108109

109110
-- | Based on the version of the GTK3 library as reported by @pkg-config@, return

src/Termonad/App.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ import GI.Vte
117117
, terminalSearchSetWrapAround
118118
, terminalSetBoldIsBright
119119
, terminalSetCursorBlinkMode
120-
, terminalSetEnableSixel
121120
, terminalSetFont
122121
, terminalSetScrollbackLines
123122
, terminalSetWordCharExceptions
@@ -126,7 +125,7 @@ import System.Environment (getExecutablePath)
126125
import System.FilePath (takeFileName)
127126

128127
import Paths_termonad (getDataFileName)
129-
import Termonad.Gtk (appNew, objFromBuildUnsafe)
128+
import Termonad.Gtk (appNew, objFromBuildUnsafe, terminalSetEnableSixelIfExists)
130129
import Termonad.Keys (handleKeyPress)
131130
import Termonad.Lenses
132131
( lensBoldIsBright
@@ -729,7 +728,7 @@ applyNewPreferencesToTab mvarTMState tab = do
729728
terminalSetWordCharExceptions term (wordCharExceptions options)
730729
terminalSetScrollbackLines term (fromIntegral (scrollbackLen options))
731730
terminalSetBoldIsBright term (boldIsBright options)
732-
terminalSetEnableSixel term (enableSixel options)
731+
terminalSetEnableSixelIfExists term (enableSixel options)
733732

734733
let vScrollbarPolicy = showScrollbarToPolicy (options ^. lensShowScrollbar)
735734
scrolledWindowSetPolicy scrolledWin PolicyTypeAutomatic vScrollbarPolicy

src/Termonad/Gtk.hs

+35
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
{-# LANGUAGE CPP #-}
2+
3+
-- | This module contains two things:
4+
--
5+
-- 1. Extension functions to libraries like GTK. These functions wrap up some
6+
-- generic GTK functionality. They are not Termonad-specific.
7+
--
8+
-- 2. Wrappers around functionality that is only specific to certain versions
9+
-- of libraries like GTK or VTE.
10+
--
11+
-- For instance, 'terminalSetEnableSixelIfExists' is
12+
-- a wrapper around 'terminalSetEnableSixel'. Sixel support is only availble in
13+
-- vte >= 0.63, so if a user tries to compile Termonad with a version of vte
14+
-- less than 0.63, this function won't do anything.
15+
116
module Termonad.Gtk where
217

318
import Termonad.Prelude
@@ -12,6 +27,12 @@ import GI.Gdk
1227
import GI.Gio (ApplicationFlags)
1328
import GI.Gtk (Application, IsWidget, Widget(Widget), applicationNew, builderGetObject, toWidget)
1429
import qualified GI.Gtk as Gtk
30+
import GI.Vte
31+
( IsTerminal
32+
#ifdef VTE_VERSION_GEQ_0_63
33+
, terminalSetEnableSixel
34+
#endif
35+
)
1536

1637

1738
objFromBuildUnsafe ::
@@ -58,3 +79,17 @@ widgetEq a b = do
5879
withManagedPtr managedPtrA $ \ptrA ->
5980
withManagedPtr managedPtrB $ \ptrB ->
6081
pure (ptrA == ptrB)
82+
83+
-- | Wrapper around 'terminalSetEnableSixel'. The 'terminalSetEnableSixel' function
84+
-- is only available starting with vte-0.63. This function has no effect when
85+
-- compiling against previous versions of vte.
86+
terminalSetEnableSixelIfExists
87+
:: (HasCallStack, MonadIO m, IsTerminal t)
88+
=> t -- ^ a Terminal
89+
-> Bool -- ^ whether to enable SIXEL images
90+
-> m ()
91+
terminalSetEnableSixelIfExists t b = do
92+
#ifdef VTE_VERSION_GEQ_0_63
93+
terminalSetEnableSixel t b
94+
#endif
95+
pure ()

src/Termonad/Term.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ import GI.Vte
9090
, terminalNew
9191
, terminalSetBoldIsBright
9292
, terminalSetCursorBlinkMode
93-
, terminalSetEnableSixel
9493
, terminalSetFont
9594
, terminalSetScrollbackLines
9695
, terminalSetWordCharExceptions
@@ -99,6 +98,7 @@ import GI.Vte
9998
import System.Directory (getSymbolicLinkTarget)
10099
import System.Environment (lookupEnv)
101100

101+
import Termonad.Gtk (terminalSetEnableSixelIfExists)
102102
import Termonad.Lenses
103103
( lensConfirmExit
104104
, lensOptions
@@ -361,7 +361,7 @@ createAndInitVteTerm tmStateFontDesc curOpts = do
361361
terminalSetScrollbackLines vteTerm (fromIntegral (scrollbackLen curOpts))
362362
terminalSetCursorBlinkMode vteTerm (cursorBlinkMode curOpts)
363363
terminalSetBoldIsBright vteTerm (boldIsBright curOpts)
364-
terminalSetEnableSixel vteTerm (enableSixel curOpts)
364+
terminalSetEnableSixelIfExists vteTerm (enableSixel curOpts)
365365
widgetShow vteTerm
366366
pure vteTerm
367367

0 commit comments

Comments
 (0)