Skip to content

Commit e8996fc

Browse files
authored
Switch to GTK3 (#137)
We upgrade from the deprecated GTK2 to the still supported GTK3. Most of the changes we had to make were described in the migration guide: https://docs.gtk.org/gtk3/migrating-2to3.html#changes-that-need-to-be-done-at-the-time-of-the-switch Many of the functions we depended on for low-level rendering were removed, so I've substituted mostly equivalent ones. The way events are subscribed to has slightly changed and that has lead to a bunch of changes. With the new version of GTK3, windows CI works again. Resolves #135, #97 We've also updated the Cabal file to be made aware of stuff included through TH.
1 parent 4a1a6c4 commit e8996fc

File tree

15 files changed

+131
-183
lines changed

15 files changed

+131
-183
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
include:
2525
# The windows build is currently broken
2626
# See #135
27-
#- os: windows-latest
28-
# ghc-version: '9.10'
27+
- os: windows-latest
28+
ghc-version: '9.10'
2929
- os: macos-latest
3030
ghc-version: '9.10'
3131
# gtk2hs is broken under apline
@@ -48,28 +48,41 @@ jobs:
4848
zlib-dev zlib-static binutils curl \
4949
gcc g++ gmp-dev libc-dev libffi-dev make \
5050
musl-dev ncurses-dev perl tar xz \
51-
gtk+2.0-dev
51+
gtk+3.0-dev
5252
5353
- name: Install system dependencies (Ubuntu)
5454
if: runner.os == 'Linux' && !startsWith(matrix.container, 'alpine')
55-
run: sudo apt-get update && sudo apt-get install libgtk2.0-dev
55+
run: sudo apt-get update && sudo apt-get install libgtk-3-dev
5656

5757
- name: Install system dependencies (macOS)
5858
if: runner.os == 'macOS'
59-
run: brew install cairo gtk+ pkg-config
59+
run: brew install cairo gtk+3 pkg-config
6060

6161
- name: Set extra cabal build options (macOS)
6262
if: runner.os == 'macOS'
6363
run: |
6464
printf 'package gtk\n flags: +have-quartz-gtk' >>cabal.project
6565
66-
6766
- name: Set up GHC ${{ matrix.ghc-version }}
6867
uses: haskell-actions/setup@v2
6968
id: setup
7069
with:
7170
ghc-version: ${{ matrix.ghc-version }}
7271

72+
# Taken from https://github.com/agda/agda/blob/8210048a50c35d8d6fd0ae7e5edd1699592fda6f/src/github/workflows/cabal.yml#L113C1-L124C85
73+
# See: https://github.com/haskell/text-icu/pull/86
74+
# pacman needs MSYS /usr/bin in PATH, but this breaks the latest cache action.
75+
# - https://github.com/actions/cache/issues/1073
76+
# MSYS' pkg-config needs MSYS /mingw64/bin which we can safely add to the PATH
77+
#
78+
- name: Install system dependencies (Windows)
79+
if: ${{ startsWith(matrix.os, 'windows') }}
80+
shell: pwsh
81+
run: |
82+
$env:PATH = "C:\msys64\usr\bin;$env:PATH"
83+
pacman --noconfirm -S msys2-keyring mingw-w64-x86_64-pkgconf mingw-w64-x86_64-gtk3
84+
echo "C:\msys64\mingw64\bin" | Out-File -FilePath "$env:GITHUB_PATH" -Append
85+
7386
- name: Enable static build (only on alpine)
7487
if: ${{ startsWith(matrix.container, 'alpine') }}
7588
run: |
@@ -106,15 +119,6 @@ jobs:
106119
path: ${{ steps.setup.outputs.cabal-store }}
107120
key: ${{ steps.cache.outputs.cache-primary-key }}
108121

109-
- name: Install system dependencies (Windows)
110-
if: ${{ startsWith(matrix.os, 'windows') }}
111-
uses: msys2/setup-msys2@v2
112-
with:
113-
path-type: inherit
114-
install: >-
115-
mingw-w64-x86_64-pkg-config
116-
mingw-w64-x86_64-gtk2
117-
118122
- name: Build
119123
run: cabal build all
120124

GUI/BookmarkView.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bookmarkViewNew builder BookmarkViewActions{..} = do
117117
(ts,_) <- listStoreGetValue bookmarkStore pos
118118
bookmarkViewGotoBookmark ts
119119

120-
onRowActivated bookmarkTreeView $ \[pos] _ -> do
120+
bookmarkTreeView `on` rowActivated $ \[pos] _ -> do
121121
(ts, _) <- listStoreGetValue bookmarkStore pos
122122
bookmarkViewGotoBookmark ts
123123

GUI/Dialogs.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Graphics.UI.Gtk
88

99
import Data.Version (showVersion)
1010
import System.FilePath
11+
import Control.Monad.Trans
1112

1213

1314
-------------------------------------------------------------------------------
@@ -32,7 +33,7 @@ aboutDialog parent
3233
aboutDialogWebsite := "http://www.haskell.org/haskellwiki/ThreadScope",
3334
windowTransientFor := toWindow parent
3435
]
35-
onResponse dialog $ \_ -> widgetDestroy dialog
36+
dialog `on` response $ \_ -> widgetDestroy dialog
3637
widgetShow dialog
3738

