[GTK3] Use Ctrl+C to break into the debugger in developer mode

This commit is contained in:
Maximilian Mader 2021-01-02 22:53:58 +01:00
parent e46d87257c
commit d365f44fec
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
3 changed files with 26 additions and 3 deletions

View File

@ -513,7 +513,9 @@ void console_clear(ConsoleWindow *self) {
gtk_widget_queue_draw(GTK_WIDGET(self));
}
void break_debugger(ConsoleWindow *self) {
void break_debugger(ConsoleWindow *self, bool forced) {
if (!forced && !self->developer_mode) return;
GB_debugger_break(self->gb);
focus(self);
}

View File

@ -12,7 +12,7 @@ char *console_get_async_input(ConsoleWindow *self, GB_gameboy_t *gb);
char *console_get_sync_input(ConsoleWindow *self, GB_gameboy_t *gb);
void console_log(ConsoleWindow *self, const char *message, GB_log_attributes attributes);
void console_clear(ConsoleWindow *self);
void break_debugger(ConsoleWindow *self);
void break_debugger(ConsoleWindow *self, bool forced);
void abort_debugger(ConsoleWindow *self);
void set_developer_mode(ConsoleWindow *self, bool value);
#endif

View File

@ -1075,6 +1075,10 @@ static void startup(GApplication *app, gpointer null_ptr) {
gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
G_MODULE_EXPORT void break_debugger_keyboard(GtkWidget *w, gpointer user_data_ptr) {
break_debugger(gui_data.console, false);
}
G_MODULE_EXPORT void on_quit_activate(GtkWidget *w, gpointer user_data_ptr) {
quit();
}
@ -1158,6 +1162,18 @@ void on_preferences_notify_interference_volume(PreferencesWindow *pref, const gu
}
static void connect_signal_handlers(GApplication *app) {
g_signal_new(
"break-debugger-keyboard", // signal name
G_TYPE_FROM_INSTANCE(gui_data.main_window), // itype
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_ACTION, // signal_flags
0, // class_offset
NULL, // accumulator
NULL, // accumulator_data
NULL, // c_marshaller,
G_TYPE_NONE, // return_type
0 // n_params
);
// Connect signal handlers
gtk_widget_add_events(GTK_WIDGET(gui_data.main_window), GDK_KEY_PRESS_MASK);
gtk_widget_add_events(GTK_WIDGET(gui_data.main_window), GDK_KEY_RELEASE_MASK);
@ -1166,6 +1182,7 @@ static void connect_signal_handlers(GApplication *app) {
g_signal_connect(gui_data.main_window, "key-press-event", G_CALLBACK(on_key_press), NULL);
g_signal_connect(gui_data.main_window, "key-release-event", G_CALLBACK(on_key_press), NULL);
g_signal_connect(gui_data.main_window, "window-state-event", G_CALLBACK(on_window_state_change), NULL);
g_signal_connect(gui_data.main_window, "break-debugger-keyboard", G_CALLBACK(break_debugger_keyboard), NULL);
// Just hide our sub-windows when closing them
g_signal_connect(gui_data.preferences, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
@ -1192,6 +1209,10 @@ static void activate(GApplication *app, gpointer null_ptr) {
gtk_window_fullscreen(GTK_WINDOW(gui_data.main_window));
}
GtkAccelGroup *accelGroup = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(gui_data.main_window), accelGroup);
gtk_widget_add_accelerator(GTK_WIDGET(gui_data.main_window), "break-debugger-keyboard", accelGroup, GDK_KEY_C, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW(gui_data.main_window));
gtk_widget_show_all(GTK_WIDGET(gui_data.main_window));
@ -1271,7 +1292,7 @@ static void activate_clear_console(GSimpleAction *action, GVariant *parameter, g
// app.break_debugger GAction
// Clears the debugger console
static void activate_break_debugger(GSimpleAction *action, GVariant *parameter, gpointer app) {
break_debugger(gui_data.console);
break_debugger(gui_data.console, true);
}
// Closes a ROM