some magic with stackable windows
authorJavier S. Pedro <maemo@javispedro.com>
Sun, 3 Jan 2010 00:48:01 +0000 (01:48 +0100)
committerJavier S. Pedro <maemo@javispedro.com>
Sun, 3 Jan 2010 00:48:01 +0000 (01:48 +0100)
Makefile
gui/Makefile
gui/i18n/es_ES.po
gui/plugin.c
platform/sdlv.cpp
platform/sdlv.h
platform/sdlvhildon.cpp [new file with mode: 0644]
platform/sdlvscalers.cpp

index 3a3e373..2b8efa4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -49,15 +49,6 @@ else
        OBJS += sa1cpu.o
 endif
 
-
-ifeq ($(CONF_XSP), 1)
-       CPPFLAGS += -DCONF_XSP=1 $(shell pkg-config --cflags xsp)
-       LDLIBS += $(shell pkg-config --libs xsp)
-endif
-ifeq ($(CONF_HD), 1)
-       CPPFLAGS += -DCONF_HD=1
-endif
-
 OBJS += $(CONF_BUILD_MISC_ROUTINES).o
 
 # from open-whatever sdk
@@ -69,6 +60,14 @@ OBJS += platform/path.o platform/config.o
 OBJS += platform/sdl.o platform/sdlv.o platform/sdla.o platform/sdli.o
 OBJS += platform/sdlvscalers.o
 
+ifeq ($(CONF_XSP), 1)
+       CPPFLAGS += -DCONF_XSP=1 $(shell pkg-config --cflags xsp)
+       LDLIBS += $(shell pkg-config --libs xsp)
+endif
+ifeq ($(CONF_HD), 1)
+       CPPFLAGS += -DCONF_HD=1
+       OBJS += platform/sdlvhildon.o
+endif
 ifeq ($(CONF_HGW), 1)
        CPPFLAGS += -DCONF_HGW=1 -I/usr/include/hgw
        LDLIBS += -lhgw
index b4df9bd..b147f4e 100644 (file)
@@ -1,4 +1,4 @@
-PKGS:=gtk+-2.0 hildon-1 hildon-fm-2 libhildonmime gconf-2.0 gnome-vfs-2.0
+PKGS:=gtk+-2.0 hildon-1 hildon-fm-2 libhildonmime gconf-2.0 gnome-vfs-2.0 x11
 CPPFLAGS:=$(shell pkg-config --cflags $(PKGS))
 LDLIBS:=$(shell pkg-config --libs $(PKGS))
 
index 8e4f88a..06b2701 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: DrNokSnes 1.2.5\n"
 "Report-Msgid-Bugs-To: maemo@javispedro.com\n"
-"POT-Creation-Date: 2009-12-31 03:20+0100\n"
+"POT-Creation-Date: 2010-01-03 00:53+0100\n"
 "PO-Revision-Date: 2009-12-31 03:25+0100\n"
 "Last-Translator: Javier <javier@javispedro.com>\n"
 "Language-Team: Spanish <maemo@javispedro.com>\n"
@@ -23,95 +23,87 @@ msgstr ""
 msgid "<no rom selected>"
 msgstr "<sin rom seleccionada>"
 
-#: plugin.c:213
+#: plugin.c:233
 msgid "ROM"
 msgstr "ROM"
 
-#: plugin.c:231
+#: plugin.c:251
 msgid "Select ROM..."
 msgstr "Seleccionar ROM..."
 
-#: plugin.c:248
+#: plugin.c:268
 msgid "Sound"
 msgstr "Sonido"
 
-#: plugin.c:254
+#: plugin.c:274
 msgid "Target framerate"
 msgstr "Velocidad objetivo"
 
-#: plugin.c:271
+#: plugin.c:291
 msgid "Show while in game"
 msgstr "Mostrar durante el juego"
 
-#: plugin.c:275
-#: plugin.c:293
+#: plugin.c:295 plugin.c:313
 msgid "Turbo mode"
 msgstr "Modo Turbo"
 
-#: plugin.c:290
+#: plugin.c:310
 msgid "Enable sound"
 msgstr "Activar sonido"
 
