diff --git a/base/sources/backends/linux_system.c b/base/sources/backends/linux_system.c index cc8df42f..62b6ce34 100644 --- a/base/sources/backends/linux_system.c +++ b/base/sources/backends/linux_system.c @@ -1322,3 +1322,40 @@ bool iron_gamepad_connected(int gamepad) { void iron_gamepad_rumble(int gamepad, float left, float right) {} #endif + +#ifdef WITH_NFD // Has gtk +#include +extern void (*iron_save_and_quit)(bool); + +bool _save_and_quit_callback_internal() { + bool save = false; + XTextProperty text_prop; + XGetTextProperty(x11_ctx.display, x11_ctx.windows[0].window, &text_prop, NET_WM_NAME); + char *title = (char *)text_prop.value; + bool dirty = strstr(title, "* - ArmorPaint") != NULL; + // XFree(title); + if (dirty) { + gtk_init(NULL, NULL); + GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO, "Project has been modified, save changes?"); + gtk_window_set_title(GTK_WINDOW(dialog), "Save Changes?"); + gtk_widget_realize(dialog); + gint res = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + while (g_main_context_pending(NULL)) { + g_main_context_iteration(NULL, FALSE); + } + if (res == GTK_RESPONSE_YES) { + save = true; + } + else if (res == GTK_RESPONSE_NO) { + save = false; + } + else { + return false; + } + } + iron_save_and_quit(save); + return false; +} + +#endif diff --git a/base/sources/iron.h b/base/sources/iron.h index 51a29de8..80a4b421 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -185,7 +185,6 @@ void _kickstart(); bool enable_window = true; bool in_background = false; int paused_frames = 0; -bool save_and_quit_callback_set = false; #ifdef IDLE_SLEEP bool input_down = false; int last_window_width = 0; @@ -1405,7 +1404,11 @@ void iron_file_download(string_t *url, void (*callback)(char *, buffer_t *), i32 iron_https_request(url_base, url_path, NULL, 443, 0, &_https_callback, cbd); } -bool _window_close_callback(void *data) { +#ifdef IRON_LINUX +bool _save_and_quit_callback_internal(); +#endif + +bool _save_and_quit_callback(void *data) { #ifdef IRON_WINDOWS bool save = false; wchar_t title[1024]; @@ -1423,18 +1426,21 @@ bool _window_close_callback(void *data) { return false; } } - if (save_and_quit_callback_set) { - iron_save_and_quit(save); - return false; - } + iron_save_and_quit(save); + return false; #endif + + #if defined(IRON_LINUX) && defined(WITH_NFD) // Has gtk + _save_and_quit_callback_internal(); + return false; + #endif + return true; } void iron_set_save_and_quit_callback(void (*callback)(bool)) { iron_save_and_quit = callback; - save_and_quit_callback_set = true; - iron_window_set_close_callback(_window_close_callback, NULL); + iron_window_set_close_callback(_save_and_quit_callback, NULL); } void iron_delay_idle_sleep() {