adding new "saver" setting
authorJavier S. Pedro <maemo@javispedro.com>
Mon, 1 Feb 2010 01:26:42 +0000 (02:26 +0100)
committerJavier S. Pedro <maemo@javispedro.com>
Mon, 1 Feb 2010 01:26:42 +0000 (02:26 +0100)
debian/changelog
gui/drnoksnes.schemas.m4
gui/gconf.h
gui/i18n/de.po
gui/i18n/pl.po
gui/i18n/sv.po
platform/config.cpp
platform/osso.cpp
platform/platform.h
platform/sdlv.cpp
platform/sdlvscalers.cpp

index bca1564..e02a338 100644 (file)
@@ -3,8 +3,10 @@ drnoksnes (1.2.6) unstable; urgency=low
   * Using SDL_haa for scaling in Fremantle now.
   * Reworked GUI key mapping gconf entries.
   * Using GConfClient instead of HGW. Removing dependency on hgw.
+  * Moved config file from ~/apps to ~/.config
+  * Added new "saver" setting.
 
- -- Javier S. Pedro <maemo@javispedro.com>  Mon,  1 Feb 2010 00:27:45 +0100
+ -- Javier S. Pedro <maemo@javispedro.com>  Mon,  1 Feb 2010 02:26:00 +0100
 
 drnoksnes (1.2.5) unstable; urgency=low
 
index 56e01b7..9a2b0b1 100644 (file)
@@ -45,6 +45,20 @@ define(`N_', `$*')dnl
       </locale>
     </schema>
     <schema>
+     <key>/schemas/apps/maemo/drnoksnes/saver</key>
+      <applyto>/apps/maemo/drnoksnes/saver</applyto>
+      <owner>drnoksnes</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+        <short>Enable power saving</short>
+        <long>
+          This will save and close the emulator when it is deactivated or
+          the device enters idle state.
+        </long>
+      </locale>
+    </schema>
+    <schema>
      <key>/schemas/apps/maemo/drnoksnes/sound</key>
       <applyto>/apps/maemo/drnoksnes/sound</applyto>
       <owner>drnoksnes</owner>
index c7ae3d0..bb4d9a4 100644 (file)
@@ -3,6 +3,7 @@
 
 #define kGConfPath "/apps/maemo/drnoksnes"
 #define kGConfRomFile kGConfPath "/" "rom"
+#define kGConfSaver kGConfPath "/" "saver"
 #define kGConfSound kGConfPath "/" "sound"
 #define kGConfTurboMode kGConfPath "/" "turbo"
 #define kGConfFrameskip kGConfPath "/" "frameskip"
index d4898fa..f833fc4 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: drnoksnes\n"
 "Report-Msgid-Bugs-To: maemo@javispedro.com\n"
-"POT-Creation-Date: 2010-01-26 20:44+0100\n"
+"POT-Creation-Date: 2010-01-28 01:47+0100\n"
 "PO-Revision-Date: 2010-01-28 09:50+0100\n"
 "Last-Translator: Philipp Zabel <philipp.zabel@gmail.com>\n"
 "Language-Team: German\n"
@@ -41,8 +41,7 @@ msgstr "Ziel-Bildwiederholrate"
 msgid "Show while in game"
 msgstr "Im Spiel anzeigen"
 
-#: plugin.c:295
-#: plugin.c:313
+#: plugin.c:295 plugin.c:313
 msgid "Turbo mode"
 msgstr "Turbomodus"
 
@@ -54,8 +53,7 @@ msgstr "Ton einschalten"
 msgid "Display framerate"
 msgstr "Bildwiederholrate anzeigen"
 
-#: plugin.c:334
-#: settings.c:224
+#: plugin.c:334 settings.c:224
 msgid "Accurate graphics"
 msgstr "Akkurate Grafik"
 
@@ -63,18 +61,15 @@ msgstr "Akkurate Grafik"
 msgid "Framerate:"
 msgstr "Bildwiederholrate:"
 
-#: plugin.c:347
-#: settings.c:249
+#: plugin.c:347 settings.c:249
 msgid "No speedhacks"
 msgstr "Keine Speedhacks"
 
-#: plugin.c:348
-#: settings.c:250
+#: plugin.c:348 settings.c:250
 msgid "Safe hacks only"
 msgstr "Nur sichere Hacks"
 
-#: plugin.c:349
-#: settings.c:251
+#: plugin.c:349 settings.c:251
 msgid "All speedhacks"
 msgstr "Alle Speedhacks"
 
@@ -82,13 +77,11 @@ msgstr "Alle Speedhacks"
 msgid "Settings…"
 msgstr "Einstellungen..."
 
-#: plugin.c:448
-#: plugin.c:457
+#: plugin.c:448 plugin.c:457
 msgid "About…"
 msgstr "Über..."
 
-#: plugin.c:456
-#: settings.c:177
+#: plugin.c:456 settings.c:177
 msgid "Settings"
 msgstr "Einstellungen"
 
@@ -157,18 +150,16 @@ msgstr "Wiimote"
 msgid "Zeemote"
 msgstr "Zeemote"
 
-#: keys.c:267
+#: keys.c:266
 #, c-format
 msgid "Player %d keys"
 msgstr "Spieler %d Tasten"
 
-#: keys.c:270
+#: keys.c:269
 msgid "Defaults"
 msgstr "Standardeinstellungen"
 
-#: settings.c:52
-#: settings.c:59
-#: settings.c:61
+#: settings.c:52 settings.c:59 settings.c:61
 msgid "2x zoom"
 msgstr "2x Vergrößerung"
 
@@ -243,4 +234,3 @@ msgstr "Schnell laden 2"
 #: buttons.inc:27
 msgid "Quick Save 2"
 msgstr "Schnell speichern 2"
-
index 35c18fe..f9c5213 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: drnoksnes\n"
 "Report-Msgid-Bugs-To: maemo@javispedro.com\n"
-"POT-Creation-Date: 2010-01-26 20:44+0100\n"
+"POT-Creation-Date: 2010-01-28 01:47+0100\n"
 "PO-Revision-Date: 2010-01-28 00:42+0100\n"
 "Last-Translator: Tomasz Dominikowski <dominikowski@gmail.com>\n"
 "Language-Team: Polish <dominikowski@gmail.com>\n"
@@ -41,8 +41,7 @@ msgstr "Docel. liczba kl./s"
 msgid "Show while in game"
 msgstr "Wyświetlaj podczas gry"
 
-#: plugin.c:295
-#: plugin.c:313
+#: plugin.c:295 plugin.c:313
 msgid "Turbo mode"
 msgstr "Tryb Turbo"
 
@@ -54,8 +53,7 @@ msgstr "Włącz dźwięk"
 msgid "Display framerate"
 msgstr "Wyświetlaj liczbę klatek/s"
 
-#: plugin.c:334
-#: settings.c:224
+#: plugin.c:334 settings.c:224
 msgid "Accurate graphics"
 msgstr "Dokładna grafika"
 
@@ -63,18 +61,15 @@ msgstr "Dokładna grafika"
 msgid "Framerate:"
 msgstr "Klatek/s:"
 
-#: plugin.c:347
-#: settings.c:249
+#: plugin.c:347 settings.c:249
 msgid "No speedhacks"
 msgstr "Bez sztuczek z prędkością"
 
-#: plugin.c:348
-#: settings.c:250
+#: plugin.c:348 settings.c:250
 msgid "Safe hacks only"
 msgstr "Tylko bezpieczne sztuczki"
 
-#: plugin.c:349
-#: settings.c:251
+#: plugin.c:349 settings.c:251
 msgid "All speedhacks"
 msgstr "Wszystkie sztuczki z prędkością"
 
@@ -82,13 +77,11 @@ msgstr "Wszystkie sztuczki z prędkością"
 msgid "Settings…"
 msgstr "Ustawienia..."
 
-#: plugin.c:448
-#: plugin.c:457
+#: plugin.c:448 plugin.c:457
 msgid "About…"
 msgstr "O programie..."
 
-#: plugin.c:456
-#: settings.c:177
+#: plugin.c:456 settings.c:177
 msgid "Settings"
 msgstr "Ustawienia"
 
@@ -157,18 +150,16 @@ msgstr "Wiimote"
 msgid "Zeemote"
 msgstr "Zeemote"
 
-#: keys.c:267
+#: keys.c:266
 #, c-format
 msgid "Player %d keys"
 msgstr "Klawisze gracza %d"
 
-#: keys.c:270
+#: keys.c:269
 msgid "Defaults"
 msgstr "Domyślne"
 
-#: settings.c:52
-#: settings.c:59
-#: settings.c:61
+#: settings.c:52 settings.c:59 settings.c:61
 msgid "2x zoom"
 msgstr "2x przybliżenie"
 
@@ -243,4 +234,3 @@ msgstr "Szybkie wczytanie 2"
 #: buttons.inc:27
 msgid "Quick Save 2"
 msgstr "Szybki zapis 2"
-
index e9fda7b..6611cb9 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: maemo@javispedro.com\n"
-"POT-Creation-Date: 2010-01-26 20:44+0100\n"
+"POT-Creation-Date: 2010-01-28 01:47+0100\n"
 "PO-Revision-Date: 2010-01-28 05:00+0100\n"
 "Last-Translator: Robert Hägerström <rofo1000@gmail.com>\n"
 "Language-Team: Swedish\n"
@@ -149,12 +149,12 @@ msgstr "Wiimote"
 msgid "Zeemote"
 msgstr "Zeemote"
 
-#: keys.c:267
+#: keys.c:266
 #, c-format
 msgid "Player %d keys"
 msgstr "Spelare %d tangenter"
 
-#: keys.c:270
+#: keys.c:269
 msgid "Defaults"
 msgstr "Standard"
 
index 2486dd6..8802456 100644 (file)
@@ -188,6 +188,7 @@ static void loadDefaults()
        basePath = 0;
 
        Config.quitting = false;
+       Config.saver = false;
        Config.enableAudio = true;
        Config.fullscreen = false;
        Config.scaler = 0;
index b967018..38128d9 100644 (file)
@@ -66,6 +66,18 @@ static gint ossoAppCallback(const gchar *interface, const gchar *method,
        return OSSO_OK;
 }
 
+static void ossoHwCallback(osso_hw_state_t *state, gpointer data)
+{
+       if (state->shutdown_ind) {
+               // Shutting down. Try to quit gracefully.
+               S9xDoAction(kActionQuit);
+       }
+       if (Config.saver && state->system_inactivity_ind) {
+               // Screen went off, and power saving is active.
+               S9xDoAction(kActionQuit);
+       }
+}
+
 /** Called from main(), initializes Glib & libosso stuff if needed. */
 void OssoInit()
 {
@@ -78,6 +90,8 @@ void OssoInit()
        }
 
        g_type_init();
+       g_set_prgname("drnoksnes");
+       g_set_application_name("DrNokSnes");
        mainContext = g_main_context_default();
        mainLoop = g_main_loop_new(mainContext, FALSE);
        ossoContext = osso_initialize("com.javispedro.drnoksnes", "1", 0, 0);
@@ -92,7 +106,13 @@ void OssoInit()
 
        osso_return_t ret;
        ret = osso_rpc_set_default_cb_f(ossoContext, ossoAppCallback, 0);
-       g_assert(ret == OSSO_OK);
+       g_warn_if_fail(ret == OSSO_OK);
+
+       osso_hw_state_t hwStateFlags = { FALSE };
+       hwStateFlags.shutdown_ind = TRUE;
+       hwStateFlags.system_inactivity_ind = TRUE;
+       ret = osso_hw_set_event_cb(ossoContext, &hwStateFlags, ossoHwCallback, 0);
+       g_warn_if_fail(ret == OSSO_OK);
 
        printf("Osso: Initialized libosso\n");
 }
