Changes needed to allow for SDL (and maybe others) that need a fullscreen window.

This commit is contained in:
waltje
2018-05-10 22:58:11 -04:00
parent bf676a9213
commit f018b3bc33
6 changed files with 253 additions and 164 deletions

View File

@@ -8,7 +8,7 @@
# #
# Makefile for Windows systems using the MinGW32 environment. # Makefile for Windows systems using the MinGW32 environment.
# #
# Version: @(#)Makefile.mingw 1.0.42 2018/05/09 # Version: @(#)Makefile.mingw 1.0.43 2018/05/10
# #
# Author: Fred N. van Kempen, <decwiz@yahoo.com> # Author: Fred N. van Kempen, <decwiz@yahoo.com>
# #
@@ -490,13 +490,14 @@ CXXFLAGS := $(WX_FLAGS) $(OPTS) $(DFLAGS) $(COPTIM) $(AOPTIM) \
######################################################################### #########################################################################
# Create the (final) list of objects to build. # # Create the (final) list of objects to build. #
######################################################################### #########################################################################
MAINOBJ := pc.o config.o misc.o \ MAINOBJ := pc.o config.o misc.o random.o timer.o io.o mem.o \
random.o timer.o io.o dma.o nmi.o pic.o pit.o ppi.o \ rom.o rom_load.o device.o nvr.o $(VNCOBJ) $(RDPOBJ)
pci.o mca.o mcr.o mem.o memregs.o rom.o rom_load.o \
device.o nvr.o nvr_at.o nvr_ps2.o $(VNCOBJ) $(RDPOBJ)
UIOBJ += ui_main.o ui_new_floppy.o ui_stbar.o ui_vidapi.o UIOBJ += ui_main.o ui_new_floppy.o ui_stbar.o ui_vidapi.o
SYSOBJ := dma.o nmi.o pic.o pit.o ppi.o pci.o mca.o mcr.o \
memregs.o nvr_at.o nvr_ps2.o
INTELOBJ := intel.o \ INTELOBJ := intel.o \
intel_flash.o \ intel_flash.o \
intel_sio.o \ intel_sio.o \
@@ -637,8 +638,8 @@ PLATOBJ += win_crashdump.o
endif endif
OBJ := $(MAINOBJ) $(INTELOBJ) $(CPUOBJ) $(MCHOBJ) $(DEVOBJ) \ OBJ := $(MAINOBJ) $(CPUOBJ) $(MCHOBJ) $(SYSOBJ) $(DEVOBJ) \
$(FDDOBJ) $(CDROMOBJ) $(ZIPOBJ) $(HDDOBJ) \ $(INTELOBJ) $(FDDOBJ) $(CDROMOBJ) $(ZIPOBJ) $(HDDOBJ) \
$(USBOBJ) $(NETOBJ) $(SCSIOBJ) $(SNDOBJ) $(VIDOBJ) \ $(USBOBJ) $(NETOBJ) $(SCSIOBJ) $(SNDOBJ) $(VIDOBJ) \
$(UIOBJ) $(PLATOBJ) $(FSYNTHOBJ) $(MUNTOBJ) $(DEVBROBJ) $(UIOBJ) $(PLATOBJ) $(FSYNTHOBJ) $(MUNTOBJ) $(DEVBROBJ)
ifdef EXOBJ ifdef EXOBJ
@@ -664,10 +665,6 @@ else
@echo $< @echo $<
@$(CPP) $(CXXFLAGS) -c $< @$(CPP) $(CXXFLAGS) -c $<
%.int: %.c
@echo $<
@$(PREPROC) $(OPTS) $< >$@
%.d: %.c $(wildcard $*.d) %.d: %.c $(wildcard $*.d)
@echo $< @echo $<
@$(CC) $(CFLAGS) $(DEPS) -E $< >NUL @$(CC) $(CFLAGS) $(DEPS) -E $< >NUL

View File

