-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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)
- Loading branch information
Showing
6 changed files
with
108 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
extern "C" { | ||
void revery_alert_gtk(void *pWin, const char *szMessage); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,41 @@ | ||
type os = | ||
| Windows | ||
| Mac | ||
| Linux | ||
| Unknown | ||
module C = Configurator.V1 | ||
|
||
type os = Windows | Mac | Linux | Unknown | ||
|
||
type config = {libs: string list; cflags: string list; flags: string list} | ||
|
||
let get_mac_config () = | ||
{cflags= ["-I"; "."; "-x"; "objective-c"]; libs= []; flags= []} | ||
|
||
let get_linux_config c = | ||
let default = {libs= []; cflags= []; flags= []} in | ||
match C.Pkg_config.get c with | ||
| None -> default | ||
| Some pc -> ( | ||
match C.Pkg_config.query pc ~package:"gtk+-3.0" with | ||
| None -> default | ||
| Some conf -> {libs= conf.libs; cflags= conf.cflags; flags= []} ) | ||
|
||
let uname () = | ||
let ic = Unix.open_process_in "uname" in | ||
let uname = input_line ic in let () = close_in ic in uname | ||
let uname = input_line ic in | ||
let () = close_in ic in | ||
uname | ||
|
||
let get_os = | ||
match Sys.os_type with | ||
| "Win32" -> Windows | ||
| _ -> | ||
(match uname () with | ||
| "Darwin" -> Mac | ||
| "Linux" -> Linux | ||
| _ -> Unknown) | ||
let c_flags = | ||
match get_os with | Mac -> ["-I"; "."; "-x"; "objective-c"] | _ -> [] | ||
let flags = [] | ||
;;Configurator.V1.Flags.write_sexp "c_flags.sexp" c_flags; | ||
Configurator.V1.Flags.write_sexp "flags.sexp" flags | ||
| _ -> ( | ||
match uname () with "Darwin" -> Mac | "Linux" -> Linux | _ -> Unknown ) | ||
|
||
let () = | ||
C.main ~name:"discover" (fun c -> | ||
let conf = | ||
match get_os with | ||
| Mac -> get_mac_config () | ||
| Linux -> get_linux_config c | ||
| _ -> {libs= []; flags= []; cflags= []} | ||
in | ||
C.Flags.write_sexp "flags.sexp" conf.flags ; | ||
C.Flags.write_sexp "c_flags.sexp" conf.cflags ; | ||
C.Flags.write_sexp "c_library_flags.sexp" conf.libs ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,45 @@ | ||
#include <stdio.h> | ||
|
||
#include <caml/mlvalues.h> | ||
#include <caml/memory.h> | ||
#include <caml/alloc.h> | ||
#include <caml/callback.h> | ||
#include <caml/memory.h> | ||
#include <caml/mlvalues.h> | ||
|
||
#ifdef WIN32 | ||
#include "ReveryWin32.h" | ||
#include "ReveryWin32.h" | ||
#elif __APPLE__ | ||
#include "ReveryCocoa.h" | ||
#include "ReveryCocoa.h" | ||
#else | ||
#include "ReveryGtk.h" | ||
#endif | ||
|
||
extern "C" { | ||
CAMLprim value | ||
revery_alertSupported() { | ||
#ifdef WIN32 | ||
return Val_true; | ||
#elif __APPLE__ | ||
return Val_true; | ||
#else | ||
return Val_false; | ||
#endif | ||
} | ||
CAMLprim value revery_alertSupported() { | ||
#ifdef WIN32 | ||
return Val_true; | ||
#elif __APPLE__ | ||
return Val_true; | ||
#elif __linux__ | ||
return Val_true; | ||
#else | ||
return Val_false; | ||
#endif | ||
} | ||
|
||
CAMLprim value | ||
revery_alert(value vWindow, value vMessage) { | ||
CAMLparam2(vWindow, vMessage); | ||
const char *szMessage = String_val(vMessage); | ||
void* pWin = (void *)vWindow; | ||
CAMLprim value revery_alert(value vWindow, value vMessage) { | ||
CAMLparam2(vWindow, vMessage); | ||
const char *szMessage = String_val(vMessage); | ||
void *pWin = (void *)vWindow; | ||
|
||
#ifdef WIN32 | ||
revery_alert_win32(pWin, szMessage); | ||
#elif __APPLE__ | ||
revery_alert_cocoa(pWin, szMessage); | ||
#else | ||
printf("WARNING - Not implemented: alert"); | ||
#endif | ||
return Val_unit; | ||
} | ||
#ifdef WIN32 | ||
revery_alert_win32(pWin, szMessage); | ||
#elif __APPLE__ | ||
revery_alert_cocoa(pWin, szMessage); | ||
#elif __linux__ | ||
revery_alert_gtk(pWin, szMessage); | ||
#else | ||
printf("WARNING - Not implemented: alert"); | ||
#endif | ||
return Val_unit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifdef __linux__ | ||
#include <gtk/gtk.h> | ||
|
||
// The callback to g_signal_connect MUST be an `activate` function | ||
static void activate(GtkApplication *app, const char *user_data) { | ||
GtkWidget *dialog; | ||
|
||
GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT; | ||
dialog = gtk_message_dialog_new(NULL, flags, GTK_MESSAGE_INFO, | ||
GTK_BUTTONS_CLOSE, user_data); | ||
gtk_dialog_run(GTK_DIALOG(dialog)); | ||
gtk_widget_destroy(dialog); | ||
} | ||
|
||
void revery_alert_gtk(void *pWin, const char *szMessage) { | ||
/* | ||
* TODO: | ||
* 1. figure out how to convert the pointer from an X11 window handle | ||
* to a GTK window, see (for inspiration): | ||
* https://gist.github.com/mmozeiko/2401933b1fa89e5d5bd238b33eab0465 | ||
* | ||
* 2. Get reference to revery application, is there an existing | ||
* gtk application reference when a glfw window is created that can be reused? | ||
*/ | ||
GtkApplication *app; | ||
app = gtk_application_new("org.gtk.revery", G_APPLICATION_FLAGS_NONE); | ||
g_signal_connect(app, "activate", G_CALLBACK(activate), (gpointer)szMessage); | ||
/* argv the final argument to run can be set to NULL in which case argc should | ||
* be set to 0 */ | ||
g_application_run(G_APPLICATION(app), 0, NULL); | ||
g_object_unref(app); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters