[GTK3] Stop the emulation when quitting
This commit is contained in:
parent
b1be15377c
commit
9044189a95
46
gtk3/main.c
46
gtk3/main.c
@ -22,6 +22,7 @@ typedef struct{
|
|||||||
|
|
||||||
static void run(UserData *user_data);
|
static void run(UserData *user_data);
|
||||||
|
|
||||||
|
GtkApplication *main_application;
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GtkApplicationWindow *main_window;
|
GtkApplicationWindow *main_window;
|
||||||
GtkGLArea *gl_area;
|
GtkGLArea *gl_area;
|
||||||
@ -37,6 +38,8 @@ static double clock_mutliplier = 1.0;
|
|||||||
static char *battery_save_path_ptr;
|
static char *battery_save_path_ptr;
|
||||||
static Rect rect;
|
static Rect rect;
|
||||||
|
|
||||||
|
static bool running = true;
|
||||||
|
|
||||||
unsigned char number_of_buffers(void) {
|
unsigned char number_of_buffers(void) {
|
||||||
bool should_blend = true;
|
bool should_blend = true;
|
||||||
|
|
||||||
@ -168,10 +171,15 @@ static GMenuModel *get_menu_model(GApplication *app, const char *id) {
|
|||||||
return menu ? G_MENU_MODEL(g_object_ref_sink(menu)) : NULL;
|
return menu ? G_MENU_MODEL(g_object_ref_sink(menu)) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void quit(GApplication *app) {
|
||||||
|
g_application_quit(app);
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
|
||||||
// app.quit GAction
|
// app.quit GAction
|
||||||
// Exits the application
|
// Exits the application
|
||||||
static void activate_quit(GSimpleAction *action, GVariant *parameter, gpointer user_data) {
|
static void activate_quit(GSimpleAction *action, GVariant *parameter, gpointer user_data) {
|
||||||
g_application_quit(G_APPLICATION(user_data));
|
quit(G_APPLICATION(user_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
// app.about GAction
|
// app.about GAction
|
||||||
@ -188,6 +196,10 @@ static GActionEntry app_entries[] = {
|
|||||||
{ "about", activate_about, NULL, NULL, NULL },
|
{ "about", activate_about, NULL, NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
G_MODULE_EXPORT void on_quit(GtkWidget *w, gpointer app) {
|
||||||
|
quit(G_APPLICATION(app));
|
||||||
|
}
|
||||||
|
|
||||||
G_MODULE_EXPORT void on_show_window(GtkWidget *w, gpointer window) {
|
G_MODULE_EXPORT void on_show_window(GtkWidget *w, gpointer window) {
|
||||||
gtk_widget_show_all(GTK_WIDGET(window));
|
gtk_widget_show_all(GTK_WIDGET(window));
|
||||||
}
|
}
|
||||||
@ -311,10 +323,13 @@ static void activate(GApplication *app, gpointer user_data_gptr) {
|
|||||||
gtk_window_fullscreen(GTK_WINDOW(main_window));
|
gtk_window_fullscreen(GTK_WINDOW(main_window));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_connect(main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
g_signal_connect(main_window, "destroy", G_CALLBACK(on_quit), app);
|
||||||
|
|
||||||
gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW(main_window));
|
gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW(main_window));
|
||||||
gtk_widget_show_all(GTK_WIDGET(main_window));
|
gtk_widget_show_all(GTK_WIDGET(main_window));
|
||||||
|
|
||||||
|
// Start the emulation loop.
|
||||||
|
// This loop takes care of the GTK main loop.
|
||||||
run(user_data);
|
run(user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,6 +350,10 @@ static void open(GApplication *app, GFile **files, gint n_files, const gchar *hi
|
|||||||
activate(app, user_data_gptr);
|
activate(app, user_data_gptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void shutdown(GApplication *app, GFile **files, gint n_files, const gchar *hint, gpointer user_data_gptr) {
|
||||||
|
g_print("SHUTDOWN\n");
|
||||||
|
}
|
||||||
|
|
||||||
// This function gets called after the parsing of the commandline options has occurred.
|
// This function gets called after the parsing of the commandline options has occurred.
|
||||||
static gint handle_local_options(GApplication *app, GVariantDict *options, gpointer user_data_gptr) {
|
static gint handle_local_options(GApplication *app, GVariantDict *options, gpointer user_data_gptr) {
|
||||||
UserData *user_data = user_data_gptr;
|
UserData *user_data = user_data_gptr;
|
||||||
@ -432,7 +451,7 @@ static void run(UserData *user_data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Run emulation */
|
/* Run emulation */
|
||||||
while (true) {
|
while (running) {
|
||||||
if (paused || rewind_paused) {
|
if (paused || rewind_paused) {
|
||||||
while (gtk_events_pending()) {
|
while (gtk_events_pending()) {
|
||||||
gtk_main_iteration();
|
gtk_main_iteration();
|
||||||
@ -456,7 +475,7 @@ static void run(UserData *user_data) {
|
|||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
// Create our GApplication and tell GTK that we are able to handle files
|
// Create our GApplication and tell GTK that we are able to handle files
|
||||||
GtkApplication *app = gtk_application_new(APP_ID, G_APPLICATION_HANDLES_OPEN);
|
main_application = gtk_application_new(APP_ID, G_APPLICATION_HANDLES_OPEN);
|
||||||
|
|
||||||
UserData user_data = { NULL };
|
UserData user_data = { NULL };
|
||||||
|
|
||||||
@ -467,23 +486,24 @@ int main(int argc, char *argv[]) {
|
|||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
// Setup our command line information
|
// Setup our command line information
|
||||||
g_application_add_main_option_entries(G_APPLICATION(app), entries);
|
g_application_add_main_option_entries(G_APPLICATION(main_application), entries);
|
||||||
g_application_set_option_context_parameter_string(G_APPLICATION(app), "[FILE…]");
|
g_application_set_option_context_parameter_string(G_APPLICATION(main_application), "[FILE…]");
|
||||||
g_application_set_option_context_summary(G_APPLICATION(app), "SameBoy is an open source Game Boy (DMG) and Game Boy Color (CGB) emulator.");
|
g_application_set_option_context_summary(G_APPLICATION(main_application), "SameBoy is an open source Game Boy (DMG) and Game Boy Color (CGB) emulator.");
|
||||||
|
|
||||||
// Add signal handlers
|
// Add signal handlers
|
||||||
g_signal_connect(app, "handle-local-options", G_CALLBACK(handle_local_options), &user_data);
|
g_signal_connect(main_application, "handle-local-options", G_CALLBACK(handle_local_options), &user_data);
|
||||||
g_signal_connect(app, "startup", G_CALLBACK(startup), &user_data);
|
g_signal_connect(main_application, "startup", G_CALLBACK(startup), &user_data);
|
||||||
g_signal_connect(app, "activate", G_CALLBACK(activate), &user_data);
|
g_signal_connect(main_application, "activate", G_CALLBACK(activate), &user_data);
|
||||||
g_signal_connect(app, "open", G_CALLBACK(open), &user_data);
|
g_signal_connect(main_application, "open", G_CALLBACK(open), &user_data);
|
||||||
|
g_signal_connect(main_application, "shutdown", G_CALLBACK(shutdown), &user_data);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
//gtk_window_set_interactive_debugging(true);
|
//gtk_window_set_interactive_debugging(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Start our GApplication main loop
|
// Start our GApplication main loop
|
||||||
int status = g_application_run(G_APPLICATION(app), argc, argv);
|
int status = g_application_run(G_APPLICATION(main_application), argc, argv);
|
||||||
g_object_unref(app);
|
g_object_unref(main_application);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user