[GTK3] Open console window when logging messages in developer mode

This commit is contained in:
Maximilian Mader 2021-01-02 19:11:36 +01:00
parent a56a97d657
commit e46d87257c
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
4 changed files with 57 additions and 4 deletions

View File

@ -30,6 +30,8 @@ struct _ConsoleWindow {
uintptr_t auto_complete_context; uintptr_t auto_complete_context;
bool ignore_auto_complete_context_reset; bool ignore_auto_complete_context_reset;
bool developer_mode;
GB_gameboy_t *gb; GB_gameboy_t *gb;
}; };
@ -479,10 +481,19 @@ char *console_get_sync_input(ConsoleWindow *self, GB_gameboy_t *gb) {
return command; 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 // Queues a message to be logged to the console
void console_log(ConsoleWindow *self, const char *message, GB_log_attributes attributes) { void console_log(ConsoleWindow *self, const char *message, GB_log_attributes attributes) {
if (!message || g_str_equal("", message)) return; if (!message || g_str_equal("", message)) return;
if (self->developer_mode) {
focus(self);
}
AttributedMessage *attr_msg = g_new(AttributedMessage, 1); AttributedMessage *attr_msg = g_new(AttributedMessage, 1);
attr_msg->message = g_strdup(message); attr_msg->message = g_strdup(message);
attr_msg->attributes = attributes; attr_msg->attributes = attributes;
@ -504,8 +515,7 @@ void console_clear(ConsoleWindow *self) {
void break_debugger(ConsoleWindow *self) { void break_debugger(ConsoleWindow *self) {
GB_debugger_break(self->gb); GB_debugger_break(self->gb);
gtk_window_present_with_time(GTK_WINDOW(self), time(NULL)); focus(self);
gtk_widget_grab_focus(GTK_WIDGET(self->input));
} }
// Hack to avoid deadlocking on queue reads ... // 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")); g_async_queue_push(self->output_queue, g_strdup("c\0"));
console_clear(self); console_clear(self);
} }
void set_developer_mode(ConsoleWindow *self, bool value) {
self->developer_mode = value;
}

View File

@ -14,4 +14,5 @@ void console_log(ConsoleWindow *self, const char *message, GB_log_attributes att
void console_clear(ConsoleWindow *self); void console_clear(ConsoleWindow *self);
void break_debugger(ConsoleWindow *self); void break_debugger(ConsoleWindow *self);
void abort_debugger(ConsoleWindow *self); void abort_debugger(ConsoleWindow *self);
void set_developer_mode(ConsoleWindow *self, bool value);
#endif #endif

View File

@ -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_about(GSimpleAction *action, GVariant *parameter, gpointer app);
static void activate_preferences(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_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 void on_mute_changed(GSimpleAction *action, GVariant *value, gpointer user_data_ptr);
static const GActionEntry file_entries[] = { 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_memory_viewer", activate_open_memory_viewer, NULL, NULL, NULL },
{ "open_vram_viewer", activate_open_vram_viewer, NULL, NULL, NULL }, { "open_vram_viewer", activate_open_vram_viewer, NULL, NULL, NULL },
{ "break_debugger", activate_break_debugger, 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 }, { "clear_console", activate_clear_console, NULL, NULL, NULL },
{ "open_gtk_debugger", activate_open_gtk_debugger, 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); 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) { 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) { static void init(void) {
@ -1309,6 +1327,11 @@ static void activate_quit(GSimpleAction *action, GVariant *parameter, gpointer a
quit(); 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) { static void on_mute_changed(GSimpleAction *action, GVariant *value, gpointer user_data_ptr) {
config.audio.muted = g_variant_get_boolean(value); config.audio.muted = g_variant_get_boolean(value);

View File

@ -389,6 +389,21 @@ Maximilian Mader https://github.com/max-m</property>
<object class="GtkMenu"> <object class="GtkMenu">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action_name">app.toggle_developer_mode</property>
<property name="label" translatable="yes">Developer Mode</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child> <child>
<object class="GtkMenuItem"> <object class="GtkMenuItem">
<property name="visible">True</property> <property name="visible">True</property>