Skip to content

Switch to GTK3 #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
include:
# The windows build is currently broken
# See #135
#- os: windows-latest
# ghc-version: '9.10'
- os: windows-latest
ghc-version: '9.10'
- os: macos-latest
ghc-version: '9.10'
# gtk2hs is broken under apline
Expand All @@ -48,28 +48,41 @@ jobs:
zlib-dev zlib-static binutils curl \
gcc g++ gmp-dev libc-dev libffi-dev make \
musl-dev ncurses-dev perl tar xz \
gtk+2.0-dev
gtk+3.0-dev

- name: Install system dependencies (Ubuntu)
if: runner.os == 'Linux' && !startsWith(matrix.container, 'alpine')
run: sudo apt-get update && sudo apt-get install libgtk2.0-dev
run: sudo apt-get update && sudo apt-get install libgtk-3-dev

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

- name: Set extra cabal build options (macOS)
if: runner.os == 'macOS'
run: |
printf 'package gtk\n flags: +have-quartz-gtk' >>cabal.project


- name: Set up GHC ${{ matrix.ghc-version }}
uses: haskell-actions/setup@v2
id: setup
with:
ghc-version: ${{ matrix.ghc-version }}

# Taken from https://github.com/agda/agda/blob/8210048a50c35d8d6fd0ae7e5edd1699592fda6f/src/github/workflows/cabal.yml#L113C1-L124C85
# See: https://github.com/haskell/text-icu/pull/86
# pacman needs MSYS /usr/bin in PATH, but this breaks the latest cache action.
# - https://github.com/actions/cache/issues/1073
# MSYS' pkg-config needs MSYS /mingw64/bin which we can safely add to the PATH
#
- name: Install system dependencies (Windows)
if: ${{ startsWith(matrix.os, 'windows') }}
shell: pwsh
run: |
$env:PATH = "C:\msys64\usr\bin;$env:PATH"
pacman --noconfirm -S msys2-keyring mingw-w64-x86_64-pkgconf mingw-w64-x86_64-gtk3
echo "C:\msys64\mingw64\bin" | Out-File -FilePath "$env:GITHUB_PATH" -Append

- name: Enable static build (only on alpine)
if: ${{ startsWith(matrix.container, 'alpine') }}
run: |
Expand Down Expand Up @@ -106,15 +119,6 @@ jobs:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ steps.cache.outputs.cache-primary-key }}

- name: Install system dependencies (Windows)
if: ${{ startsWith(matrix.os, 'windows') }}
uses: msys2/setup-msys2@v2
with:
path-type: inherit
install: >-
mingw-w64-x86_64-pkg-config
mingw-w64-x86_64-gtk2

- name: Build
run: cabal build all

Expand Down
2 changes: 1 addition & 1 deletion GUI/BookmarkView.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bookmarkViewNew builder BookmarkViewActions{..} = do
(ts,_) <- listStoreGetValue bookmarkStore pos
bookmarkViewGotoBookmark ts

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

Expand Down
9 changes: 5 additions & 4 deletions GUI/Dialogs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Graphics.UI.Gtk

import Data.Version (showVersion)
import System.FilePath
import Control.Monad.Trans


-------------------------------------------------------------------------------
Expand All @@ -32,7 +33,7 @@ aboutDialog parent
aboutDialogWebsite := "http://www.haskell.org/haskellwiki/ThreadScope",
windowTransientFor := toWindow parent
]
onResponse dialog $ \_ -> widgetDestroy dialog
dialog `on` response $ \_ -> widgetDestroy dialog
widgetShow dialog

-------------------------------------------------------------------------------
Expand All @@ -59,7 +60,7 @@ openFileDialog parent open
fileFilterAddPattern allfiles "*"
fileChooserAddFilter dialog allfiles

onResponse dialog $ \response -> do
dialog `on` response $ \response -> do
case response of
ResponseAccept -> do
mfile <- fileChooserGetFilename dialog
Expand Down Expand Up @@ -105,7 +106,7 @@ exportFileDialog parent oldfile save = do
fileFilterAddPattern pdfFiles "*.pdf"
fileChooserAddFilter dialog pdfFiles

onResponse dialog $ \response ->
dialog `on` response $ \response ->
case response of
ResponseAccept -> do
mfile <- fileChooserGetFilename dialog
Expand Down Expand Up @@ -158,5 +159,5 @@ errorMessageDialog parent headline explanation = do
dialogAddButton dialog "Close" ResponseClose
dialogSetDefaultResponse dialog ResponseClose

onResponse dialog $ \_-> widgetDestroy dialog
dialog `on` response $ \_-> widgetDestroy dialog
widgetShowAll dialog
55 changes: 25 additions & 30 deletions GUI/EventsView.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
) where

import GHC.RTS.Events
import Debug.Trace

Check warning on line 16 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Debug.Trace’ is redundant

Check warning on line 16 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Debug.Trace’ is redundant

Check warning on line 16 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Debug.Trace’ is redundant

import Graphics.UI.Gtk
import Graphics.UI.Gtk hiding (rectangle)
import Graphics.Rendering.Cairo
import qualified GUI.GtkExtras as GtkExt