-#: plugin.c:295
+#: plugin.c:315
 msgid "Display framerate"
 msgstr "Mostrar velocidad"
 
-#: plugin.c:314
-#: settings.c:203
+#: plugin.c:334 settings.c:203
 msgid "Accurate graphics"
 msgstr "Mejores gráficos"
 
-#: plugin.c:318
+#: plugin.c:338
 msgid "Framerate:"
 msgstr "Velocidad:"
 
-#: plugin.c:327
-#: settings.c:228
+#: plugin.c:347 settings.c:228
 msgid "No speedhacks"
 msgstr "Sin speedhacks"
 
-#: plugin.c:328
-#: settings.c:229
+#: plugin.c:348 settings.c:229
 msgid "Safe hacks only"
 msgstr "Sólo hacks seguros"
 
-#: plugin.c:329
-#: settings.c:230
+#: plugin.c:349 settings.c:230
 msgid "All speedhacks"
 msgstr "Todos los hacks"
 
-#: plugin.c:423
+#: plugin.c:448
 msgid "Settings…"
 msgstr "Ajustes…"
 
-#: plugin.c:425
-#: plugin.c:434
+#: plugin.c:450 plugin.c:459
 msgid "About…"
 msgstr "Acerca de…"
 
-#: plugin.c:433
-#: settings.c:165
+#: plugin.c:458 settings.c:165
 msgid "Settings"
 msgstr "Ajustes"
 
-#: plugin.c:442
+#: plugin.c:467
 msgid "Controls…"
 msgstr "Controles…"
 
-#: plugin.c:446
+#: plugin.c:471
 msgid "Advanced…"
 msgstr "Avanzados…"
 
-#: plugin.c:508
+#: plugin.c:533
 msgid "No ROM selected"
 msgstr "Sin ROM seleccionada"
 
-#: plugin.c:513
+#: plugin.c:538
 msgid "ROM file does not exist"
 msgstr "El archivo ROM no existe"
 
-#: controls.c:285
-#: settings.c:184
+#: controls.c:285 settings.c:184
 msgid "Controls"
 msgstr "Controles"
 
@@ -123,9 +115,7 @@ msgstr "Pulsa tecla o…"
 msgid "Simple 2x zoom (fast)"
 msgstr "Zoom 2X simple (rápido)"
 
-#: settings.c:53
-#: settings.c:59
-#: settings.c:61
+#: settings.c:53 settings.c:59 settings.c:61
 msgid "Simple 2x zoom"
 msgstr "Zoom 2X simple"
 
@@ -164,4 +154,3 @@ msgstr "Speedhacks"
 #: about.c:55
 msgid "About"
 msgstr "Acerca de"
-
index 85d684d..39324d4 100644 (file)
@@ -186,7 +186,10 @@ static void about_item_callback(GtkWidget * button, gpointer data)
 }
 
 #if MAEMO_VERSION >= 5
-/* Called for each of the play/restart/continue buttons */
+#include <gdk/gdkx.h>
+#include <X11/Xatom.h>
+
+/** Called for each of the play/restart/continue buttons */
 static void found_ogs_button_callback(GtkWidget *widget, gpointer data)
 {
        hildon_gtk_widget_set_theme_size(widget,
@@ -195,6 +198,23 @@ static void found_ogs_button_callback(GtkWidget *widget, gpointer data)
        gtk_box_set_child_packing(GTK_BOX(data), widget,
                FALSE, FALSE, 0, GTK_PACK_START);
 }
+/** Converts the window into a stackable one */
+static void plugin_realized_callback(GtkWidget *widget, gpointer data)
+{
+       GdkDisplay *display;
+    Atom atom;
+    unsigned long val = 0;
+       GtkWidget* window = gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW);
+       printf("signal called %d %d\n", GTK_WIDGET_REALIZED(window), GTK_WIDGET_VISIBLE(window));
+
+    /* Set additional property "_HILDON_STACKABLE_WINDOW", to allow the WM to manage
+       it as a stackable window. */
+    display = gdk_drawable_get_display(window->window);
+    atom = gdk_x11_get_xatom_by_name_for_display (display, "_HILDON_STACKABLE_WINDOW");
+    XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window->window), atom,
+                     XA_INTEGER, 32, PropModeReplace,
+                     (unsigned char *) &val, 1);
+}
 #endif
 
 static GtkWidget * load_plugin(void)
