mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-25 22:01:13 +02:00
Update to 20180724 release.
byuu says: I failed to complete a WIP, have five of eight cores updated with some major changes to Emulator::Interface. I'll just post a quick temporary WIP in the off chance someone wants to look over the new interface and comment on it. Also implemented screen saver suppression into hiro/GTK. I should also add ... a plan of mine is to develop target-bsnes into a more generic user interface, with the general idea being that target-higan is for multiple Emulator::Interface cores at the same time, and target-bsnes is for just one Emulator::Interface core. The idea being that if one were to compile target-bsnes with the GBA core, it'd become bgba, for instance. I don't plan on releasing single-core emulators like this, but ... I don't see any downsides to being more flexible.
This commit is contained in:
@@ -6,6 +6,7 @@ vector<pWindow*> pApplication::windows;
|
||||
|
||||
#if defined(DISPLAY_XORG)
|
||||
XlibDisplay* pApplication::display = nullptr;
|
||||
bool pApplication::xdgScreenSaver = false;
|
||||
#endif
|
||||
|
||||
auto pApplication::run() -> void {
|
||||
@@ -29,16 +30,21 @@ auto pApplication::quit() -> void {
|
||||
if(gtk_main_level()) gtk_main_quit();
|
||||
|
||||
#if defined(DISPLAY_XORG)
|
||||
//TODO: Keyboard::poll() is being called after Application::quit();
|
||||
//so if display is closed; this causes a segfault
|
||||
//XCloseDisplay(display);
|
||||
//display = nullptr;
|
||||
XCloseDisplay(display);
|
||||
display = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
auto pApplication::setScreenSaver(bool screenSaver) -> void {
|
||||
#if defined(DISPLAY_XORG)
|
||||
for(auto& window : windows) window->_setScreenSaver(screenSaver);
|
||||
#endif
|
||||
}
|
||||
|
||||
auto pApplication::initialize() -> void {
|
||||
#if defined(DISPLAY_XORG)
|
||||
display = XOpenDisplay(nullptr);
|
||||
xdgScreenSaver = (bool)execute("xdg-screensaver", "--version").output.find("xdg-screensaver");
|
||||
#endif
|
||||
|
||||
//set WM_CLASS to Application::name()
|
||||
|
@@ -7,6 +7,7 @@ struct pApplication {
|
||||
static auto pendingEvents() -> bool;
|
||||
static auto processEvents() -> void;
|
||||
static auto quit() -> void;
|
||||
static auto setScreenSaver(bool screenSaver) -> void;
|
||||
|
||||
static auto initialize() -> void;
|
||||
|
||||
@@ -14,6 +15,7 @@ struct pApplication {
|
||||
|
||||
#if defined(DISPLAY_XORG)
|
||||
static XlibDisplay* display;
|
||||
static bool xdgScreenSaver;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@@ -3,6 +3,8 @@
|
||||
namespace hiro {
|
||||
|
||||
auto pKeyboard::poll() -> vector<bool> {
|
||||
if(Application::state.quit) return {};
|
||||
|
||||
vector<bool> result;
|
||||
char state[256];
|
||||
#if defined(DISPLAY_XORG)
|
||||
|
@@ -79,14 +79,16 @@ auto pViewport::destruct() -> void {
|
||||
gtkParent = nullptr;
|
||||
}
|
||||
|
||||
auto pViewport::handle() const -> uintptr_t {
|
||||
auto pViewport::handle() const -> uintptr {
|
||||
#if defined(DISPLAY_WINDOWS)
|
||||
return (uintptr_t)GDK_WINDOW_HWND(gtk_widget_get_window(gtkWidget));
|
||||
return (uintptr)GDK_WINDOW_HWND(gtk_widget_get_window(gtkWidget));
|
||||
#endif
|
||||
|
||||
#if defined(DISPLAY_XORG)
|
||||
return GDK_WINDOW_XID(gtk_widget_get_window(gtkWidget));
|
||||
#endif
|
||||
|
||||
return (uintptr)nullptr;
|
||||
}
|
||||
|
||||
auto pViewport::setDroppable(bool droppable) -> void {
|
||||
|
@@ -5,7 +5,7 @@ namespace hiro {
|
||||
struct pViewport : pWidget {
|
||||
Declare(Viewport, Widget)
|
||||
|
||||
auto handle() const -> uintptr_t;
|
||||
auto handle() const -> uintptr;
|
||||
auto setDroppable(bool droppable) -> void;
|
||||
};
|
||||
|
||||
|
@@ -99,6 +99,10 @@ static auto Window_keyRelease(GtkWidget* widget, GdkEventKey* event, pWindow* p)
|
||||
return false;
|
||||
}
|
||||
|
||||
static auto Window_realize(GtkWidget* widget, pWindow* p) -> void {
|
||||
p->_setScreenSaver(Application::screenSaver());
|
||||
}
|
||||
|
||||
static auto Window_sizeAllocate(GtkWidget* widget, GtkAllocation* allocation, pWindow* p) -> void {
|
||||
p->_synchronizeState();
|
||||
p->_synchronizeGeometry();
|
||||
@@ -125,6 +129,10 @@ static auto Window_stateEvent(GtkWidget* widget, GdkEvent* event, pWindow* p) ->
|
||||
}
|
||||
}
|
||||
|
||||
static auto Window_unrealize(GtkWidget* widget, pWindow* p) -> void {
|
||||
p->_setScreenSaver(true);
|
||||
}
|
||||
|
||||
auto pWindow::construct() -> void {
|
||||
widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_resizable(GTK_WINDOW(widget), true);
|
||||
@@ -186,6 +194,7 @@ auto pWindow::construct() -> void {
|
||||
g_signal_connect(G_OBJECT(widget), "drag-data-received", G_CALLBACK(Window_drop), (gpointer)this);
|
||||
g_signal_connect(G_OBJECT(widget), "key-press-event", G_CALLBACK(Window_keyPress), (gpointer)this);
|
||||
g_signal_connect(G_OBJECT(widget), "key-release-event", G_CALLBACK(Window_keyRelease), (gpointer)this);
|
||||
g_signal_connect(G_OBJECT(widget), "realize", G_CALLBACK(Window_realize), (gpointer)this);
|
||||
g_signal_connect(G_OBJECT(formContainer), "size-allocate", G_CALLBACK(Window_sizeAllocate), (gpointer)this);
|
||||
#if HIRO_GTK==2
|
||||
g_signal_connect(G_OBJECT(formContainer), "size-request", G_CALLBACK(Window_sizeRequest), (gpointer)this);
|
||||
@@ -194,6 +203,7 @@ auto pWindow::construct() -> void {
|
||||
widgetClass->get_preferred_width = Window_getPreferredWidth;
|
||||
widgetClass->get_preferred_height = Window_getPreferredHeight;
|
||||
#endif
|
||||
g_signal_connect(G_OBJECT(widget), "unrealize", G_CALLBACK(Window_unrealize), (gpointer)this);
|
||||
g_signal_connect(G_OBJECT(widget), "window-state-event", G_CALLBACK(Window_stateEvent), (gpointer)this);
|
||||
|
||||
g_object_set_data(G_OBJECT(widget), "hiro::window", (gpointer)this);
|
||||
@@ -247,6 +257,18 @@ auto pWindow::frameMargin() const -> Geometry {
|
||||
};
|
||||
}
|
||||
|
||||
auto pWindow::handle() const -> uintptr {
|
||||
#if defined(DISPLAY_WINDOWS)
|
||||
return (uintptr)GDK_WINDOW_HWND(gtk_widget_get_window(widget));
|
||||
#endif
|
||||
|
||||
#if defined(DISPLAY_XORG)
|
||||
return GDK_WINDOW_XID(gtk_widget_get_window(widget));
|
||||
#endif
|
||||
|
||||
return (uintptr)nullptr;
|
||||
}
|
||||
|
||||
auto pWindow::remove(sMenuBar menuBar) -> void {
|
||||
_setMenuVisible(false);
|
||||
}
|
||||
@@ -458,6 +480,19 @@ auto pWindow::_setMenuVisible(bool visible) -> void {
|
||||
gtk_widget_set_visible(gtkMenu, visible);
|
||||
}
|
||||
|
||||
auto pWindow::_setScreenSaver(bool screenSaver) -> void {
|
||||
if(!gtk_widget_get_realized(widget)) return;
|
||||
|
||||
#if defined(DISPLAY_XORG)
|
||||
if(pApplication::xdgScreenSaver) {
|
||||
if(this->screenSaver != screenSaver) {
|
||||
this->screenSaver = screenSaver;
|
||||
execute("xdg-screensaver", screenSaver ? "resume" : "suspend", string{"0x", hex(handle())});
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
auto pWindow::_setStatusEnabled(bool enabled) -> void {
|
||||
gtk_widget_set_sensitive(gtkStatus, enabled);
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ struct pWindow : pObject {
|
||||
auto append(sStatusBar statusBar) -> void;
|
||||
auto focused() const -> bool override;
|
||||
auto frameMargin() const -> Geometry;
|
||||
auto handle() const -> uintptr;
|
||||
auto remove(sMenuBar menuBar) -> void;
|
||||
auto remove(sSizable sizable) -> void;
|
||||
auto remove(sStatusBar statusBar) -> void;
|
||||
@@ -33,6 +34,7 @@ struct pWindow : pObject {
|
||||
auto _append(mMenu& menu) -> void;
|
||||
auto _menuHeight() const -> int;
|
||||
auto _menuTextHeight() const -> int;
|
||||
auto _setScreenSaver(bool screenSaver) -> void;
|
||||
auto _setIcon(const string& basename) -> bool;
|
||||
auto _setMenuEnabled(bool enabled) -> void;
|
||||
auto _setMenuFont(const Font& font) -> void;
|
||||
@@ -55,6 +57,7 @@ struct pWindow : pObject {
|
||||
GtkWidget* gtkStatus = nullptr;
|
||||
GtkAllocation lastMove = {0};
|
||||
GtkAllocation lastSize = {0};
|
||||
bool screenSaver = true;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user