Check warning on line 20 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The qualified import of ‘GUI.GtkExtras’ is redundant

Check warning on line 20 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The qualified import of ‘GUI.GtkExtras’ is redundant

Check warning on line 20 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The qualified import of ‘GUI.GtkExtras’ is redundant

import Control.Monad
import Control.Monad.Reader

Check warning on line 23 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Control.Monad.Reader’ is redundant

Check warning on line 23 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Control.Monad.Reader’ is redundant

Check warning on line 23 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Control.Monad.Reader’ is redundant
import Data.Array
import Data.Monoid
import Data.IORef
Expand Down Expand Up @@ -100,9 +102,9 @@
-----------------------------------------------------------------------------
-- Drawing

on drawArea exposeEvent $ liftIO $ do
on drawArea draw $ liftIO $ do
drawEvents eventsView =<< readIORef stateRef
return True
return ()

-----------------------------------------------------------------------------
-- Key navigation
Expand All @@ -122,7 +124,7 @@
return True

key <- eventKeyName
#if MIN_VERSION_gtk(0,13,0)
#if MIN_VERSION_gtk3(0,13,0)
case T.unpack key of
#else
case key of
Expand Down Expand Up @@ -239,7 +241,7 @@
updateScrollAdjustment EventsView{drawArea, adj}
ViewState{lineHeight, eventsState} = do

(_,windowHeight) <- widgetGetSize drawArea
Rectangle _ _ _ windowHeight <- widgetGetAllocation drawArea
let numLines = case eventsState of
EventsEmpty -> 0
EventsLoaded{eventsArr} -> snd (bounds eventsArr) + 1
Expand Down Expand Up @@ -276,18 +278,20 @@
begin = lower
end = min upper (snd (bounds eventsArr))

win <- widgetGetDrawWindow drawArea
style <- get drawArea widgetStyle
focused <- get drawArea widgetIsFocus
-- TODO: don't use Just here
Just win <- widgetGetWindow drawArea
style <- widgetGetStyle drawArea

Check warning on line 283 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

Defined but not used: ‘style’

Check warning on line 283 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

Defined but not used: ‘style’

Check warning on line 283 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

Defined but not used: ‘style’
focused <- widgetGetIsFocus drawArea
let state | focused = StateSelected
| otherwise = StateActive

pangoCtx <- widgetGetPangoContext drawArea
layout <- layoutEmpty pangoCtx
layoutSetEllipsize layout EllipsizeEnd

(width,clipHeight) <- widgetGetSize drawArea
let clipRect = Rectangle 0 0 width clipHeight

(Rectangle _ _ width _) <- widgetGetAllocation drawArea
let clipRect = Rectangle 0 0 0 0

Check warning on line 294 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

Defined but not used: ‘clipRect’

Check warning on line 294 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

Defined but not used: ‘clipRect’

Check warning on line 294 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

Defined but not used: ‘clipRect’

let -- With average char width, timeWidth is enough for 24 hours of logs
-- (way more than TS can handle, currently). Aligns nicely with
Expand All @@ -301,43 +305,34 @@