@@ -362,6 +382,11 @@ static GtkWidget * load_plugin(void)
 
        set_rom(gconf_client_get_string(gcc, kGConfRomFile, NULL));
 
+#if MAEMO_VERSION == 5
+       g_signal_connect_after(G_OBJECT(parent), "realize",
+                                               G_CALLBACK(plugin_realized_callback), NULL);
+#endif
+
        // Connect signals
        g_signal_connect(G_OBJECT(select_rom_btn), "clicked",
                                        G_CALLBACK(select_rom_callback), NULL);
index 1f35939..513a93e 100644 (file)
@@ -176,6 +176,10 @@ void S9xInitDisplay(int argc, const char ** argv)
        if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) 
                DIE("SDL_InitSubSystem(VIDEO): %s", SDL_GetError());
 
+#if CONF_HD
+       hd_setup();
+#endif
+
        setupVideoSurface();
        drawOnscreenControls();
 }
index b713ea0..94031f1 100644 (file)
@@ -5,4 +5,46 @@
 
 extern SDL_Surface* screen;
 
+#if CONF_HD
+#      include <SDL_syswm.h>
+#      include <X11/Xatom.h>
+#      define HDATOM(X) hdAtomsValues[ ATOM ## X ]
+
+enum hdAtoms {
+       ATOM_HILDON_NON_COMPOSITED_WINDOW = 0,
+       ATOM_HILDON_STACKABLE_WINDOW,
+       ATOM_NET_WM_STATE,
+       ATOM_NET_WM_STATE_FULLSCREEN,
+       ATOM_NET_WM_WINDOW_TYPE,
+       ATOM_NET_WM_WINDOW_TYPE_NORMAL,
+       ATOM_NET_WM_WINDOW_TYPE_DIALOG,
+       ATOM_HILDON_WM_WINDOW_TYPE_ANIMATION_ACTOR,
+       ATOM_HILDON_ANIMATION_CLIENT_READY,
+       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_SHOW,
+       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_POSITION,
+       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_ROTATION,
+       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_SCALE,
+       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_ANCHOR,
+       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_PARENT,
+       ATOM_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE,
+       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SHM,
+       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_DAMAGE,
+       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW,
+       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION,
+       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_OFFSET,
+       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE,
+       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT,
+       ATOM_HILDON_TEXTURE_CLIENT_READY,
+       ATOM_COUNT
+};
+
+extern Atom hdAtomsValues[];
+
+extern SDL_SysWMinfo WMinfo;
+
+extern void hd_setup();
+extern void hd_set_non_compositing(bool enable);
+
+#endif
+
 #endif
