Skip to content

Commit 76df52c

Browse files
committed
Switch to GTK3
1 parent 9b614f4 commit 76df52c

File tree

13 files changed

+90
-79
lines changed

13 files changed

+90
-79
lines changed

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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ eventsViewNew builder EventsViewActions{..} = do
100100
-----------------------------------------------------------------------------
101101
-- Drawing
102102

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

107107
-----------------------------------------------------------------------------
108108
-- Key navigation
@@ -122,7 +122,7 @@ eventsViewNew builder EventsViewActions{..} = do
122122
return True
123123

124124
key <- eventKeyName
125-
#if MIN_VERSION_gtk(0,13,0)
125+
#if MIN_VERSION_gtk3(0,13,0)
126126
case T.unpack key of
127127
#else
128128
case key of
@@ -239,7 +239,7 @@ updateScrollAdjustment :: EventsView -> ViewState -> IO ()
239239
updateScrollAdjustment EventsView{drawArea, adj}
240240
ViewState{lineHeight, eventsState} = do
241241

242-
(_,windowHeight) <- widgetGetSize drawArea
242+
Rectangle _ _ _ windowHeight <- widgetGetAllocation drawArea
243243
let numLines = case eventsState of
244244
EventsEmpty -> 0
245245
EventsLoaded{eventsArr} -> snd (bounds eventsArr) + 1
@@ -276,7 +276,8 @@ drawEvents EventsView{drawArea, adj}
276276
begin = lower
277277
end = min upper (snd (bounds eventsArr))
278278

279-
win <- widgetGetDrawWindow drawArea
279+
-- TODO: don't use Just here
280+
Just win <- widgetGetWindow drawArea
280281
style <- get drawArea widgetStyle
281282
focused <- get drawArea widgetIsFocus
282283
let state | focused = StateSelected
@@ -286,7 +287,7 @@ drawEvents EventsView{drawArea, adj}
286287
layout <- layoutEmpty pangoCtx
287288
layoutSetEllipsize layout EllipsizeEnd
288289

289-
(width,clipHeight) <- widgetGetSize drawArea
290+
Rectangle _ _ width clipHeight <- widgetGetAllocation drawArea
290291
let clipRect = Rectangle 0 0 width clipHeight
291292

292293
let -- With average char width, timeWidth is enough for 24 hours of logs

GUI/Histogram.hs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Graphics.UI.Gtk
1616
import qualified GUI.GtkExtras as GtkExt
1717

1818
import Data.IORef
19+
import Control.Monad.Trans
1920

2021
data HistogramView =
2122
HistogramView
@@ -51,7 +52,7 @@ histogramViewNew builder = do
5152
fontDescriptionSetFamily fd "sans serif"
5253
widgetModifyFont histogramYScaleArea (Just fd)
5354

54-
(_, xh) <- widgetGetSize timelineXScaleArea
55+
Rectangle _ _ _ xh <- widgetGetAllocation timelineXScaleArea
5556
let xScaleAreaHeight = fromIntegral xh
5657
traces = [TraceHistogram]
5758
paramsHist (w, h) minterval = ViewParameters
@@ -80,13 +81,14 @@ histogramViewNew builder = do
8081
++ "Re-run with <tt>+RTS -lf</tt> to generate them."
8182

8283
-- Program the callback for the capability drawingArea
83-
on histogramDrawingArea exposeEvent $
84+
on histogramDrawingArea draw $
8485
C.liftIO $ do
8586
maybeEventArray <- readIORef hecsIORef
86-
win <- widgetGetDrawWindow histogramDrawingArea
87-
(w, windowHeight) <- widgetGetSize histogramDrawingArea
87+
-- TODO: get rid of Just
88+
Just win <- widgetGetWindow histogramDrawingArea
89+
Rectangle _ _ w windowHeight <- widgetGetAllocation histogramDrawingArea
8890
case maybeEventArray of
89-
Nothing -> return False
91+
Nothing -> return ()
9092
Just hecs
9193
| null (durHistogram hecs) -> do
9294
GtkExt.stylePaintLayout
@@ -96,37 +98,38 @@ histogramViewNew builder = do
9698
histogramDrawingArea ""
9799
4 20
98100
layout
99-
return True
101+
return ()
100102
| otherwise -> do
101103
minterval <- readIORef mintervalIORef
102104
if windowHeight < 80
103-
then return False
105+
then return ()
104106
else do
105107
let size = (w, windowHeight - firstTraceY)
106108
params = paramsHist size minterval
107109
rect = Rectangle 0 0 w (snd size)
108-
renderWithDrawable win $
110+
renderWithDrawWindow win $
109111
renderTraces params hecs rect
110-
return True
112+
return ()
111113

