gi-gtk-declarative icon indicating copy to clipboard operation
gi-gtk-declarative copied to clipboard

No window appears when running App.Simple application executable

Open dimsuz opened this issue 6 years ago • 10 comments

I have created a standalone application based on GI.Gtk.Declarative.App.Simple. Its sources are copy paste of the Hello.hs example.

You can find the repository here.

I observe the following:

  1. Trying to build and run it produces no window at all
$ stack build && stack exec amfora-hs
# No window, have to interrupt
^C^C
$
  1. Trying to load it inside stack ghci and running main manually somehow does produce a window (greeting names cycle, all's working), but then there's another problem: when I click on x (close) button, the application hangs with x pressed down. In ghci I can see that main has returned, but window stays on screen

To be sure that all this is something related to gi-gtk-declarative, I tried to replace main contents with some simple hello-world window from haskell-gi samples and it does work both with stack exec and stack ghci: window is shown and closed.

I'm not sure why no window appears for the case 1., but as for window freeze I suspect that this might have to do with the fact that there's no listener to window #destroy event in App.Simple code, but I might be mistaken.


Stack version: 1.9.3 Resolver: lts-13.2 (ghc version 8.6.3) gi-gtk-declarative: 0.4.1 gi-gtk-declarative-app-simple: 0.4.0

dimsuz avatar Jan 13 '19 19:01 dimsuz

Make sure you comple with -threaded.

@owickstrom this is definitely something which could be better documented.

aristaeus avatar Jan 23 '19 03:01 aristaeus

For the first case, as @aristaeus says, you need to add the -threaded GHC option.

For the second, I think you're right about the missing destroy listener. See the examples on how it's done there, with a special event for window being closed, eventually leading to Exit.

owickstrom avatar Jan 23 '19 09:01 owickstrom

The hint to use -threaded helped to fix the first issue, thank you!

As for the second one in my project I actually use the example copy-pasted from this repo and it does have the special event for window closing which you mention, as you can see here, but the issue is still there.

When I said that there's no listener for #destroy I've meant not the client code, but library code, this is the event used in haskell-gi example, but not emitted by App.Simple internally (not sure if needed, just an observation).

Did you try to run Hello example from stack ghci, does it close normally for you? I didn't try to compile this repo on my machine, will try soon. If this only happens in my sample-project repository, but not in gtk-gi-declarative repo, must be some local issue...

dimsuz avatar Jan 23 '19 19:01 dimsuz

Oh, okay. Sorry I'm on vacation and I don't have a laptop. Let me try this with ghci next week, and I'll get back to you.

Den ons 23 jan. 2019 19:14 skrev dimsuz [email protected]:

The hint to use -threaded helped to fix the first issue, thank you!

As for the second one in my project I actually use the example copy-pasted from this repo and it does have the special event for window closing which you mention, as you can see here https://github.com/dimsuz/amfora-hs/blob/master/src/Main.hs#L26, but the issue is still there.

When I said that there's no listener for #destroy I've meant not the client code, but library code, this is the event used in haskell-gi example, but not emitted by App.Simple internally (not sure if needed, just an observation).

Did you try to run Hello example from stack ghci, does it close normally for you? I didn't try to compile this repo on my machine, will try soon. If this only happens in my sample-project repository, but not in gtk-gi-declarative repo, must be some local issue...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/owickstrom/gi-gtk-declarative/issues/38#issuecomment-456929759, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZYCL99ym_Ck-5pqhNWBqjOvyw3IQeQks5vGLStgaJpZM4Z9U_N .

owickstrom avatar Jan 23 '19 19:01 owickstrom

Thanks, I'll report back if I find something interesting too. Have a good vacation! :)

dimsuz avatar Jan 23 '19 19:01 dimsuz

OK, I can reproduce this in GHCi (and cabal v2-repl) locally on the Hello example. Haven't had time to dig into it yet, but I'll have a closer look this weekend hopefully.

owickstrom avatar Feb 02 '19 08:02 owickstrom

I poked around a bit trying to fix the hang on exit in ghci and while I didn't fix it I discovered some things worth noting.

  1. I have a workaround that makes the X button work again. Namely just replace True to False here: https://github.com/owickstrom/gi-gtk-declarative/blob/master/examples/AddBoxes.hs#L30. As I understand this lets the destroy signal propagate to the window. That makes me wonder if the topmost widget doesn't need to be explicitly destroyed.

  2. The builder example from haskell-gi also hangs on exit in ghci: https://github.com/haskell-gi/haskell-gi/blob/master/examples/introductory/src/builder.hs Again, it seems that calling Gtk.mainQuit is not enough in ghci. Modifying the example to send a close signal to the window on button click made the example work for me.

  3. The root cause is probably different, I suspect that some finalizers are not getting called or get called in a wrong thread. I base that on the investigation from https://github.com/haskell-gi/haskell-gi/issues/96, but that's only a weak suspicion.

My GHC version: 8.6.5

niteria avatar Jul 12 '19 18:07 niteria

I ran into the exact same problem and the s/True/False/ workaround worked for me as well :+1:

mrkgnao avatar Nov 11 '19 00:11 mrkgnao

Switching the propagation, if I'm not mistaken (it's been a while since I hacked on this), has the unfortunate effect of the special Exit event not being emitted. Maybe this would not matter for most applications, but I think a graceful shutdown mechanism should depend on the Exit event.

owickstrom avatar Dec 24 '19 08:12 owickstrom

I've also confirmed it hangs in GHCi for me. Can't say say for certain, but I think it has worked before (maybe an older GHCi or haskell-gi package version).

owickstrom avatar Jan 03 '20 09:01 owickstrom