diff --git a/platform/sdlvhildon.cpp b/platform/sdlvhildon.cpp
new file mode 100644 (file)
index 0000000..3438710
--- /dev/null
@@ -0,0 +1,239 @@
+#if CONF_HD
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+#include <SDL.h>
+#include <SDL_syswm.h>
+
+#include "sdlv.h"
+#include "hgw.h"
+
+#define DIE(format, ...) do { \
+               fprintf(stderr, "Died at %s:%d: ", __FILE__, __LINE__ ); \
+               fprintf(stderr, format "\n", ## __VA_ARGS__); \
+               abort(); \
+       } while (0);
+
+static const char * hdAtomNames[] = {
+       "_HILDON_NON_COMPOSITED_WINDOW",
+       "_HILDON_STACKABLE_WINDOW",
+       "_NET_WM_STATE",
+       "_NET_WM_STATE_FULLSCREEN",
+       "_NET_WM_WINDOW_TYPE",
+       "_NET_WM_WINDOW_TYPE_NORMAL",
+       "_NET_WM_WINDOW_TYPE_DIALOG",
+       "_HILDON_WM_WINDOW_TYPE_ANIMATION_ACTOR",
+       "_HILDON_ANIMATION_CLIENT_READY",
+       "_HILDON_ANIMATION_CLIENT_MESSAGE_SHOW",        
+       "_HILDON_ANIMATION_CLIENT_MESSAGE_POSITION",
+       "_HILDON_ANIMATION_CLIENT_MESSAGE_ROTATION",
+       "_HILDON_ANIMATION_CLIENT_MESSAGE_SCALE",
+       "_HILDON_ANIMATION_CLIENT_MESSAGE_ANCHOR",
+       "_HILDON_ANIMATION_CLIENT_MESSAGE_PARENT",
+       "_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE",
+       "_HILDON_TEXTURE_CLIENT_MESSAGE_SHM",
+       "_HILDON_TEXTURE_CLIENT_MESSAGE_DAMAGE",
+       "_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW",
+       "_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION",
+       "_HILDON_TEXTURE_CLIENT_MESSAGE_OFFSET",
+       "_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE",
+       "_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT",
+       "_HILDON_TEXTURE_CLIENT_READY",
+       ""
+};
+
+static bool hd_ok = false;
+
+Atom hdAtomsValues[ATOM_COUNT];
+
+SDL_SysWMinfo WMinfo;
+
+static void hd_setup_stackable_window();
+
+void hd_setup()
+{
+       SDL_VERSION(&WMinfo.version);
+       if (!SDL_GetWMInfo(&WMinfo)) {
+               DIE("Bad SDL version");
+       }
+
+       Display * display = WMinfo.info.x11.display;
+
+       if (!hd_ok) {
+               XInternAtoms(display, (char**)hdAtomNames, ATOM_COUNT, True, hdAtomsValues);
+
+               if (HDATOM(_HILDON_NON_COMPOSITED_WINDOW) == None) {
+                       DIE("Hildon Desktop seems not be loaded, since %s is not defined",
+                               "_HILDON_NON_COMPOSITED_WINDOW");
+                       return;
+               }
+
+               if (hgwLaunched) {
+                       hd_setup_stackable_window();
+               }
+
+               hd_ok = true;
+       }
+};
+
+/** Enables or disables the Hildon NonCompositedWindow property */
+void hd_set_non_compositing(bool enable)
+{
+       Display *display;
+       Window xwindow;
+       XSetWindowAttributes xattr;
+       Atom atom;
+       int one = 1;
+
+       WMinfo.info.x11.lock_func();
+       display = WMinfo.info.x11.display;
+       xwindow = WMinfo.info.x11.fswindow;
+
+       if (enable) {
+               /* 
+                * The basic idea behind this is to disable the override_redirect
+                * window attribute, which SDL sets, and instead use _NET_WM_STATE
+                * to tell hildon-desktop to fullscreen the app.
+                * I am not really happy with this, which should ideally be fixed
+                * at the libsdl level, but seems to work.
+                * As soon as the window is managed by Hildon-Desktop again, set for it
+                * not to be composited.
+                */
+               XUnmapWindow(display, xwindow);
+               xattr.override_redirect = False;
+               XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &xattr);
+
+               atom = HDATOM(_NET_WM_STATE_FULLSCREEN);
+               XChangeProperty(display, xwindow, HDATOM(_NET_WM_STATE),
+                       XA_ATOM, 32, PropModeReplace,
+                       (unsigned char *) &atom, 1);
+
+               XChangeProperty(display, xwindow, HDATOM(_HILDON_NON_COMPOSITED_WINDOW),
+                       XA_INTEGER, 32, PropModeReplace,
+                       (unsigned char *) &one, 1);
+               XMapWindow(display, xwindow);
+       } else {
+               xattr.override_redirect = True;
+               XDeleteProperty(display, xwindow,
+                       HDATOM(_HILDON_NON_COMPOSITED_WINDOW));
+               XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &xattr);
+       }
+
+       WMinfo.info.x11.unlock_func();
+}
+
+static Atom get_window_type(Display *dpy, Window win)
+{
+       Atom window_type = None;
+       Atom actual_type;
+       int actual_format;
+       unsigned long nitems, bytes_after;
+       unsigned char *prop_return = NULL;
+
+    if(Success == XGetWindowProperty(dpy, win, HDATOM(_NET_WM_WINDOW_TYPE),
+                                                               0L, sizeof(Atom),
+                                     False, XA_ATOM, &actual_type,
+                                     &actual_format, &nitems, &bytes_after,
+                                     &prop_return) && prop_return) {
+               window_type = *(Atom *)prop_return;
+               XFree(prop_return);
+       }
+
+       return window_type;
+}
+
+static Window find_launcher_window(Display *display, Window start)
+{
+       Window root, parent, *children;
+       unsigned int count, i;
+
+       if (XQueryTree(display, start, &root, &parent, &children, &count)) {
+               XClassHint class_hints;
+               for (i = 0; i < count; i++) {
+                       Window cur = children[i];
+                       Window sub = find_launcher_window(display, cur);
+                       if (sub) return sub;
+
+                       if (XGetClassHint(display, cur, &class_hints)) {
+                               if (strcasecmp(class_hints.res_class, "drnoksnes_startup") == 0) {
+                                       XFree(class_hints.res_name);
+                                       XFree(class_hints.res_class);
+
+                                       if (get_window_type(display, cur) != 
+                                               HDATOM(_NET_WM_WINDOW_TYPE_NORMAL)) {
+                                               continue;
+                                       }
+
+                                       XFree(children);
+
+                                       return cur;
+                               }
+                               XFree(class_hints.res_name);
+                               XFree(class_hints.res_class);
+                       }
+               }
+               XFree(children);
+       }
+       
+       return 0;
+}
+
+/** Finds the drnoksnes_startup window. */
+static Window find_launcher_window(Display *display)
+{
+       return find_launcher_window(display,
+               RootWindow(display, DefaultScreen(display)));
+}
+
+/** Converts the aux SDL windows into tops of the HildonWindowStack */
+static void hd_setup_stackable_window()
+{
+       Display *display;
+       Window window;
+       Atom atom = HDATOM(_NET_WM_WINDOW_TYPE_NORMAL);
+       XWMHints *hints;
+       int one = 1;
+
+       WMinfo.info.x11.lock_func();
+       display = WMinfo.info.x11.display;
+
+       Window launcher = find_launcher_window(display);
+
+       if (!launcher) {
+               printf("HD: Games startup window was not found\n");
+               return;
+       }
+
+       hints = XGetWMHints(display, launcher);
+       hints->flags &= WindowGroupHint;
+
+       window = WMinfo.info.x11.wmwindow;
+       XSetTransientForHint(display, window, launcher);
+       XSetWMHints(display, window, hints);
+       XChangeProperty(display, window, HDATOM(_NET_WM_WINDOW_TYPE),
+               XA_ATOM, 32, PropModeReplace,
+               (unsigned char *) &atom, 1);
+       XChangeProperty(display, window, HDATOM(_HILDON_STACKABLE_WINDOW),
+               XA_INTEGER, 32, PropModeReplace,
+               (unsigned char *) &one, 1);
+
+       window = WMinfo.info.x11.fswindow;
+       XSetTransientForHint(display, window, launcher);
+       XSetWMHints(display, window, hints);
+       XChangeProperty(display, window, HDATOM(_NET_WM_WINDOW_TYPE),
+               XA_ATOM, 32, PropModeReplace,
+               (unsigned char *) &atom, 1);
+       XChangeProperty(display, window, HDATOM(_HILDON_STACKABLE_WINDOW),
+               XA_INTEGER, 32, PropModeReplace,
+               (unsigned char *) &one, 1);
+
+       XFree(hints);
+
+       WMinfo.info.x11.unlock_func();
+}
+
+#endif
index 7139f5a..d949bde 100644 (file)
@@ -4,7 +4,6 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <SDL.h>
-#include <SDL_syswm.h>
 
 #if CONF_XSP
 #      include <X11/extensions/Xsp.h>