112114
-- Redrawing histogramYScaleArea
113-
histogramYScaleArea `onExpose` \_ -> do
115+
histogramYScaleArea `on` draw $ liftIO $ do
114116
maybeEventArray <- readIORef hecsIORef
115117
case maybeEventArray of
116-
Nothing -> return False
118+
Nothing -> return ()
117119
Just hecs
118-
| null (durHistogram hecs) -> return False
120+
| null (durHistogram hecs) -> return ()
119121
| otherwise -> do
120-
win <- widgetGetDrawWindow histogramYScaleArea
122+
-- TODO: get rid of Just
123+
Just win <- widgetGetWindow histogramYScaleArea
121124
minterval <- readIORef mintervalIORef
122-
(_, windowHeight) <- widgetGetSize histogramYScaleArea
125+
Rectangle _ _ _ windowHeight <- widgetGetAllocation histogramYScaleArea
123126
if windowHeight < 80
124-
then return False
127+
then return ()
125128
else do
126129
let size = (undefined, windowHeight - firstTraceY)
127130
params = paramsHist size minterval
128-
renderWithDrawable win $
131+
renderWithDrawWindow win $
129132
renderYScaleArea params hecs histogramYScaleArea
130-
return True
133+
return ()
131134

132135
return HistogramView{..}

GUI/KeyView.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ keyViewNew builder = do
2424

2525
keyTreeView <- builderGetObject builder castToTreeView "key_list"
2626

27-
dw <- widgetGetDrawWindow keyTreeView
27+
-- TODO: get rid of this Just
28+
Just dw <- widgetGetWindow keyTreeView
2829
keyEntries <- createKeyEntries dw keyData
2930

3031
keyStore <- listStoreNew keyEntries
@@ -113,7 +114,7 @@ keyData =
113114
]
114115

115116

116-
createKeyEntries :: DrawableClass dw
117+
createKeyEntries :: DrawWindowClass dw
117118
=> dw
118119
-> [(String, KeyStyle, Color,String)]
119120
-> IO [(String, String, Pixbuf)]
@@ -165,12 +166,12 @@ renderKEvent keyColour = do
165166
C.relLineTo 0 25
166167
C.stroke
167168

168-
renderToPixbuf :: DrawableClass dw => dw -> (Int, Int) -> C.Render ()
169+
renderToPixbuf :: DrawWindowClass dw => dw -> (Int, Int) -> C.Render ()
169170
-> IO Pixbuf
170171
renderToPixbuf similar (w, h) draw = do
171-
pixmap <- pixmapNew (Just similar) w h Nothing
172-
renderWithDrawable pixmap draw
173-
Just pixbuf <- pixbufGetFromDrawable pixmap (Rectangle 0 0 w h)
172+
-- TODO: is this right???
173+
renderWithDrawWindow similar draw
174+
pixbuf <- pixbufNewFromWindow similar 0 0 w h
174175
return pixbuf
175176

176177
-------------------------------------------------------------------------------

GUI/MainWindow.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ instance Glib.GObjectClass MainWindow where
3232
toGObject = toGObject . mainWindow
3333
unsafeCastGObject = error "cannot downcast to MainView type"
3434

35-
instance Gtk.ObjectClass MainWindow
3635
instance Gtk.WidgetClass MainWindow
3736
instance Gtk.ContainerClass MainWindow
3837
instance Gtk.BinClass MainWindow

GUI/ProgressView.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import GUI.GtkExtras
1616
import qualified Control.Concurrent as Concurrent
1717
import Control.Exception
1818
import Data.Typeable
19+
import Control.Monad.Trans
1920

