Skip to content

Commit

Permalink
Gtk: Thread preferences creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
bearoso committed Aug 23, 2020
1 parent a3c0c46 commit 95c7fda
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
19 changes: 14 additions & 5 deletions gtk/src/gtk_preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@

#define SAME_AS_GAME _("Same location as current game")

void snes9x_preferences_open(Snes9xWindow *window, Snes9xConfig *config)
static Snes9xPreferences *preferences = nullptr;

void snes9x_preferences_create(Snes9xConfig *config)
{
static Snes9xPreferences *preferences = nullptr;
Glib::Thread::create([config] {
Snes9xPreferences *new_preferences;
new_preferences = new Snes9xPreferences(config);
preferences = new_preferences;
}, true);
}

void snes9x_preferences_open(Snes9xWindow *window)
{
if (!preferences)
{
preferences = new Snes9xPreferences(config);
}
return;

auto &config = preferences->config;

window->pause_from_focus_change ();

Expand Down
3 changes: 2 additions & 1 deletion gtk/src/gtk_preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#include "gtk_s9x.h"
#include "gtk_builder_window.h"

void snes9x_preferences_open(Snes9xWindow *window, Snes9xConfig *config);
void snes9x_preferences_create(Snes9xConfig *config);
void snes9x_preferences_open(Snes9xWindow *window);

class Snes9xPreferences : public GtkBuilderWindow
{
Expand Down
5 changes: 3 additions & 2 deletions gtk/src/gtk_s9xwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Snes9xWindow::Snes9xWindow(Snes9xConfig *config)
cairo_owned = false;
mouse_grabbed = false;

snes9x_preferences_create(config);

if (Gtk::IconTheme::get_default()->has_icon("snes9x"))
{
window->set_default_icon_name("snes9x");
Expand All @@ -86,7 +88,6 @@ Snes9xWindow::Snes9xWindow(Snes9xConfig *config)
{
auto loader = Gdk::PixbufLoader::create();
loader->write((const guint8 *)app_icon, sizeof(app_icon));
loader->close();
window->set_default_icon(loader->get_pixbuf());
}

Expand Down Expand Up @@ -244,7 +245,7 @@ void Snes9xWindow::connect_signals()
});

get_object<Gtk::MenuItem>("preferences_item")->signal_activate().connect([&] {
snes9x_preferences_open(this, config);
snes9x_preferences_open(this);
});

get_object<Gtk::MenuItem>("open_netplay_item")->signal_activate().connect([&] {
Expand Down

0 comments on commit 95c7fda

Please sign in to comment.