Skip to content
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

Native Integration - Linux: Implement alert API using GtkMessageDialog #278

Closed
bryphe opened this issue Jan 29, 2019 · 5 comments · Fixed by #294
Closed

Native Integration - Linux: Implement alert API using GtkMessageDialog #278

bryphe opened this issue Jan 29, 2019 · 5 comments · Fixed by #294
Labels
A-native Area: Native platform integration help wanted Extra attention is needed platform-linux Platform: Linux

Comments

@bryphe
Copy link
Member

bryphe commented Jan 29, 2019

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:

printf("WARNING - Not implemented: alert");

@tcoopman gave some very helpful suggestions - Electron uses GTK for its Linux platform UI - helpful PR is here: electron/electron#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:

- 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.

@bryphe bryphe changed the title Native Integration - Linux - Alert: Implement alert using GtkMessageDialog Native Integration - Linux: Implement alert API using GtkMessageDialog Jan 29, 2019
@bryphe bryphe added help wanted Extra attention is needed A-native Area: Native platform integration platform-linux Platform: Linux labels Jan 29, 2019
@akinsho
Copy link
Member

akinsho commented Jan 29, 2019

@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

@bryphe
Copy link
Member Author

bryphe commented Jan 30, 2019

@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

@tcoopman
Copy link
Contributor

tcoopman commented Jan 30, 2019 via email

@akinsho
Copy link
Member

akinsho commented Jan 31, 2019

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

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

@bryphe
Copy link
Member Author

bryphe commented Jan 31, 2019

@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

@akinsho akinsho mentioned this issue Jan 31, 2019
2 tasks
akinsho added a commit that referenced this issue Feb 5, 2019
Very early WIP implementation of gtk dialog alert to fix #278 (please ignore the commented out code etc. just trying to get stuff working)

Progress so far:

No longer chokes on `#include <gtk/gtk.h>` - currently need to tweak the borrowed snippet from #278 as an example to create an alert doesn't work as is, I think

Things to note/note to self:
- [x] I have to rework the `discover.ml` so it can use the pkg_config functionality on linux but behave as normal on other systems

- [x] Fix GTK crash on opening dialog - things compile but the function to open a dialog causes a crash, note this also happens in a separate project when I try and create a dialog with the same function (might be specific to my machine or more likely a bug in the code)
akinsho added a commit to akinsho/revery that referenced this issue Feb 18, 2019
Very early WIP implementation of gtk dialog alert to fix revery-ui#278 (please ignore the commented out code etc. just trying to get stuff working)

Progress so far:

No longer chokes on `#include <gtk/gtk.h>` - currently need to tweak the borrowed snippet from revery-ui#278 as an example to create an alert doesn't work as is, I think

Things to note/note to self:
- [x] I have to rework the `discover.ml` so it can use the pkg_config functionality on linux but behave as normal on other systems

- [x] Fix GTK crash on opening dialog - things compile but the function to open a dialog causes a crash, note this also happens in a separate project when I try and create a dialog with the same function (might be specific to my machine or more likely a bug in the code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-native Area: Native platform integration help wanted Extra attention is needed platform-linux Platform: Linux
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants