bsnes/hiro/qt/application.cpp

119 lines
3.5 KiB
C++
Raw Normal View History

#if defined(Hiro_Application)
namespace hiro {
auto pApplication::exit() -> void {
quit();
::exit(EXIT_SUCCESS);
}
Update to 20180809 release. byuu says: The Windows port can now run the emulation while navigating menus, moving windows, and resizing windows. The main window also doesn't try so hard to constantly clear itself. This may leave a bit of unwelcome residue behind in some video drivers during resize, but under most drivers, it lets you resize without a huge amount of flickering. On all platforms, I now also run the emulation during MessageWindow modal events, where I didn't before. I'm thinking we should probably mute the audio during modal periods, since it can generate a good deal of distortion. The tooltip timeout was increased to ten seconds. On Windows, the enter key can now activate buttons, so you can more quickly dismiss MessageDialog windows. This part may not actually work ... I'm in the middle of trying to get messages out of the global `Application_windowProc` hook and into the individual `Widget_windowProc` hooks, so I need to do some testing. I fixed a bug where changing the input driver wouldn't immediately reload the input/hotkey settings lists properly. I also went from disabling the driver "Change" button when the currently active driver is selected in the list, to instead setting it to say "Reload", and I also added a tool tip to the input driver reload button, advising that if you're using DirectInput or SDL, you can hit "Reload" to rescan for hotplugged gamepads without needing to restart the emulator. XInput and udev have auto hotswap support. If we can ever get that into DirectInput and SDL, then I'll remove the tooltip. But regardless, the reload functionality is nice to have for all drivers. I'm not sure what should happen when a user changes their driver selection while a game is loaded, gets the warning dialog, chooses not to change it, and then closes the emulator. Currently, it will make the change happen the next time you start the emulator. This feels a bit unexpected, but when you change the selection without a game loaded, it takes immediate effect. So I'm not really sure what's best here.
2018-08-10 05:02:59 +00:00
auto pApplication::modal() -> bool {
return Application::state().modal > 0;
}
auto pApplication::run() -> void {
if(Application::state().onMain) {
while(!Application::state().quit) {
Application::doMain();
processEvents();
}
} else {
QApplication::exec();
}
}
auto pApplication::pendingEvents() -> bool {
return QApplication::hasPendingEvents();
}
auto pApplication::processEvents() -> void {
while(pendingEvents()) QApplication::processEvents();
}
auto pApplication::quit() -> void {
QApplication::quit();
qtApplication = nullptr; //note: deleting QApplication will crash libQtGui
if(state().display) {
if(state().screenSaverXDG && state().screenSaverWindow) {
//this needs to run synchronously, so that XUnmapWindow() won't happen before xdg-screensaver is finished
execute("xdg-screensaver", "resume", string{"0x", hex(state().screenSaverWindow)});
XUnmapWindow(state().display, state().screenSaverWindow);
state().screenSaverWindow = 0;
}
XCloseDisplay(state().display);
state().display = nullptr;
}
}
auto pApplication::setScreenSaver(bool screenSaver) -> void {
#if defined(DISPLAY_XORG)
if(state().screenSaverXDG && state().screenSaverWindow) {
invoke("xdg-screensaver", screenSaver ? "resume" : "suspend", string{"0x", hex(state().screenSaverWindow)});
}
#endif
}
auto pApplication::state() -> State& {
static State state;
return state;
}
//this is sadly necessary for things like determining window frame geometry
//obviously, it is used as sparingly as possible
auto pApplication::synchronize() -> void {
for(auto n : range(8)) {
#if HIRO_QT==4 && defined(DISPLAY_XORG)
QApplication::syncX();
#elif HIRO_QT==5
QApplication::sync();
#endif
Application::processEvents();
usleep(2000);
}
}
auto pApplication::initialize() -> void {
#if HIRO_QT==5 && defined(PLATFORM_BSD)
setenv("QTCOMPOSE", "/usr/local/lib/X11/locale/", 0);
#endif
#if defined(DISPLAY_XORG)
state().display = XOpenDisplay(nullptr);
state().screenSaverXDG = (bool)execute("xdg-screensaver", "--version").output.find("xdg-screensaver");
if(state().screenSaverXDG) {
auto screen = DefaultScreen(state().display);
auto rootWindow = RootWindow(state().display, screen);
XSetWindowAttributes attributes{};
attributes.background_pixel = BlackPixel(state().display, screen);
attributes.border_pixel = 0;
attributes.override_redirect = true;
state().screenSaverWindow = XCreateWindow(state().display, rootWindow,
0, 0, 1, 1, 0, DefaultDepth(state().display, screen),
InputOutput, DefaultVisual(state().display, screen),
CWBackPixel | CWBorderPixel | CWOverrideRedirect, &attributes
);
//note: hopefully xdg-screensaver does not require the window to be mapped ...
//if it does, we're in trouble: a small 1x1 black pixel window will be visible in said case
XMapWindow(state().display, state().screenSaverWindow);
XFlush(state().display);
}
#endif
static auto name = Application::state().name ? Application::state().name : string{"hiro"};
Update to v106r21 release. byuu says: Changelog: - higan: target-tomoko has been renamed to target-higan - Super Famicom: event has been renamed to processor(architecture=uPD78214) - Super Famicom: SNES-EVENT supported once more; under board IDs EVENT-CC92 and EVENT-PF94 - Super Famicom: SNES-EVENT preliminarily set up to use DIP switch settings ala the Nintendo Super System (incomplete) - Super Famicom: MCC PSRAM moved inside the MCU, as it is remappable - Super Famicom: MCC emulation rewritten from scratch; it is now vastly more accurate than before - Super Famicom: added BSC-1A5B9P-01 board definition to database; corrected BS-MCC-RAM board definition - Super Famicom: moved SHVC-LN3B-01 RAM outside of processor(identifier=SDD1) - higan: when selecting a default game to load for a new system entry, it will change the system option to match the media type - higan: the load text box on the system entry window is now editable; can be used to erase entries - icarus: fixed bug in Famicom importing - icarus: importing unappended SNES coprocessor firmware will now rename the firmware properly - hiro/GTK,Qt: WM_CLASS is now set correctly in `argv[0]`, so applications should show “higan”, “icarus” instead of “hiro” now Note: if you wish to run the BS-X town cartridge, the database currently lists the download RAM as type “PSRAM”. This needs to be changed to “RAM” in order to load properly. Otherwise, the emulator will bomb out on the load window, because BSC-1A5B9P-01 expects PSRAM to always be present, but it won't find it with the wrong memory type. I'll correct this in the database in a later release. For now, you can copy the game portion of the manifest to a new manifest.bml file and drop it into the gamepak folder until I fix the database.
2018-05-17 03:37:29 +00:00
//QApplication stores references to argc;
//and will access them after pApplication::initialize() returns
static int argc = 1;
static char* argv[] = {name.get(), nullptr};
static char** argvp = argv;
qtApplication = new QApplication(argc, argvp);
pKeyboard::initialize();
}
}
#endif