@@ -364,130 +363,6 @@ const ARMScaler::Factory ARMScaler::factory;
 
 #if CONF_HD
 
-enum hdAtoms {
-       ATOM_HILDON_NON_COMPOSITED_WINDOW = 0,
-       ATOM_NET_WM_STATE,
-       ATOM_NET_WM_STATE_FULLSCREEN,
-       ATOM_NET_WM_WINDOW_TYPE,
-       ATOM_NET_WM_WINDOW_TYPE_NORMAL,
-       ATOM_NET_WM_WINDOW_TYPE_DIALOG,
-       ATOM_HILDON_WM_WINDOW_TYPE_ANIMATION_ACTOR,
-       ATOM_HILDON_ANIMATION_CLIENT_READY,
-       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_SHOW,
-       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_POSITION,
-       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_ROTATION,
-       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_SCALE,
-       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_ANCHOR,
-       ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_PARENT,
-       ATOM_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE,
-       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SHM,
-       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_DAMAGE,
-       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW,
-       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION,
-       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_OFFSET,
-       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE,
-       ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT,
-       ATOM_HILDON_TEXTURE_CLIENT_READY,
-       ATOM_COUNT
-};
-
-static const char * hdAtomNames[] = {
-       "_HILDON_NON_COMPOSITED_WINDOW",
-       "_NET_WM_STATE",
-       "_NET_WM_STATE_FULLSCREEN",
-       "_NET_WM_WINDOW_TYPE",
-       "_NET_WM_WINDOW_TYPE_NORMAL",
-       "_NET_WM_WINDOW_TYPE_DIALOG",
-       "_HILDON_WM_WINDOW_TYPE_ANIMATION_ACTOR",
-       "_HILDON_ANIMATION_CLIENT_READY",
-       "_HILDON_ANIMATION_CLIENT_MESSAGE_SHOW",        
-       "_HILDON_ANIMATION_CLIENT_MESSAGE_POSITION",
-       "_HILDON_ANIMATION_CLIENT_MESSAGE_ROTATION",
-       "_HILDON_ANIMATION_CLIENT_MESSAGE_SCALE",
-       "_HILDON_ANIMATION_CLIENT_MESSAGE_ANCHOR",
-       "_HILDON_ANIMATION_CLIENT_MESSAGE_PARENT",
-       "_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE",
-       "_HILDON_TEXTURE_CLIENT_MESSAGE_SHM",
-       "_HILDON_TEXTURE_CLIENT_MESSAGE_DAMAGE",
-       "_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW",
-       "_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION",
-       "_HILDON_TEXTURE_CLIENT_MESSAGE_OFFSET",
-       "_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE",
-       "_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT",
-       "_HILDON_TEXTURE_CLIENT_READY",
-       ""
-};
-
-static Atom hdAtomsValues[ATOM_COUNT];
-static bool hdAtomsLoaded = false;
-
-#define HDATOM(X) hdAtomsValues[ ATOM ## X ]
-
-static void hildon_load_atoms(Display* display)
-{
-       if (hdAtomsLoaded) return;
-       
-       XInternAtoms(display, (char**)hdAtomNames, ATOM_COUNT, True, hdAtomsValues);
-       hdAtomsLoaded = true;
-       
-       if (HDATOM(_HILDON_NON_COMPOSITED_WINDOW) == None) {
-               DIE("Hildon Desktop seems not be loaded, since %s is not defined",
-                       "_HILDON_NON_COMPOSITED_WINDOW");
-               return;
-       }
-}
-
-/** Enables or disables the Hildon NonCompositedWindow property */
-static void hildon_set_non_compositing(bool enable)
-{
-       SDL_SysWMinfo wminfo;
-       Display *display;
-       Window xwindow;
-       XSetWindowAttributes xattr;
-       Atom atom;
-       int one = 1;
-       
-       SDL_VERSION(&wminfo.version);
-       if (!SDL_GetWMInfo(&wminfo)) return;
-       
-       wminfo.info.x11.lock_func();
-       display = wminfo.info.x11.display;
-       xwindow = wminfo.info.x11.fswindow;
-       hildon_load_atoms(display);
-
-       if (enable) {
-               /* 
-                * The basic idea behind this is to disable the override_redirect
-                * window attribute, which SDL sets, and instead use _NET_WM_STATE
-                * to tell hildon-desktop to fullscreen the app.
-                * I am not really happy with this, which should ideally be fixed
-                * at the libsdl level, but seems to work.
-                * As soon as the window is managed by Hildon-Desktop again, set for it
-                * not to be composited.
-                */
-               XUnmapWindow(display, xwindow);
-               xattr.override_redirect = False;
-               XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &xattr);
-
-               atom = HDATOM(_NET_WM_STATE_FULLSCREEN);
-               XChangeProperty(display, xwindow, HDATOM(_NET_WM_STATE),
-                       XA_ATOM, 32, PropModeReplace,
-                       (unsigned char *) &atom, 1);
-
-               XChangeProperty(display, xwindow, HDATOM(_HILDON_NON_COMPOSITED_WINDOW),
-                       XA_INTEGER, 32, PropModeReplace,
-                       (unsigned char *) &one, 1);
-               XMapWindow(display, xwindow);
-       } else {
-               xattr.override_redirect = True;
-               XDeleteProperty(display, xwindow,
-                       HDATOM(_HILDON_NON_COMPOSITED_WINDOW));
-               XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &xattr);
-       }
-
-       wminfo.info.x11.unlock_func();
-}
-
 class HDScalerBase : public Scaler
 {
        SDL_Surface * m_screen;
@@ -496,7 +371,6 @@ class HDScalerBase : public Scaler
        const float ratio_x, ratio_y;
 
        // SDL/X11 stuff we save for faster access.
-       SDL_SysWMinfo wminfo;
        Display* display;
        Window window;
 
@@ -532,17 +406,12 @@ private:
        /** Sends all configuration parameters for the remote texture. */
        void reconfigure()
        {
-               SDL_VERSION(&wminfo.version);
-               if (!SDL_GetWMInfo(&wminfo)) {
-                       DIE("Bad SDL version!");
-               }
-
                Window parent;
                int yoffset = 0;
                if (Config.fullscreen) {
-                       parent = wminfo.info.x11.fswindow;
+                       parent = WMinfo.info.x11.fswindow;
                } else {
-                       parent = wminfo.info.x11.wmwindow;
+                       parent = WMinfo.info.x11.wmwindow;
                        yoffset = 60; // Hardcode the title bar size for now.
                }
 
@@ -572,24 +441,14 @@ protected:
                //  - Render to that new window, instead of the SDL window ("screen").
                // Yet another load of uglyness, but hey.
 
-               // Barf if this is not a known SDL version.
-               SDL_VERSION(&wminfo.version);
-               if (!SDL_GetWMInfo(&wminfo)) {
-                       DIE("Bad SDL version!");
-               }
-
                // Clear the SDL screen with black, just in case it gets drawn.
                SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
 
-               // Get the SDL gfxdisplay (this is where events end up).
-               display = wminfo.info.x11.display;
+               display = WMinfo.info.x11.display;
 
                // The parent window needs to be mapped, so we sync it.
                XSync(display, True);
 
-               // Ensure hildon atoms are synced, and that hildon-desktop is up.
-               hildon_load_atoms(display);
-
                // Create our alternative window.
                const int blackColor = BlackPixel(display, DefaultScreen(display));
                window = XCreateSimpleWindow(display, DefaultRootWindow(display),
@@ -621,7 +480,7 @@ protected:
                }
 
                // Create a shared memory segment with hildon-desktop
-               shmkey = ftok("/usr/bin/drnoksnes", 'd'); // TODO Put rom file here
+               shmkey = ftok(S9xGetFilename(FILE_ROM), 'v');
                shmid = shmget(shmkey, m_w * m_h * m_Bpp, IPC_CREAT | 0777);
                if (shmid < 0) {
                        DIE("Failed to create shared memory");
@@ -768,13 +627,13 @@ class HDDummy : public DummyScaler
        HDDummy(SDL_Surface* screen, int w, int h)
        : DummyScaler(screen, w, h)
        {
-               hildon_set_non_compositing(true);
+               hd_set_non_compositing(true);
        }
        
 public:
        ~HDDummy()
        {
-               hildon_set_non_compositing(false);
+               hd_set_non_compositing(false);
        };
 
        class Factory : public ScalerFactory
@@ -809,13 +668,13 @@ class HDSW : public SWScaler
        HDSW(SDL_Surface* screen, int w, int h)
        : SWScaler(screen, w, h)
        {
-               hildon_set_non_compositing(true);
+               hd_set_non_compositing(true);
        }
        
 public:
        ~HDSW()
        {
-               hildon_set_non_compositing(false);
+               hd_set_non_compositing(false);
        };
 
        class Factory : public ScalerFactory