3839
-------------------------------------------------------------------------------
@@ -59,7 +60,7 @@ openFileDialog parent open
5960
fileFilterAddPattern allfiles "*"
6061
fileChooserAddFilter dialog allfiles
6162

62-
onResponse dialog $ \response -> do
63+
dialog `on` response $ \response -> do
6364
case response of
6465
ResponseAccept -> do
6566
mfile <- fileChooserGetFilename dialog
@@ -105,7 +106,7 @@ exportFileDialog parent oldfile save = do
105106
fileFilterAddPattern pdfFiles "*.pdf"
106107
fileChooserAddFilter dialog pdfFiles
107108

108-
onResponse dialog $ \response ->
109+
dialog `on` response $ \response ->
109110
case response of
110111
ResponseAccept -> do
111112
mfile <- fileChooserGetFilename dialog
@@ -158,5 +159,5 @@ errorMessageDialog parent headline explanation = do
158159
dialogAddButton dialog "Close" ResponseClose
159160
dialogSetDefaultResponse dialog ResponseClose
160161

161-
onResponse dialog $ \_-> widgetDestroy dialog
162+
dialog `on` response $ \_-> widgetDestroy dialog
162163
widgetShowAll dialog

GUI/EventsView.hs

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ module GUI.EventsView (
1313
) where
1414

1515
import GHC.RTS.Events
16+
import Debug.Trace
1617

17-
import Graphics.UI.Gtk
18+
import Graphics.UI.Gtk hiding (rectangle)
19+
import Graphics.Rendering.Cairo
1820
import qualified GUI.GtkExtras as GtkExt
1921

2022
import Control.Monad
@@ -100,9 +102,9 @@ eventsViewNew builder EventsViewActions{..} = do
100102
-----------------------------------------------------------------------------
101103
-- Drawing
102104

103-
on drawArea exposeEvent $ liftIO $ do
105+
on drawArea draw $ liftIO $ do
104106
drawEvents eventsView =<< readIORef stateRef
105-
return True
107+
return ()
106108

107109
-----------------------------------------------------------------------------
108110
-- Key navigation
@@ -122,7 +124,7 @@ eventsViewNew builder EventsViewActions{..} = do
122124
return True
123125

124126
key <- eventKeyName
125-
#if MIN_VERSION_gtk(0,13,0)
127+
#if MIN_VERSION_gtk3(0,13,0)
126128
case T.unpack key of
127129
#else
128130
case key of
@@ -239,7 +241,7 @@ updateScrollAdjustment :: EventsView -> ViewState -> IO ()
239241
updateScrollAdjustment EventsView{drawArea, adj}
240242
ViewState{lineHeight, eventsState} = do
241243

242-
(_,windowHeight) <- widgetGetSize drawArea
244+
Rectangle _ _ _ windowHeight <- widgetGetAllocation drawArea
243245
let numLines = case eventsState of
244246
EventsEmpty -> 0
245247
EventsLoaded{eventsArr} -> snd (bounds eventsArr) + 1
@@ -276,18 +278,20 @@ drawEvents EventsView{drawArea, adj}
276278
begin = lower
277279
end = min upper (snd (bounds eventsArr))
278280

279-
win <- widgetGetDrawWindow drawArea
280-
style <- get drawArea widgetStyle
281-
focused <- get drawArea widgetIsFocus
281+
-- TODO: don't use Just here
282+
Just win <- widgetGetWindow drawArea
283+
style <- widgetGetStyle drawArea
284+
focused <- widgetGetIsFocus drawArea
282285
let state | focused = StateSelected
283286
| otherwise = StateActive
284287

285288
pangoCtx <- widgetGetPangoContext drawArea
286289
layout <- layoutEmpty pangoCtx
287290
layoutSetEllipsize layout EllipsizeEnd
288291

289-
(width,clipHeight) <- widgetGetSize drawArea
290-
let clipRect = Rectangle 0 0 width clipHeight
292+
293+
(Rectangle _ _ width _) <- widgetGetAllocation drawArea
294+
let clipRect = Rectangle 0 0 0 0
291295

292296
let -- With average char width, timeWidth is enough for 24 hours of logs
293297
-- (way more than TS can handle, currently). Aligns nicely with
@@ -301,36 +305,27 @@ drawEvents EventsView{drawArea, adj}
301305

