#include <libgen.h>
#include <hgw/hgw.h>
+#include "snes9x.h"
+
+#include <glib.h>
+#include <gconf/gconf.h>
+#include <gconf/gconf-client.h>
+
#include "platform.h"
#include "hgw.h"
-#include "snes9x.h"
+#include "../gui/gconf.h"
#define DIE(format, ...) do { \
fprintf(stderr, "Died at %s:%d: ", __FILE__, __LINE__ ); \
abort(); \
} while (0);
-
bool hgwLaunched;
static HgwContext *hgw;
static void createActionMappingsOnly();
-static void parseGConfKeyMappings();
+static void parseGConfKeyMappings(GConfClient* gcc);
void HgwInit()
{
// hildon-games-wrapper sets this env variable for itself.
char* service = getenv("HGW_EXEC_SERVICE");
-
+
if (!service) {
// Not launched from hildon-games-wrapper
hgwLaunched = false;
return;
}
-
+
+ g_type_init();
hgw = hgw_context_init();
-
+
if (!hgw) {
fprintf(stderr, "Error opening hgw context\n");
hgwLaunched = false;
}
-
+
hgwLaunched = true;
printf("Loading in HGW mode\n");
}
void HgwConfig()
{
if (!hgwLaunched) return;
-
+
+ GConfClient *gcc = gconf_client_get_default();
+
Config.fullscreen = true;
-
+
char romFile[PATH_MAX + 1];
- if (hgw_conf_request_string(hgw, kGConfRomFile, romFile) == HGW_ERR_NONE) {
+ if (hgw_conf_request_string(hgw, kGConfRomFile, romFile) == HGW_ERR_NONE
+ && strlen(romFile) > 0) {
S9xSetRomFile(romFile);
} else {
- hgw_context_destroy(hgw, HGW_BYE_INACTIVE);
- DIE("No Rom in Gconf!");
+ printf("Exiting gracefully because there's no ROM in Gconf\n");
+ HgwDeinit();
+ exit(0);
}
char sound = FALSE;
Settings.Transparency = transparency ? TRUE : FALSE;
}
-#if CONF_XSP
- char xsp = TRUE;
- if (hgw_conf_request_bool(hgw, kGConfXSP, &xsp) == HGW_ERR_NONE) {
- if (!xsp) {
- free(Config.scaler);
- Config.scaler = strdup("2x");
- }
+ char scaler[NAME_MAX];
+ if (hgw_conf_request_string(hgw, kGConfScaler, scaler) == HGW_ERR_NONE
+ && strlen(scaler) > 0) {
+ free(Config.scaler);
+ Config.scaler = strdup(scaler);
}
-#endif
char displayFramerate = FALSE;
if (hgw_conf_request_bool(hgw, kGConfDisplayFramerate, &displayFramerate) == HGW_ERR_NONE) {
Settings.DisplayFrameRate = displayFramerate ? TRUE : FALSE;
}
+#if TODO
char displayControls = FALSE;
if (hgw_conf_request_bool(hgw, kGConfDisplayControls, &displayControls) == HGW_ERR_NONE) {
Config.touchscreenShow = displayControls ? true : false;
}
+#endif
int speedhacks = 0;
if (hgw_conf_request_int(hgw, kGConfSpeedhacks, &speedhacks) == HGW_ERR_NONE) {
< 0) {
Config.hacksFile = 0; // malloc error.
}
- // romFile[] is garbled from now on.
+ // remember that dirname garbles romFile.
}
- int mappings = 0;
- if (hgw_conf_request_int(hgw, kGConfMapping, &mappings) == HGW_ERR_NONE) {
- switch (mappings) {
- case 0:
- // Do nothing, leave mappings as is.
- break;
- case 1: // Keys
- parseGConfKeyMappings();
- break;
- case 2: // Touchscreen
- Config.touchscreenInput = true;
- createActionMappingsOnly();
- break;
- case 3: // Touchscreen + keys
- Config.touchscreenInput = true;
- parseGConfKeyMappings();
- break;
- case 4: // Mouse
- Settings.Mouse = TRUE;
- Settings.ControllerOption = SNES_MOUSE_SWAPPED;
- createActionMappingsOnly();
- break;
- case 5: // Mouse + keys
- Settings.Mouse = TRUE;
- Settings.ControllerOption = SNES_MOUSE;
- parseGConfKeyMappings();
- break;
- }
+ gchar key[kGConfPlayerPathBufferLen];
+ gchar *relKey = key + sprintf(key, kGConfPlayerPath, 1);
+
+ strcpy(relKey, kGConfPlayerKeyboardEnable);
+ if (gconf_client_get_bool(gcc, key, NULL)) {
+ parseGConfKeyMappings(gcc);
+ } else {
+ createActionMappingsOnly();
}
HgwStartCommand cmd = hgw_context_get_start_command(hgw);
Config.quitting = true;
break;
}
+
+ g_object_unref(G_OBJECT(gcc));
}
void HgwPollEvents()
// For now, please keep this in sync with ../gui/controls.c
typedef struct ButtonEntry {
- char * gconf_key;
+ const char * gconf_key;
unsigned long mask;
bool is_action;
} ButtonEntry;
{ kGConfKeysPath "/" name, kAction##action, true }
#define BUTTON_LAST \
{ 0 }
+
static const ButtonEntry buttons[] = {
- BUTTON_INITIALIZER(A, "a"),
- BUTTON_INITIALIZER(B, "b"),
- BUTTON_INITIALIZER(X, "x"),
- BUTTON_INITIALIZER(Y, "y"),
- BUTTON_INITIALIZER(TL, "l"),
- BUTTON_INITIALIZER(TR, "r"),
- BUTTON_INITIALIZER(START, "start"),
- BUTTON_INITIALIZER(SELECT, "select"),
- BUTTON_INITIALIZER(UP, "up"),
- BUTTON_INITIALIZER(DOWN, "down"),
- BUTTON_INITIALIZER(LEFT, "left"),
- BUTTON_INITIALIZER(RIGHT, "right"),
- ACTION_INITIALIZER(Quit, "quit"),
- ACTION_INITIALIZER(ToggleFullscreen, "fullscreen"),
- ACTION_INITIALIZER(QuickLoad1, "quickload1"),
- ACTION_INITIALIZER(QuickSave1, "quicksave1"),
- ACTION_INITIALIZER(QuickLoad2, "quickload2"),
- ACTION_INITIALIZER(QuickSave2, "quicksave2"),
- BUTTON_LAST
+#define HELP(...)
+#define P(x) SNES_##x##_MASK
+#define A(x) kAction##x
+#define BUTTON(description, slug, actions, d, f) \
+ { G_STRINGIFY(slug), actions, false },
+#define ACTION(description, slug, actions, d, f) \
+ { G_STRINGIFY(slug), actions, true },
+#define LAST \
+ { 0 }
+#include "../gui/buttons.inc"
+#undef HELP
+#undef P
+#undef A
+#undef BUTTON
+#undef ACTION
+#undef LAST
};
static void createActionMappingsOnly()
{
- // Discard any other mapping
- ZeroMemory(Config.joypad1Mapping, sizeof(Config.joypad1Mapping));
- ZeroMemory(Config.action, sizeof(Config.action));
-
// Map quit to fullscreen, escape and task switch.
Config.action[72] = kActionQuit;
Config.action[9] = kActionQuit;
Config.action[71] = kActionQuit;
}
-static void parseGConfKeyMappings()
+static void parseGConfKeyMappings(GConfClient* gcc)
{
- // Discard any other mapping
- ZeroMemory(Config.joypad1Mapping, sizeof(Config.joypad1Mapping));
- ZeroMemory(Config.action, sizeof(Config.action));
+ // Build player 1 keyboard gconf key relative path
+ gchar key[kGConfPlayerPathBufferLen];
+ gchar *relKey = key + sprintf(key,
+ kGConfPlayerPath kGConfPlayerKeyboardPath "/", 1);
// If the user does not map fullscreen or quit
bool quit_mapped = false;
printf("Hgw: Using gconf key mappings\n");
+ // Thus ignoring config file key mappings
+ ZeroMemory(Config.joypad1Mapping, sizeof(Config.joypad1Mapping));
+ ZeroMemory(Config.action, sizeof(Config.action));
int i, scancode;
for (i = 0; buttons[i].gconf_key; i++) {
- if (hgw_conf_request_int(hgw, buttons[i].gconf_key, &scancode) == HGW_ERR_NONE) {
- if (scancode <= 0 || scancode > 255) continue;
+ strcpy(relKey, buttons[i].gconf_key);
+ scancode = gconf_client_get_int(gcc, key, NULL);
- if (buttons[i].is_action) {
- Config.action[scancode] |= buttons[i].mask;
- if (buttons[i].mask & (kActionQuit | kActionToggleFullscreen)) {
- quit_mapped = true;
- }
- } else {
- Config.joypad1Mapping[scancode] |= buttons[i].mask;
+ if (scancode <= 0 || scancode > 255) continue;
+
+ if (buttons[i].is_action) {
+ Config.action[scancode] |= buttons[i].mask;
+ if (buttons[i].mask & (kActionQuit | kActionToggleFullscreen)) {
+ quit_mapped = true;
}
+ } else {
+ Config.joypad1Mapping[scancode] |= buttons[i].mask;
}
}
+#if MAEMO && !CONF_EXIT_BUTTON
// Safeguards
if (!quit_mapped) {
// Newbie user won't know how to quit game.
if (!Config.action[71] && !Config.joypad1Mapping[71]) {
Config.action[71] = kActionQuit;
}
+#endif
}