sequence_
[ do when (inside || selected) $
GtkExt.stylePaintFlatBox
style win
state1 ShadowNone
clipRect
drawArea ""
0 (round y) width (round lineHeight)
renderWithDrawWindow win $ do
-- TODO: figure out how I can grab the correct color from GTK's style
setSourceRGBA 0.2 1 1 0.2
rectangle 0 y (fromIntegral width) lineHeight
fill

-- The event time
layoutSetText layout (showEventTime event)
layoutSetAlignment layout AlignRight
layoutSetWidth layout (Just (fromIntegral timeWidth))
GtkExt.stylePaintLayout
style win
state2 True
clipRect
drawArea ""
0 (round y)
layout
renderWithDrawWindow win $ do
moveTo 0 y
showLayout layout

-- The event description text
layoutSetText layout (showEventDescr event)
layoutSetAlignment layout AlignLeft
layoutSetWidth layout (Just (fromIntegral descrWidth))
GtkExt.stylePaintLayout
style win
state2 True
clipRect
drawArea ""
(timeWidth + columnGap) (round y)
layout
renderWithDrawWindow win $ do
moveTo (fromIntegral $ timeWidth + columnGap) y
showLayout layout

| n <- [begin..end]
, let y = fromIntegral n * lineHeight - yOffset
event = eventsArr ! n
inside = maybe False (\ (s, e) -> s <= n && n <= e) mrange
selected = cursorPos == n
(state1, state2)

Check warning on line 335 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

Defined but not used: ‘state1’

Check warning on line 335 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

Defined but not used: ‘state1’

Check warning on line 335 in GUI/EventsView.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

Defined but not used: ‘state1’
| inside = (StatePrelight, StatePrelight)
| selected = (state, state)
| otherwise = (state, StateNormal)
Expand Down
58 changes: 0 additions & 58 deletions GUI/GtkExtras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
-- (as of gtk-0.12.0)

import Graphics.UI.GtkInternals
import Graphics.UI.Gtk (Rectangle)

Check warning on line 8 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Graphics.UI.Gtk’ is redundant

Check warning on line 8 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Graphics.UI.Gtk’ is redundant

Check warning on line 8 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Graphics.UI.Gtk’ is redundant

Check warning on line 8 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Graphics.UI.Gtk’ is redundant

Check warning on line 8 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.10 on macos-latest

The import of ‘Graphics.UI.Gtk’ is redundant

Check warning on line 8 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.12 on ubuntu-latest

The import of ‘Graphics.UI.Gtk’ is redundant

Check warning on line 8 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.10 on ubuntu-latest

The import of ‘Graphics.UI.Gtk’ is redundant

Check warning on line 8 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.10 on windows-latest

The import of ‘Graphics.UI.Gtk’ is redundant
import System.Glib.MainLoop
import Graphics.Rendering.Pango.Types

Check warning on line 10 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.Types’ is redundant

Check warning on line 10 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.Types’ is redundant

Check warning on line 10 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.Types’ is redundant

Check warning on line 10 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.Types’ is redundant

Check warning on line 10 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.10 on macos-latest

The import of ‘Graphics.Rendering.Pango.Types’ is redundant

Check warning on line 10 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.12 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.Types’ is redundant

Check warning on line 10 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.10 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.Types’ is redundant

Check warning on line 10 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.10 on windows-latest

The import of ‘Graphics.Rendering.Pango.Types’ is redundant
import Graphics.Rendering.Pango.BasicTypes

Check warning on line 11 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.BasicTypes’ is redundant

Check warning on line 11 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.BasicTypes’ is redundant

Check warning on line 11 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.BasicTypes’ is redundant

Check warning on line 11 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.BasicTypes’ is redundant

Check warning on line 11 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.10 on macos-latest

The import of ‘Graphics.Rendering.Pango.BasicTypes’ is redundant

Check warning on line 11 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.12 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.BasicTypes’ is redundant

Check warning on line 11 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.10 on ubuntu-latest

The import of ‘Graphics.Rendering.Pango.BasicTypes’ is redundant

Check warning on line 11 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.10 on windows-latest

The import of ‘Graphics.Rendering.Pango.BasicTypes’ is redundant
import Graphics.UI.Gtk.General.Enums (StateType, ShadowType)

Check warning on line 12 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Graphics.UI.Gtk.General.Enums’ is redundant

Check warning on line 12 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Graphics.UI.Gtk.General.Enums’ is redundant

Check warning on line 12 in GUI/GtkExtras.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Graphics.UI.Gtk.General.Enums’ is redundant

import Foreign
import Foreign.C
Expand All @@ -30,58 +30,6 @@

-------------------------------------------------------------------------------

stylePaintFlatBox :: WidgetClass widget
=> Style
-> DrawWindow
-> StateType
-> ShadowType
-> Rectangle
-> widget
-> String
-> Int -> Int -> Int -> Int
-> IO ()
stylePaintFlatBox style window stateType shadowType
clipRect widget detail x y width height =
with clipRect $ \rectPtr ->
withCString detail $ \detailPtr ->
(\(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)
style
window
((fromIntegral.fromEnum) stateType)
((fromIntegral.fromEnum) shadowType)
(castPtr rectPtr)
(toWidget widget)
detailPtr
(fromIntegral x) (fromIntegral y)
(fromIntegral width) (fromIntegral height)

stylePaintLayout :: WidgetClass widget
=> Style
-> DrawWindow
-> StateType
-> Bool
-> Rectangle
-> widget
-> String
-> Int -> Int
-> PangoLayout
-> IO ()
stylePaintLayout style window stateType useText
clipRect widget detail x y (PangoLayout _ layout) =
with clipRect $ \rectPtr ->
withCString detail $ \detailPtr ->
(\(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)
style
window
((fromIntegral.fromEnum) stateType)
(fromBool useText)
(castPtr rectPtr)
(toWidget widget)
detailPtr
(fromIntegral x) (fromIntegral y)
layout


launchProgramForURI :: String -> IO Bool
#if mingw32_HOST_OS || mingw32_TARGET_OS
launchProgramForURI uri = do
Expand Down Expand Up @@ -115,12 +63,6 @@

-------------------------------------------------------------------------------

foreign import ccall safe "gtk_paint_flat_box"
gtk_paint_flat_box :: Ptr Style -> Ptr DrawWindow -> CInt -> CInt -> Ptr () -> Ptr Widget -> Ptr CChar -> CInt -> CInt -> CInt -> CInt -> IO ()

foreign import ccall safe "gtk_paint_layout"
gtk_paint_layout :: Ptr Style -> Ptr DrawWindow -> CInt -> CInt -> Ptr () -> Ptr Widget -> Ptr CChar -> CInt -> CInt -> Ptr PangoLayoutRaw -> IO ()

foreign import ccall safe "gtk_show_uri"
gtk_show_uri :: Ptr Screen -> Ptr CChar -> CUInt -> Ptr (Ptr ()) -> IO CInt

Expand Down
Loading
Loading