ref: d4863b4c4ac47766b5fd3b8b0949be7af792e3d0
parent: a3b1c4e95cf3d8196858f5c98a92565eedbc1e48
author: Simon Howard <[email protected]>
date: Fri Jun 12 15:07:55 EDT 2009
On Windows CE systems without a keyboard, patch the default settings to use hardware keys. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1600
--- a/setup/configfile.c
+++ b/setup/configfile.c
@@ -35,6 +35,8 @@
#ifdef _WIN32
#include <io.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
#else
#include <sys/stat.h>
#include <sys/types.h>
@@ -645,5 +647,79 @@
// Restore the normal filename
extra_defaults.filename = main_filename;
+}
+
+#ifdef _WIN32_WCE
+
+static int SystemHasKeyboard(void)
+{
+ HKEY key;
+ DWORD valtype;
+ DWORD valsize;
+ DWORD result;
+
+ if (RegOpenKeyExW(HKEY_CURRENT_USER,
+ L"\\Software\\Microsoft\\Shell", 0,
+ KEY_READ, &key) != ERROR_SUCCESS)
+ {
+ return 0;
+ }
+
+ valtype = REG_SZ;
+ valsize = sizeof(DWORD);
+
+ if (RegQueryValueExW(key, L"HasKeyboard", NULL, &valtype,
+ (LPBYTE) &result, &valsize) != ERROR_SUCCESS)
+ {
+ result = 0;
+ }
+
+ // Close the key
+
+ RegCloseKey(key);
+
+ return result;
+}
+
+//
+// Apply custom defaults for Windows CE.
+//
+
+static void M_ApplyWindowsCEDefaults(void)
+{
+ // If the system doesn't have a keyboard, patch the default
+ // configuration to use the hardware keys.
+
+ if (!SystemHasKeyboard())
+ {
+ key_use = KEY_F1;
+ key_fire = KEY_F2;
+ key_menu_activate = KEY_F3;
+ key_map_toggle = KEY_F4;
+
+ key_menu_help = 0;
+ key_menu_save = 0;
+ key_menu_load = 0;
+ key_menu_volume = 0;
+
+ key_menu_confirm = KEY_ENTER;
+ key_menu_back = KEY_F2;
+ key_menu_abort = KEY_F2;
+ }
+}
+
+
+#endif
+
+//
+// Apply custom patches to the default values depending on the
+// platform we are running on.
+//
+
+void M_ApplyPlatformDefaults(void)
+{
+#ifdef _WIN32_WCE
+ M_ApplyWindowsCEDefaults();
+#endif
}
--- a/setup/configfile.h
+++ b/setup/configfile.h
@@ -38,5 +38,7 @@
void M_SaveMainDefaults(char *filename);
void M_SaveExtraDefaults(char *filename);
+void M_ApplyPlatformDefaults(void);
+
#endif
--- a/setup/mainmenu.c
+++ b/setup/mainmenu.c
@@ -143,6 +143,8 @@
static void InitConfig(void)
{
+ M_ApplyPlatformDefaults();
+
SetChatMacroDefaults();
SetPlayerNameDefault();
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -974,6 +974,7 @@
V_Init ();
printf (DEH_String("M_LoadDefaults: Load system defaults.\n"));
+ M_ApplyPlatformDefaults();
M_LoadDefaults (); // load before initing other systems
printf (DEH_String("W_Init: Init WADfiles.\n"));
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -31,6 +31,11 @@
#include <ctype.h>
#include <errno.h>
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif
+
#include "config.h"
#include "deh_main.h"
#include "doomdef.h"
@@ -1378,5 +1383,78 @@
configdir = strdup("");
}
}
+}
+
+#ifdef _WIN32_WCE
+
+static int SystemHasKeyboard(void)
+{
+ HKEY key;
+ DWORD valtype;
+ DWORD valsize;
+ DWORD result;
+
+ if (RegOpenKeyExW(HKEY_CURRENT_USER,
+ L"\\Software\\Microsoft\\Shell", 0,
+ KEY_READ, &key) != ERROR_SUCCESS)
+ {
+ return 0;
+ }
+
+ valtype = REG_SZ;
+ valsize = sizeof(DWORD);
+
+ if (RegQueryValueExW(key, L"HasKeyboard", NULL, &valtype,
+ (LPBYTE) &result, &valsize) != ERROR_SUCCESS)
+ {
+ result = 0;
+ }
+
+ // Close the key
+
+ RegCloseKey(key);
+
+ return result;
+}
+
+//
+// Apply custom defaults for Windows CE.
+//
+
+static void M_ApplyWindowsCEDefaults(void)
+{
+ // If the system doesn't have a keyboard, patch the default
+ // configuration to use the hardware keys.
+
+ if (!SystemHasKeyboard())
+ {
+ key_use = KEY_F1;
+ key_fire = KEY_F2;
+ key_menu_activate = KEY_F3;
+ key_map_toggle = KEY_F4;
+
+ key_menu_help = 0;
+ key_menu_save = 0;
+ key_menu_load = 0;
+ key_menu_volume = 0;
+
+ key_menu_confirm = KEY_ENTER;
+ key_menu_back = KEY_F2;
+ key_menu_abort = KEY_F2;
+ }
+}
+
+#endif
+
+//
+// Apply custom patches to the default values depending on the
+// platform we are running on.
+//
+
+void M_ApplyPlatformDefaults(void)
+{
+#ifdef _WIN32_WCE
+ M_ApplyWindowsCEDefaults();
+#endif
}
--- a/src/m_config.h
+++ b/src/m_config.h
@@ -31,6 +31,7 @@
void M_LoadDefaults(void);
void M_SaveDefaults(void);
void M_SetConfigDir(void);
+void M_ApplyPlatformDefaults(void);
extern char *configdir;