diff --git a/gtk3/console_window.c b/gtk3/console_window.c index a36cfc4..746b676 100644 --- a/gtk3/console_window.c +++ b/gtk3/console_window.c @@ -30,6 +30,8 @@ struct _ConsoleWindow { uintptr_t auto_complete_context; bool ignore_auto_complete_context_reset; + bool developer_mode; + GB_gameboy_t *gb; }; @@ -479,10 +481,19 @@ char *console_get_sync_input(ConsoleWindow *self, GB_gameboy_t *gb) { return command; } +void focus(ConsoleWindow *self) { + gtk_window_present_with_time(GTK_WINDOW(self), time(NULL)); + gtk_widget_grab_focus(GTK_WIDGET(self->input)); +} + // Queues a message to be logged to the console void console_log(ConsoleWindow *self, const char *message, GB_log_attributes attributes) { if (!message || g_str_equal("", message)) return; + if (self->developer_mode) { + focus(self); + } + AttributedMessage *attr_msg = g_new(AttributedMessage, 1); attr_msg->message = g_strdup(message); attr_msg->attributes = attributes; @@ -504,8 +515,7 @@ void console_clear(ConsoleWindow *self) { void break_debugger(ConsoleWindow *self) { GB_debugger_break(self->gb); - gtk_window_present_with_time(GTK_WINDOW(self), time(NULL)); - gtk_widget_grab_focus(GTK_WIDGET(self->input)); + focus(self); } // Hack to avoid deadlocking on queue reads ... @@ -514,3 +524,7 @@ void abort_debugger(ConsoleWindow *self) { g_async_queue_push(self->output_queue, g_strdup("c\0")); console_clear(self); } + +void set_developer_mode(ConsoleWindow *self, bool value) { + self->developer_mode = value; +} diff --git a/gtk3/console_window.h b/gtk3/console_window.h index 386269b..0dd25f8 100644 --- a/gtk3/console_window.h +++ b/gtk3/console_window.h @@ -14,4 +14,5 @@ void console_log(ConsoleWindow *self, const char *message, GB_log_attributes att void console_clear(ConsoleWindow *self); void break_debugger(ConsoleWindow *self); void abort_debugger(ConsoleWindow *self); +void set_developer_mode(ConsoleWindow *self, bool value); #endif \ No newline at end of file diff --git a/gtk3/main.c b/gtk3/main.c index 78a4da1..51dfef5 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -80,6 +80,7 @@ static void activate_quit(GSimpleAction *action, GVariant *parameter, gpointer a static void activate_about(GSimpleAction *action, GVariant *parameter, gpointer app); static void activate_preferences(GSimpleAction *action, GVariant *parameter, gpointer app); static void on_pause_changed(GSimpleAction *action, GVariant *value, gpointer user_data_ptr); +static void on_developer_mode_changed(GSimpleAction *action, GVariant *value, gpointer user_data_ptr); static void on_mute_changed(GSimpleAction *action, GVariant *value, gpointer user_data_ptr); static const GActionEntry file_entries[] = { @@ -103,7 +104,7 @@ static const GActionEntry developer_entries[] = { // { "open_memory_viewer", activate_open_memory_viewer, NULL, NULL, NULL }, { "open_vram_viewer", activate_open_vram_viewer, NULL, NULL, NULL }, { "break_debugger", activate_break_debugger, NULL, NULL, NULL }, - { "toggle_developer_mode", NULL, NULL, "false", NULL }, + { "toggle_developer_mode", NULL, NULL, "false", on_developer_mode_changed }, { "clear_console", activate_clear_console, NULL, NULL, NULL }, { "open_gtk_debugger", activate_open_gtk_debugger, NULL, NULL, NULL }, }; @@ -682,8 +683,25 @@ static char *wrapped_console_get_sync_input(GB_gameboy_t *gb) { return console_get_sync_input(gui_data.console, gb); } +struct ConsoleLogData { + const char *message; + GB_log_attributes attributes; +}; + +static bool main_thread_console_log(gpointer data) { + struct ConsoleLogData *args = data; + console_log(gui_data.console, args->message, args->attributes); + g_slice_free(struct ConsoleLogData, args); + + return false; +} + static void wrapped_console_log(GB_gameboy_t *gb, const char *message, GB_log_attributes attributes) { - console_log(gui_data.console, message, attributes); + struct ConsoleLogData *data = g_slice_alloc(sizeof(struct ConsoleLogData)); + data->message = g_strdup(message); + data->attributes = attributes; + + g_idle_add((GSourceFunc) main_thread_console_log, data); } static void init(void) { @@ -1309,6 +1327,11 @@ static void activate_quit(GSimpleAction *action, GVariant *parameter, gpointer a quit(); } +static void on_developer_mode_changed(GSimpleAction *action, GVariant *value, gpointer user_data_ptr) { + set_developer_mode(gui_data.console, g_variant_get_boolean(value)); + g_simple_action_set_state(action, value); +} + static void on_mute_changed(GSimpleAction *action, GVariant *value, gpointer user_data_ptr) { config.audio.muted = g_variant_get_boolean(value); diff --git a/gtk3/resources/ui/window.ui b/gtk3/resources/ui/window.ui index aae98ff..63fe238 100644 --- a/gtk3/resources/ui/window.ui +++ b/gtk3/resources/ui/window.ui @@ -389,6 +389,21 @@ Maximilian Mader https://github.com/max-m True False + + + True + False + app.toggle_developer_mode + Developer Mode + True + + + + + True + False + + True