[GTK3] Open console window when logging messages in developer mode
This commit is contained in:
parent
a56a97d657
commit
e46d87257c
@ -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;
|
||||
}
|
||||
|
@ -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
|
27
gtk3/main.c
27
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);
|
||||
|
||||
|
@ -389,6 +389,21 @@ Maximilian Mader https://github.com/max-m</property>
|
||||
<object class="GtkMenu">
|
||||
<property name="visible">True</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>
|
||||
<object class="GtkMenuItem">
|
||||
<property name="visible">True</property>
|
||||
|
Loading…
Reference in New Issue
Block a user