@@ -8,7 +8,7 @@
# #
# Makefile for Windows using Visual Studio 2015. # Makefile for Windows using Visual Studio 2015.
# #
# Version: @(#)Makefile.VC 1.0.29 2018/05/09 # Version: @(#)Makefile.VC 1.0.30 2018/05/10
# #
# Author: Fred N. van Kempen, <decwiz@yahoo.com> # Author: Fred N. van Kempen, <decwiz@yahoo.com>
# #
@@ -89,6 +89,9 @@ endif
ifndef USB ifndef USB
USB := n USB := n
endif endif
ifndef SDL
SDL := n
endif
ifndef VNC ifndef VNC
VNC := n VNC := n
endif endif
@@ -362,31 +365,64 @@ MUNTOBJ := midi_mt32.obj \
Tables.obj TVA.obj TVF.obj TVP.obj sha1.obj c_interface.obj Tables.obj TVA.obj TVF.obj TVP.obj sha1.obj c_interface.obj
endif endif
ifeq ($(SDL), y)
OPTS += -DUSE_SDL
RFLAGS += -DUSE_SDL
ifneq ($(SDL_PATH), )
OPTS += -I$(SDL_PATH)\INCLUDE\MSVC
ifeq ($(X64), y)
LOPTS += -LIBPATH:$(SDL_PATH)\LIB\MSVC\x64
else
LOPTS += -LIBPATH:$(SDL_PATH)\LIB\MSVC\x86
endif
LIBS += sdl2.lib
endif
SDLOBJ := win_sdl.obj
endif
ifeq ($(VNC), y) ifeq ($(VNC), y)
OPTS += -DUSE_VNC OPTS += -DUSE_VNC
RFLAGS += -DUSE_VNC RFLAGS += -DUSE_VNC
ifneq ($(VNC_PATH), ) ifneq ($(VNC_PATH), )
OPTS += -I$(VNC_PATH)\INCLUDE OPTS += -I$(VNC_PATH)\INCLUDE
LOPTS += $(VNC_PATH)\LIB LOPTS += LIBPATH:$(VNC_PATH)\LIB
LIBS += -lvncserver ifeq ($(X64), y)
LOPTS += \x64
else
LOPTS += \x86
endif
LIBS += libvncserver.lib
endif endif
VNCOBJ := vnc.obj vnc_keymap.obj VNCOBJ := vnc.obj vnc_keymap.obj
endif endif
ifeq ($(RDP), y) ifeq ($(RDP), y)
OPTS += -DUSE_RDP OPTS += -DUSE_RDP
RFLAGS += -DUSE_RDP RFLAGS += -DUSE_RDP
ifneq ($(RDP_PATH), ) ifneq ($(RDP_PATH), )
LOPTS += $(RDP_PATH)\LIB LOPTS += LIBPATH:$(RDP_PATH)\LIB
LIBS += -lrdpsrvr ifeq ($(X64), y)
LOPTS += \x64
else
LOPTS += \x86
endif
LIBS += rdpsrvr.lib
endif endif
RDPOBJ := rdp.obj RDPOBJ := rdp.obj
endif endif
ifeq ($(PNG), y) ifeq ($(PNG), y)
OPTS += -DUSE_LIBPNG OPTS += -DUSE_LIBPNG
RFLAGS += -DUSE_LIBPNG RFLAGS += -DUSE_LIBPNG
LIBS += libpng16.lib zlib.lib ifneq ($(PNG_PATH), )
LOPTS += LIBPATH:$(PNG_PATH)\LIB
ifeq ($(X64), y)
LOPTS += \x64
else
LOPTS += \x86
endif
endif
LIBS += libpng16.lib zlib.lib
endif endif
# Options for the DEV branch. # Options for the DEV branch.
@@ -453,19 +489,21 @@ CXXFLAGS := $(WX_FLAGS) $(OPTS) $(CXXOPTS) $(COPTS) $(DOPTS) $(AOPTIM) $(AFLAGS)
######################################################################### #########################################################################
# Create the (final) list of objects to build. # # Create the (final) list of objects to build. #
######################################################################### #########################################################################
MAINOBJ := pc.obj config.obj misc.obj \
random.obj timer.obj io.obj dma.obj nmi.obj pic.obj \
pit.obj ppi.obj pci.obj mca.obj mcr.obj mem.obj \
memregs.obj rom.obj rom_load.obj device.obj nvr.obj \
nvr_at.obj nvr_ps2.obj $(VNCOBJ) $(RDPOBJ)
UIOBJ += ui_main.obj ui_new_floppy.obj ui_stbar.obj ui_vidapi.obj MAINOBJ := pc.obj config.obj misc.obj random.obj timer.obj io.obj \
mem.obj rom.obj rom_load.obj device.obj nvr.obj \
$(SDLOBJ) $(VNCOBJ) $(RDPOBJ)
INTELOBJ := intel.obj \ INTELOBJ := intel.obj \
intel_flash.obj \ intel_flash.obj \
intel_sio.obj \ intel_sio.obj \
intel_piix.obj intel_piix4.obj intel_piix.obj intel_piix4.obj
UIOBJ += ui_main.obj ui_new_floppy.obj ui_stbar.obj ui_vidapi.obj
SYSOBJ := dma.obj nmi.obj pic.obj pit.obj ppi.obj pci.obj mca.obj \
mcr.obj memregs.obj nvr_at.obj nvr_ps2.obj
CPUOBJ := cpu.obj cpu_table.obj \ CPUOBJ := cpu.obj cpu_table.obj \
808x.obj 386.obj x86seg.obj x87.obj \ 808x.obj 386.obj x86seg.obj x87.obj \
386_dynarec.obj $(DYNARECOBJ) 386_dynarec.obj $(DYNARECOBJ)
@@ -602,8 +640,8 @@ PLATOBJ += win_crashdump.obj
endif endif
OBJ := $(MAINOBJ) $(INTELOBJ) $(CPUOBJ) $(MCHOBJ) $(DEVOBJ) \ OBJ := $(MAINOBJ) $(CPUOBJ) $(MCHOBJ) $(SYSOBJ) $(DEVOBJ) \
$(FDDOBJ) $(CDROMOBJ) $(ZIPOBJ) $(HDDOBJ) \ $(INTELOBJ) $(FDDOBJ) $(CDROMOBJ) $(ZIPOBJ) $(HDDOBJ) \
$(USBOBJ) $(NETOBJ) $(SCSIOBJ) $(SNDOBJ) $(VIDOBJ) \ $(USBOBJ) $(NETOBJ) $(SCSIOBJ) $(SNDOBJ) $(VIDOBJ) \
$(UIOBJ) $(PLATOBJ) $(FSYNTHOBJ) $(MUNTOBJ) $(DEVBROBJ) $(UIOBJ) $(PLATOBJ) $(FSYNTHOBJ) $(MUNTOBJ) $(DEVBROBJ)
ifdef EXOBJ ifdef EXOBJ
@@ -627,9 +665,6 @@ else
%.obj: %.cpp %.obj: %.cpp
@$(CPP) $(CXXFLAGS) -Fo$@ -c $< @$(CPP) $(CXXFLAGS) -Fo$@ -c $<
%.int: %.c
@$(PREPROC) $(OPTS) -Fo$@ $<
%.d: %.c $(wildcard $*.d) %.d: %.c $(wildcard $*.d)
$(MCPP) $(OPTS) $(DEPS) $< >NUL $(MCPP) $(OPTS) $(DEPS) $< >NUL