@@ -152,6 +172,7 @@ void OssoConfig()
        }
 
        // Read most of the non-player specific settings
+       Config.saver = gconf_client_get_bool(gcc, kGConfSaver, 0);
        Config.enableAudio = gconf_client_get_bool(gcc, kGConfSound, 0);
        Settings.TurboMode = gconf_client_get_bool(gcc, kGConfTurboMode, 0);
        Settings.Transparency = gconf_client_get_bool(gcc, kGConfTransparency, 0);
@@ -191,6 +212,7 @@ void OssoConfig()
 
        g_free(romFile);
 
+       // Read player 1 controls
        gchar key[kGConfPlayerPathBufferLen];
        gchar *relKey = key + sprintf(key, kGConfPlayerPath, 1);
 
@@ -207,6 +229,8 @@ void OssoConfig()
                g_main_context_iteration(mainContext, TRUE);
        }
 
+       // The command we received from the launcher will tell us if we have to
+       // load a snapshot file.
        switch (startupCommand) {
                case STARTUP_COMMAND_RUN:
                case STARTUP_COMMAND_RESTART:
@@ -231,6 +255,9 @@ void OssoConfig()
        g_object_unref(G_OBJECT(gcc));
 }
 
+/** This is called periodically from the main loop.
+       Iterates the GLib loop to get D-Bus events.
+ */
 void OssoPollEvents()
 {
        if (!OssoOk()) return;
index 41e7f62..2cd1769 100644 (file)
@@ -18,6 +18,8 @@ extern struct config {
        char * scaler;
        /** Audio output enabled */
        bool enableAudio;
+       /** Quit when the emulator window is deactivated */
+       bool saver;
        /** Speedhacks file to use */
        char * hacksFile;
        /** Enable touchscreen controls */
index 0d9ff32..39f68fe 100644 (file)
@@ -28,6 +28,9 @@ static bool gotWindowSize, gotScreenSize;
 /** The current scaler object */
 Scaler* scaler;
 
+/** Use the current window size to calculate screen size.
+       Useful on "single window" platforms, like Hildon.
+ */
 static void calculateScreenSize()
 {
        SDL_SysWMinfo wminfo;
@@ -57,8 +60,10 @@ static void calculateScreenSize()
        }
 }
 
+/** Sets the main window title */
 void S9xSetTitle(const char *title)
 {
+       // This is a Maemo specific hack, but works on most platforms.
        SDL_SysWMinfo info;
        SDL_VERSION(&info.version);
        if ( SDL_GetWMInfo(&info) ) {
@@ -92,9 +97,13 @@ static void setupVideoSurface()
        const unsigned gameHeight = IMAGE_HEIGHT;
 
 #ifdef MAEMO
+       // Under Maemo we know that the window manager will automatically
+       // resize our windows to fullscreen.
+       // Thus we can use that to detect the screen size.
+       // Of course, this causes flicker, so we try to avoid it when
+       // changing between modes.
        if ((Config.fullscreen && !gotScreenSize) ||
                (!Config.fullscreen && !gotWindowSize)) {
-               // Do a first try, in order to get window/screen size
                screen = SDL_SetVideoMode(gameWidth, gameHeight, 16,
                        SDL_SWSURFACE | SDL_RESIZABLE |
                        (Config.fullscreen ? SDL_FULLSCREEN : 0));
@@ -134,7 +143,7 @@ static void setupVideoSurface()
 
        scaler = sFactory->instantiate(screen, gameWidth, gameHeight);
 
-       // We get pitch surface values from SDL
+       // Each scaler may have its own pitch
        GFX.RealPitch = GFX.Pitch = scaler->getDrawBufferPitch();
        GFX.ZPitch = GFX.Pitch / 2; // gfx & tile.cpp depend on this, unfortunately.
        GFX.PixSize = screen->format->BitsPerPixel / 8;
@@ -199,11 +208,22 @@ void S9xVideoToggleFullscreen()
 
 void processVideoEvent(const SDL_Event& event)
 {
+       // If we're in power save mode, and this is a defocus event, quit.
+       if (Config.saver) {
+               if (event.type == SDL_ACTIVEEVENT &&
+                  (event.active.state & SDL_APPINPUTFOCUS) &&
+                  !event.active.gain) {
+                       S9xDoAction(kActionQuit);
+                       return;
+               }
+       }
+
+       // Forward video event to the active scaler, if any.
        if (scaler)
                scaler->filter(event);
 }
 
-// This is here for completeness, but palette mode is useless on N8x0
+// This is here for completeness, but palette mode is mostly useless (slow).
 void S9xSetPalette ()
 {
        if (Settings.SixteenBit) return;
@@ -220,6 +240,11 @@ void S9xSetPalette ()
        SDL_SetColors(screen, colors, 0, 256);
 }
 
+/** Called before rendering a frame.
+       This function must ensure GFX.Screen points to something, but we did that
+       while initializing video output.
+       @return TRUE if we should render the frame.
+ */
 bool8_32 S9xInitUpdate ()
 {
        scaler->prepare();
@@ -227,6 +252,7 @@ bool8_32 S9xInitUpdate ()
        return TRUE;
 }
 
+/** Called after rendering a frame. */
 bool8_32 S9xDeinitUpdate (int width, int height, bool8_32 sixteenBit)
 {
        scaler->finish();
index 8f7b39e..cd48c33 100644 (file)
@@ -626,15 +626,15 @@ public:
 
        bool filter(const SDL_Event& event)
        {
-               if (event.type == SDL_ACTIVEEVENT) {
-                       if (scaler && (event.active.state & SDL_APPINPUTFOCUS)) {
-                               if (event.active.gain)
-                                       scaler->resume();
-                               else
-                                       scaler->pause();
-
-                               return true;
+               if (event.type == SDL_ACTIVEEVENT &&
+                 (event.active.state & SDL_APPINPUTFOCUS)) {
+                       if (event.active.gain) {
+                               resume();
+                       } else {
+                               pause();
                        }
+
+                       return true;
                }
 
                return false;