302306
sequence_
303307
[ do when (inside || selected) $
304-
GtkExt.stylePaintFlatBox
305-
style win
306-
state1 ShadowNone
307-
clipRect
308-
drawArea ""
309-
0 (round y) width (round lineHeight)
308+
renderWithDrawWindow win $ do
309+
-- TODO: figure out how I can grab the correct color from GTK's style
310+
setSourceRGBA 0.2 1 1 0.2
311+
rectangle 0 y (fromIntegral width) lineHeight
312+
fill
310313

311314
-- The event time
312315
layoutSetText layout (showEventTime event)
313316
layoutSetAlignment layout AlignRight
314317
layoutSetWidth layout (Just (fromIntegral timeWidth))
315-
GtkExt.stylePaintLayout
316-
style win
317-
state2 True
318-
clipRect
319-
drawArea ""
320-
0 (round y)
321-
layout
318+
renderWithDrawWindow win $ do
319+
moveTo 0 y
320+
showLayout layout
322321

323322
-- The event description text
324323
layoutSetText layout (showEventDescr event)
325324
layoutSetAlignment layout AlignLeft
326325
layoutSetWidth layout (Just (fromIntegral descrWidth))
327-
GtkExt.stylePaintLayout
328-
style win
329-
state2 True
330-
clipRect
331-
drawArea ""
332-
(timeWidth + columnGap) (round y)
333-
layout
326+
renderWithDrawWindow win $ do
327+
moveTo (fromIntegral $ timeWidth + columnGap) y
328+
showLayout layout
334329

335330
| n <- [begin..end]
336331
, let y = fromIntegral n * lineHeight - yOffset

GUI/GtkExtras.hs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -30,58 +30,6 @@ waitGUI = do
3030

3131
-------------------------------------------------------------------------------
3232

33-
stylePaintFlatBox :: WidgetClass widget
34-
=> Style
35-
-> DrawWindow
36-
-> StateType
37-
-> ShadowType
38-
-> Rectangle
39-
-> widget
40-
-> String
41-
-> Int -> Int -> Int -> Int
42-
-> IO ()
43-
stylePaintFlatBox style window stateType shadowType
44-
clipRect widget detail x y width height =
45-
with clipRect $ \rectPtr ->
46-
withCString detail $ \detailPtr ->
47-
(\(Style arg1) (DrawWindow arg2) arg3 arg4 arg5 (Widget arg6) arg7 arg8 arg9 arg10 arg11 -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->withForeignPtr arg6 $ \argPtr6 -> gtk_paint_flat_box argPtr1 argPtr2 arg3 arg4 arg5 argPtr6 arg7 arg8 arg9 arg10 arg11)
48-
style
49-
window
50-
((fromIntegral.fromEnum) stateType)
51-
((fromIntegral.fromEnum) shadowType)
52-
(castPtr rectPtr)
53-
(toWidget widget)
54-
detailPtr
55-
(fromIntegral x) (fromIntegral y)
56-
(fromIntegral width) (fromIntegral height)
57-
58-
stylePaintLayout :: WidgetClass widget
59-
=> Style
60-
-> DrawWindow
61-
-> StateType
62-
-> Bool
63-
-> Rectangle
64-
-> widget
65-
-> String
66-
-> Int -> Int
67-
-> PangoLayout
68-
-> IO ()
69-
stylePaintLayout style window stateType useText
70-
clipRect widget detail x y (PangoLayout _ layout) =
71-
with clipRect $ \rectPtr ->
72-
withCString detail $ \detailPtr ->
73-
(\(Style arg1) (DrawWindow arg2) arg3 arg4 arg5 (Widget arg6) arg7 arg8 arg9 (PangoLayoutRaw arg10) -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->withForeignPtr arg6 $ \argPtr6 ->withForeignPtr arg10 $ \argPtr10 -> gtk_paint_layout argPtr1 argPtr2 arg3 arg4 arg5 argPtr6 arg7 arg8 arg9 argPtr10)
74-
style
75-
window
76-
((fromIntegral.fromEnum) stateType)
77-
(fromBool useText)
78-
(castPtr rectPtr)
79-
(toWidget widget)
80-
detailPtr
81-
(fromIntegral x) (fromIntegral y)
82-
layout
83-
84-
8533
launchProgramForURI :: String -> IO Bool
8634
#if mingw32_HOST_OS || mingw32_TARGET_OS
8735
launchProgramForURI uri = do
@@ -115,12 +63,6 @@ launchProgramForURI uri =
11563

11664
-------------------------------------------------------------------------------
11765

118-
foreign import ccall safe "gtk_paint_flat_box"
119-
gtk_paint_flat_box :: Ptr Style -> Ptr DrawWindow -> CInt -> CInt -> Ptr () -> Ptr Widget -> Ptr CChar -> CInt -> CInt -> CInt -> CInt -> IO ()
120-
121-
foreign import ccall safe "gtk_paint_layout"
122-
gtk_paint_layout :: Ptr Style -> Ptr DrawWindow -> CInt -> CInt -> Ptr () -> Ptr Widget -> Ptr CChar -> CInt -> CInt -> Ptr PangoLayoutRaw -> IO ()
123-
12466
foreign import ccall safe "gtk_show_uri"
12567
gtk_show_uri :: Ptr Screen -> Ptr CChar -> CUInt -> Ptr (Ptr ()) -> IO CInt
12668

0 commit comments

Comments
 (0)