View File

@@ -8,7 +8,7 @@
* *
* Platform main support module for Windows. * Platform main support module for Windows.
* *
* Version: @(#)win.c 1.0.11 2018/05/09 * Version: @(#)win.c 1.0.12 2018/05/10
* *
* Authors: Fred N. van Kempen, <decwiz@yahoo.com> * Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>
@@ -56,7 +56,7 @@
#define GLOBAL #define GLOBAL
#include "../plat.h" #include "../plat.h"
#ifdef USE_SDL #ifdef USE_SDL
# include "../sdl.h" # include "win_sdl.h"
#endif #endif
#ifdef USE_VNC #ifdef USE_VNC
# include "../vnc.h" # include "../vnc.h"

View File

@@ -8,7 +8,7 @@
* *
* Platform support defintions for Win32. * Platform support defintions for Win32.
* *
* Version: @(#)win.h 1.0.13 2018/05/09 * Version: @(#)win.h 1.0.14 2018/05/10
* *
* Authors: Fred N. van Kempen, <decwiz@yahoo.com> * Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>
@@ -108,6 +108,7 @@ extern int fdd_type_icon(int type);
/* Platform UI support functions. */ /* Platform UI support functions. */
extern int ui_init(int nCmdShow); extern int ui_init(int nCmdShow);
extern void ui_menu_update(void); extern void ui_menu_update(void);
extern void plat_set_input(HWND h);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -8,7 +8,7 @@
* *
* Windows raw keyboard input handler. * Windows raw keyboard input handler.
* *
* Version: @(#)win_keyboard.c 1.0.6 2018/05/06 * Version: @(#)win_keyboard.c 1.0.7 2018/05/10
* *
* Authors: Fred N. van Kempen, <decwiz@yahoo.com> * Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>
@@ -52,8 +52,10 @@
static uint16_t scancode_map[768]; static uint16_t scancode_map[768];
/* This is so we can disambiguate scan codes that would otherwise conflict and get /*
passed on incorrectly. */ * This is so we can disambiguate scan codes that would otherwise
* conflict and get passed on incorrectly.
*/
static UINT16 static UINT16
convert_scan_code(UINT16 code) convert_scan_code(UINT16 code)
{ {
@@ -131,113 +133,124 @@ void
keyboard_handle(LPARAM lParam, int focus) keyboard_handle(LPARAM lParam, int focus)
{ {
static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0; static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0;
uint32_t ri_size = 0; uint32_t ri_size;
UINT size; RAWKEYBOARD rawKB;
UINT size = 0;
RAWINPUT *raw; RAWINPUT *raw;
USHORT code; USHORT code;
if (! focus) return; if (! focus) return;
/* See how much data the RI has for us, and allocate a buffer. */
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL,
&size, sizeof(RAWINPUTHEADER)); &size, sizeof(RAWINPUTHEADER));
raw = (RAWINPUT *)malloc(size);
if (raw == NULL) {
pclog("KBD: out of memory for Raw Input buffer!\n");
return;
}
raw = malloc(size); /* Read the event buffer from RI. */
if (raw == NULL) return;
/* Here we read the raw input data for the keyboard */
ri_size = GetRawInputData((HRAWINPUT)(lParam), RID_INPUT, ri_size = GetRawInputData((HRAWINPUT)(lParam), RID_INPUT,
raw, &size, sizeof(RAWINPUTHEADER)); raw, &size, sizeof(RAWINPUTHEADER));
if (ri_size != size) return; if (ri_size != size) {
pclog("KBD: bad event buffer %d/%d\n", size, ri_size);
return;
}
/* If the input is keyboard, we process it */ /* We only process keyboard events. */
if (raw->header.dwType == RIM_TYPEKEYBOARD) { if (raw->header.dwType != RIM_TYPEKEYBOARD) {
RAWKEYBOARD rawKB = raw->data.keyboard; free(raw);
code = rawKB.MakeCode; return;
}
/* If it's not a scan code that starts with 0xE1 */ rawKB = raw->data.keyboard;
if (!(rawKB.Flags & RI_KEY_E1)) { code = rawKB.MakeCode;
if (rawKB.Flags & RI_KEY_E0)
code |= (0xE0 << 8);
/* Translate the scan code to 9-bit */ /* If it's not a scan code that starts with 0xE1 */
code = convert_scan_code(code); if (!(rawKB.Flags & RI_KEY_E1)) {
if (rawKB.Flags & RI_KEY_E0)
code |= (0xE0 << 8);
/* Remap it according to the list from the Registry */ /* Translate the scan code to 9-bit */
/* pclog("Scan code: %04X (map: %04X)\n", code, scancode_map[code]); */ code = convert_scan_code(code);
code = scancode_map[code];
/* If it's not 0xFFFF, send it to the emulated /* Remap it according to the list from the Registry */
keyboard. #if 0
We use scan code 0xFFFF to mean a mapping that pclog("Scan code: %04X (map: %04X)\n", code, scancode_map[code]);
has a prefix other than E0 and that is not E1 1D, #endif
which is, for our purposes, invalid. */ code = scancode_map[code];
if ((code == 0x00F) &&
!(rawKB.Flags & RI_KEY_BREAK) &&
(recv_lalt || recv_ralt) &&
!mouse_capture) {
/* We received a TAB while ALT was pressed, while the mouse
is not captured, suppress the TAB and send an ALT key up. */
if (recv_lalt) {
keyboard_input(0, 0x038);
/* Extra key press and release so the guest is not stuck in the
menu bar. */
keyboard_input(1, 0x038);
keyboard_input(0, 0x038);
recv_lalt = 0;
}
if (recv_ralt) {
keyboard_input(0, 0x138);
/* Extra key press and release so the guest is not stuck in the
menu bar. */
keyboard_input(1, 0x138);
keyboard_input(0, 0x138);
recv_ralt = 0;
}
} else if (((code == 0x038) || (code == 0x138)) &&
!(rawKB.Flags & RI_KEY_BREAK) &&
recv_tab &&
!mouse_capture) {
/* We received an ALT while TAB was pressed, while the mouse
is not captured, suppress the ALT and send a TAB key up. */
keyboard_input(0, 0x00F);
recv_tab = 0;
} else {
switch(code) {
case 0x00F:
recv_tab = !(rawKB.Flags & RI_KEY_BREAK);
break;
case 0x038:
recv_lalt = !(rawKB.Flags & RI_KEY_BREAK);
break;
case 0x138:
recv_ralt = !(rawKB.Flags & RI_KEY_BREAK);
break;
}
/* Translate right CTRL to left ALT if the user has so /*
chosen. */ * If it's not 0xFFFF, send it to the emulated keyboard.
if ((code == 0x11D) && rctrl_is_lalt) * We use scan code 0xFFFF to mean a mapping that
code = 0x038; * has a prefix other than E0 and that is not E1 1D,
* which is, for our purposes, invalid.
/* Normal scan code pass through, pass it through as is if */
it's not an invalid scan code. */ if ((code == 0x00F) && !(rawKB.Flags & RI_KEY_BREAK) &&
if (code != 0xFFFF) (recv_lalt || recv_ralt) && !mouse_capture) {
keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), code); /* We received a TAB while ALT was pressed, while the mouse
is not captured, suppress the TAB and send an ALT key up. */
if (recv_lalt) {
keyboard_input(0, 0x038);
/* Extra key press and release so the guest is not stuck in the
menu bar. */
keyboard_input(1, 0x038);
keyboard_input(0, 0x038);
recv_lalt = 0;
} }
if (recv_ralt) {
keyboard_input(0, 0x138);
/* Extra key press and release so the guest is not stuck in the
menu bar. */
keyboard_input(1, 0x138);
keyboard_input(0, 0x138);
recv_ralt = 0;
}
} else if (((code == 0x038) || (code == 0x138)) &&
!(rawKB.Flags & RI_KEY_BREAK) && recv_tab && !mouse_capture) {
/* We received an ALT while TAB was pressed, while the mouse
is not captured, suppress the ALT and send a TAB key up. */
keyboard_input(0, 0x00F);
recv_tab = 0;
} else { } else {
if (rawKB.MakeCode == 0x1D) { switch(code) {
/* Translate E1 1D to 0x100 (which would case 0x00F:
otherwise be E0 00 but that is invalid recv_tab = !(rawKB.Flags & RI_KEY_BREAK);
anyway). break;
Also, take a potential mapping into
account. */
code = scancode_map[0x100];
} else
code = 0xFFFF;
case 0x038:
recv_lalt = !(rawKB.Flags & RI_KEY_BREAK);
break;
case 0x138:
recv_ralt = !(rawKB.Flags & RI_KEY_BREAK);
break;
}
/* Translate right CTRL to left ALT if the user has so
chosen. */
if ((code == 0x11D) && rctrl_is_lalt)
code = 0x038;
/* Normal scan code pass through, pass it through as is if
it's not an invalid scan code. */
if (code != 0xFFFF) if (code != 0xFFFF)
keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), code); keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), code);
} }
} else {
if (rawKB.MakeCode == 0x1D) {
/* Translate E1 1D to 0x100 (which would
otherwise be E0 00 but that is invalid
anyway).
Also, take a potential mapping into
account. */
code = scancode_map[0x100];
} else
code = 0xFFFF;
if (code != 0xFFFF)
keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), code);
} }
free(raw); free(raw);

