Revery: Native Integration - Linux: Implement alert API using GtkMessageDialog

Created on 29 Jan 2019  ยท  5Comments  ยท  Source: revery-ui/revery

Following up from #276 , which implements alert for OSX/Windows, this is tracking integrating a Gtk strategy for the 'alert' dialog on Linux. There's a few different pieces we'll need - right now, there is only a placeholder stub where the Linux strategy should be:
https://github.com/revery-ui/revery/blob/0beaee47dee1f9fdfa7a45d823a6f1f094790a13/src/Native/dialog.cpp#L37

@tcoopman gave some very helpful suggestions - Electron uses GTK for its Linux platform UI - helpful PR is here: https://github.com/electron/electron/pull/15293

A few considerations:

Dependencies

Will we need to add libgtk-3-dev as a dependency for our build environments?

Build

We have a discover.ml script to help populate the right C compiler settings: https://github.com/revery-ui/revery/blob/0beaee47dee1f9fdfa7a45d823a6f1f094790a13/src/Native/config/discover.ml#L17 - but we'll need to figure out the right place for header files (-I) and libs (-lgtk3). Is there a common place where this would usually be found? Or will we need something like pkg-config to discover these?

Functionality

The code snippets here seem very useful for create a dialog:
https://developer.gnome.org/gtk3/stable/GtkMessageDialog.html

GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
dialog = gtk_message_dialog_new (parent_window,
                                 flags,
                                 GTK_MESSAGE_ERROR,
                                 GTK_BUTTONS_CLOSE,
                                 "Error reading โ€œ%sโ€: %s",
                                 filename,
                                 g_strerror (errno));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);

Once we have the proper compilation settings, we should be able to use this code as-is. I believe for now we could pass NULL for the parent_window, until we have a good way to go from the X11 window handle from glfwGetNativeWindow to some GTK type.

A-native help wanted platform-linux

Most helpful comment

Having a look at https://ocaml.org/learn/tutorials/introduction_to_gtk.html
might be useful as well

On Wed, Jan 30, 2019, 01:37 Bryan Phelps <[email protected] wrote:

@Akin909 https://github.com/Akin909 - that would be great! This would
be a fun way to try out some C/C++ code if you're up for it ๐Ÿ˜„

My recommendation is to try compiling a simple GTK app with C before
trying to do the interop with the OCaml side - this looks like a good
tutorial: https://developer.gnome.org/gtk3/stable/gtk-getting-started.html

(That way, you have confidence that the C part works - and then, its just
a matter of wiring things up to Revery). Let me know if you need any help
getting started

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/revery-ui/revery/issues/278#issuecomment-458764929,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACx6npHn7-wI-Bh2wHQGlTCPknOJs9Aks5vIOlXgaJpZM4aYdeR
.

All 5 comments

@bryphe this is definitely outside my wheelhouse but would be up for giving this a shot I use Linux on my home machine so would be keen to get linux related functionality like this working

@Akin909 - that would be great! This would be a fun way to try out some C/C++ code if you're up for it ๐Ÿ˜„

My recommendation is to try compiling a simple GTK app with C before trying to do the interop with the OCaml side - this looks like a good tutorial: https://developer.gnome.org/gtk3/stable/gtk-getting-started.html

(That way, you have confidence that the C part works - and then, its just a matter of wiring things up to Revery). Let me know if you need any help getting started

Having a look at https://ocaml.org/learn/tutorials/introduction_to_gtk.html
might be useful as well

On Wed, Jan 30, 2019, 01:37 Bryan Phelps <[email protected] wrote:

@Akin909 https://github.com/Akin909 - that would be great! This would
be a fun way to try out some C/C++ code if you're up for it ๐Ÿ˜„

My recommendation is to try compiling a simple GTK app with C before
trying to do the interop with the OCaml side - this looks like a good
tutorial: https://developer.gnome.org/gtk3/stable/gtk-getting-started.html

(That way, you have confidence that the C part works - and then, its just
a matter of wiring things up to Revery). Let me know if you need any help
getting started

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/revery-ui/revery/issues/278#issuecomment-458764929,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACx6npHn7-wI-Bh2wHQGlTCPknOJs9Aks5vIOlXgaJpZM4aYdeR
.

@bryphe I've gone through the tutorial you recommended that was really helpful thanks :pray:

Re. the flags for gtk, from the tutorial and some digging around I think these are available on most linux systems but apparently the location of the header files can vary
I found that dune's Configurator has a Pkg_config module that I can use to derive the flags, which I've verified correctly gets them but just fiddling with the dune file now as it doesn't seem to be adding the includes to the commandline arg for ocamlopt will do some more poking

@Akin909 - awesome, great progress!

Note that there is both a flags and c_flags/cxx_flags - might need to use one or the other. You can see the discover.ml we have in reason-glfw for a more complete example (for ideas): https://github.com/bryphe/reason-glfw/blob/master/config/discover.ml

I suspect you might need to add some of these flags to the flags array instead of c_flags. Some more info here: https://jbuilder.readthedocs.io/en/latest/dune-files.html?highlight=flags#ocaml-flags

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JulesGuesnon picture JulesGuesnon  ยท  5Comments

bryphe picture bryphe  ยท  4Comments

bryphe picture bryphe  ยท  3Comments

albertorestifo picture albertorestifo  ยท  3Comments

bryphe picture bryphe  ยท  3Comments