2021
data ProgressView = ProgressView {
2122
progressWindow :: Gtk.Window,
@@ -95,8 +96,8 @@ new parent cancelAction = do
9596
progress <- progressBarNew
9697

9798
cancel <- buttonNewFromStock stockCancel
98-
onClicked cancel (widgetDestroy win >> cancelAction)
99-
onDelete win (\_ -> cancelAction >> return True)
99+
cancel `on` buttonActivated $ (widgetDestroy win >> cancelAction)
100+
win `on` destroyEvent $ lift cancelAction >> return True
100101
on win keyPressEvent $ do
101102
keyVal <- eventKeyVal
102103
case keyVal of

GUI/SaveAs.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ saveAs hecs params'@ViewParameters{xScaleAreaHeight, width,
6262

6363
saveAsPDF :: FilePath -> HECs -> ViewParameters -> DrawingArea -> IO ()
6464
saveAsPDF filename hecs params yScaleArea = do
65-
(xoffset, _) <- liftIO $ widgetGetSize yScaleArea
65+
Rectangle _ _ xoffset _ <- liftIO $ widgetGetAllocation yScaleArea
6666
let (w', h', drawAll) = saveAs hecs params (fromIntegral xoffset) yScaleArea
6767
withPDFSurface filename (fromIntegral w') (fromIntegral h') $ \surface ->
6868
renderWith surface drawAll
6969

7070
saveAsPNG :: FilePath -> HECs -> ViewParameters -> DrawingArea -> IO ()
7171
saveAsPNG filename hecs params yScaleArea = do
72-
(xoffset, _) <- liftIO $ widgetGetSize yScaleArea
72+
Rectangle _ _ xoffset _ <- liftIO $ widgetGetAllocation yScaleArea
7373
let (w', h', drawAll) = saveAs hecs params (fromIntegral xoffset) yScaleArea
7474
withImageSurface FormatARGB32 w' h' $ \surface -> do
7575
renderWith surface drawAll

GUI/Timeline.hs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import Graphics.Rendering.Cairo ( liftIO )
3838

3939
import Data.IORef
4040
import Control.Monad
41+
import Control.Monad.Trans
4142
import qualified Data.Text as T
4243

4344
-----------------------------------------------------------------------------
@@ -78,7 +79,7 @@ timelineGetViewParameters :: TimelineView -> IO ViewParameters
7879
timelineGetViewParameters TimelineView{tracesIORef, bwmodeIORef, labelsModeIORef,
7980
timelineState=TimelineState{..}} = do
8081

81-
(w, _) <- widgetGetSize timelineDrawingArea
82+
Rectangle _ _ w _ <- widgetGetAllocation timelineDrawingArea
8283
scaleValue <- readIORef scaleIORef
8384
maxSpkValue <- readIORef maxSpkIORef
8485

@@ -90,7 +91,7 @@ timelineGetViewParameters TimelineView{tracesIORef, bwmodeIORef, labelsModeIORef
9091
bwmode <- readIORef bwmodeIORef
9192
labelsMode <- readIORef labelsModeIORef
9293

93-
(_, xScaleAreaHeight) <- widgetGetSize timelineXScaleArea
94+
Rectangle _ _ _ xScaleAreaHeight <- widgetGetAllocation timelineXScaleArea
9495
let histTotalHeight = stdHistogramHeight + histXScaleHeight
9596
timelineHeight =
9697
calculateTotalTimelineHeight labelsMode histTotalHeight traces
@@ -169,32 +170,32 @@ timelineViewNew builder actions = do
169170

170171
------------------------------------------------------------------------
171172
-- Redrawing labelDrawingArea
172-
timelineYScaleArea `onExpose` \_ -> do
173+
timelineYScaleArea `on` draw $ liftIO $ do
173174
maybeEventArray <- readIORef hecsIORef
174175

175176
-- Check to see if an event trace has been loaded
176177
case maybeEventArray of
177-
Nothing -> return False
178+
Nothing -> return ()
178179
Just hecs -> do
179180
traces <- readIORef tracesIORef
180181
labelsMode <- readIORef labelsModeIORef
181182
let maxP = maxSparkPool hecs
182183
maxH = fromIntegral (maxYHistogram hecs)
183184
updateYScaleArea timelineState maxP maxH Nothing labelsMode traces
184-
return True
185+
return ()
185186

186187
------------------------------------------------------------------------
187188
-- Redrawing XScaleArea
188-
timelineXScaleArea `onExpose` \_ -> do
189+
timelineXScaleArea `on` draw $ liftIO $ do
189190
maybeEventArray <- readIORef hecsIORef
190191

191192
-- Check to see if an event trace has been loaded
192193
case maybeEventArray of
193-
Nothing -> return False
194+
Nothing -> return ()
194195
Just hecs -> do
195196
let lastTx = hecLastEventTime hecs
196197
updateXScaleArea timelineState lastTx
197-
return True
198+
return ()
198199

199200
------------------------------------------------------------------------
200201
-- Allow mouse wheel to be used for zoom in/out
@@ -253,7 +254,7 @@ timelineViewNew builder actions = do
253254
in withMouseState whenNoMouse >> return True
254255
keyName <- eventKeyName
255256
keyVal <- eventKeyVal
256-
#if MIN_VERSION_gtk(0,13,0)
257+
#if MIN_VERSION_gtk3(0,13,0)
257258
case (T.unpack keyName, keyToChar keyVal, keyVal) of
258259
#else
259260
case (keyName, keyToChar keyVal, keyVal) of
@@ -277,8 +278,7 @@ timelineViewNew builder actions = do
277278
------------------------------------------------------------------------
278279
-- Redrawing
279280

280-
on timelineDrawingArea exposeEvent $ do
281-
exposeRegion <- eventRegion
281+
on timelineDrawingArea draw $ do
282282
liftIO $ do
283283
maybeEventArray <- readIORef hecsIORef
284284

@@ -290,14 +290,15 @@ timelineViewNew builder actions = do
290290
-- render either the whole height of the timeline, or the window, whichever
291291
-- is larger (this just ensure we fill the background if the timeline is
292292
-- smaller than the window).
293-
(_, h) <- widgetGetSize timelineDrawingArea
293+
exposeRect <- widgetGetAllocation timelineDrawingArea
294+
Rectangle _ _ _ h <- widgetGetAllocation timelineDrawingArea
294295
let params' = params { height = max (height params) h }
295296
selection <- readIORef selectionRef
296297
bookmarks <- readIORef bookmarkIORef
297298

298-
renderView timelineState params' hecs selection bookmarks exposeRegion
299+
renderView timelineState params' hecs selection bookmarks exposeRect
299300

300-
return True
301+
return ()
301302

302303
on timelineDrawingArea configureEvent $ do
303304
liftIO $ configureTimelineDrawingArea timelineWin
@@ -357,7 +358,7 @@ updateTimelineVScroll TimelineView{tracesIORef, labelsModeIORef, timelineState=T
357358
labelsMode <- readIORef labelsModeIORef
358359
let histTotalHeight = stdHistogramHeight + histXScaleHeight
359360
h = calculateTotalTimelineHeight labelsMode histTotalHeight traces
360-
(_,winh) <- widgetGetSize timelineDrawingArea
361+
Rectangle _ _ _ winh <- widgetGetAllocation timelineDrawingArea
361362
let winh' = fromIntegral winh;
362363
h' = fromIntegral h
363364
adjustmentSetLower timelineVAdj 0
@@ -377,7 +378,7 @@ updateTimelineVScroll TimelineView{tracesIORef, labelsModeIORef, timelineState=T
377378
-- the view at all.
378379
updateTimelineHPageSize :: TimelineState -> IO ()
379380
updateTimelineHPageSize TimelineState{..} = do
380-
(winw,_) <- widgetGetSize timelineDrawingArea
381+
Rectangle _ _ winw _ <- widgetGetAllocation timelineDrawingArea
381382
scaleValue <- readIORef scaleIORef
382383
adjustmentSetPageSize timelineAdj (fromIntegral winw * scaleValue)
383384

@@ -467,8 +468,9 @@ mouseRelease view@TimelineView{..} TimelineViewActions{..} state button x =
467468

468469
widgetSetCursor :: WidgetClass widget => widget -> Maybe Cursor -> IO ()
469470
widgetSetCursor widget cursor = do
470-
#if MIN_VERSION_gtk(0,12,1)
471-
dw <- widgetGetDrawWindow widget
471+
#if MIN_VERSION_gtk3(0,12,1)
472+
-- TODO: get rid of this Just
473+
Just dw <- widgetGetWindow widget
472474
drawWindowSetCursor dw cursor
473475
#endif
474476
return ()

0 commit comments

Comments
 (0)