View File

@@ -8,7 +8,7 @@
* *
* Implement the user Interface module. * Implement the user Interface module.
* *
* Version: @(#)win_ui.c 1.0.22 2018/05/09 * Version: @(#)win_ui.c 1.0.23 2018/05/10
* *
* Authors: Fred N. van Kempen, <decwiz@yahoo.com> * Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>
@@ -76,7 +76,6 @@ int infocus = 1;
/* Local data. */ /* Local data. */
static wchar_t wTitle[512]; static wchar_t wTitle[512];
static RAWINPUTDEVICE device;
static HHOOK hKeyboardHook; static HHOOK hKeyboardHook;
static LONG_PTR OriginalProcedure; static LONG_PTR OriginalProcedure;
static HWND hwndSBAR = NULL; /* application status bar */ static HWND hwndSBAR = NULL; /* application status bar */
@@ -337,30 +336,6 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
return(0); return(0);
case WM_INPUT:
keyboard_handle(lParam, infocus);
break;
case WM_SETFOCUS:
infocus = 1;
if (! hook_enabled) {
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
LowLevelKeyboardProc,
GetModuleHandle(NULL),
0);
hook_enabled = 1;
}
break;
case WM_KILLFOCUS:
infocus = 0;
plat_mouse_capture(0);
if (hook_enabled) {
UnhookWindowsHookEx(hKeyboardHook);
hook_enabled = 0;
}
break;
case WM_LBUTTONUP: case WM_LBUTTONUP:
if (! vid_fullscreen) if (! vid_fullscreen)
plat_mouse_capture(1); plat_mouse_capture(1);
@@ -517,6 +492,7 @@ ui_init(int nCmdShow)
{ {
WCHAR title[200]; WCHAR title[200];
WNDCLASSEX wincl; /* buffer for main window's class */ WNDCLASSEX wincl; /* buffer for main window's class */
RAWINPUTDEVICE ridev; /* RawInput device */
MSG messages; /* received-messages buffer */ MSG messages; /* received-messages buffer */
HACCEL haccel; /* handle to accelerator table */ HACCEL haccel; /* handle to accelerator table */
DWORD flags; DWORD flags;
@@ -616,6 +592,21 @@ ui_init(int nCmdShow)
/* Make the window visible on the screen. */ /* Make the window visible on the screen. */
ShowWindow(hwndMain, nCmdShow); ShowWindow(hwndMain, nCmdShow);
/* Initialize the RawInput (keyboard) module. */
memset(&ridev, 0x00, sizeof(ridev));
ridev.usUsagePage = 0x01;
ridev.usUsage = 0x06;
ridev.dwFlags = RIDEV_NOHOTKEYS;
ridev.hwndTarget = NULL; /* current focus window */
if (! RegisterRawInputDevices(&ridev, 1, sizeof(ridev))) {
ui_msgbox(MBX_CONFIG, (wchar_t *)IDS_2154);
return(4);
}
keyboard_getkeymap();
/* Set up the main window for RawInput. */
plat_set_input(hwndMain);
/* Create the Machine Rendering window. */ /* Create the Machine Rendering window. */
hwndRender = CreateWindow(L"STATIC", hwndRender = CreateWindow(L"STATIC",
NULL, NULL,
@@ -684,17 +675,6 @@ again:
/* Create the status bar window. */ /* Create the status bar window. */
StatusBarCreate(IDC_STATBAR); StatusBarCreate(IDC_STATBAR);
/* Initialize the input (keyboard, mouse, game) module. */
device.usUsagePage = 0x01;
device.usUsage = 0x06;
device.dwFlags = RIDEV_NOHOTKEYS;
device.hwndTarget = hwndMain;
if (! RegisterRawInputDevices(&device, 1, sizeof(device))) {
ui_msgbox(MBX_CONFIG, (wchar_t *)IDS_2154);
return(4);
}
keyboard_getkeymap();
/* Initialize the mouse module. */ /* Initialize the mouse module. */
win_mouse_init(); win_mouse_init();
@@ -760,6 +740,69 @@ again:
} }
/* Catch WM_INPUT messages for 'current focus' window. */
static LONG_PTR input_orig_proc;
static HWND input_orig_hwnd = NULL;
#ifdef __amd64__
static LRESULT CALLBACK
#else
static BOOL CALLBACK
#endif
input_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_INPUT:
pclog("UI: hwnd=%08lx WM_INPUT (infocus=%d) !\n", hwnd, infocus);
keyboard_handle(lParam, infocus);
break;
case WM_SETFOCUS:
pclog("UI: hwnd=%08lx WM_SETFOCUS (infocus=%d) !\n", hwnd, infocus);
infocus = 1;
if (! hook_enabled) {
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
LowLevelKeyboardProc,
GetModuleHandle(NULL),
0);
hook_enabled = 1;
}
break;
case WM_KILLFOCUS:
pclog("UI: hwnd=%08lx WM_KILLFOCUS (infocus=%d) !\n", hwnd, infocus);
infocus = 0;
plat_mouse_capture(0);
if (hook_enabled) {
UnhookWindowsHookEx(hKeyboardHook);
hook_enabled = 0;
}
break;
default:
return(CallWindowProc((WNDPROC)input_orig_proc,
hwnd, message, wParam, lParam));
}
return(0);
}
void
plat_set_input(HWND h)
{
/* If needed, rest the old one first. */
if (input_orig_hwnd != NULL) {
SetWindowLongPtr(input_orig_hwnd, GWL_WNDPROC,
(LONG_PTR)input_orig_proc);
}
/* Redirect the window procedure so we can catch WM_INPUT. */
input_orig_proc = GetWindowLongPtr(h, GWLP_WNDPROC);
input_orig_hwnd = h;
SetWindowLongPtr(h, GWL_WNDPROC, (LONG_PTR)input_proc);
}
/* Tell the UI about a new screen resolution. */ /* Tell the UI about a new screen resolution. */
void void
ui_resize(int x, int y) ui_resize(int x, int y)