ref: 68d27f05262b7928b4d755d2e27868cfc51b3007
parent: 8f1c713735316422cfe041400ccc49999d563d8b
author: Simon Tatham <anakin@pobox.com>
date: Thu May 12 14:25:57 EDT 2005
I've had two complaints that Solo ought to recognise the numeric keypad. The reason it doesn't is because front ends were carefully translating the numeric keypad into 8-way directional keys for the benefit of Cube. Therefore, a policy change: - front ends process the numeric keypad by sending MOD_NUM_KEYPAD | '3' and similar - front ends running on a platform with Num Lock SHOULD do this _irrespective_ of the state of Num Lock - back ends do whatever they see fit with numeric keypad keys. Result: the numeric keypad now works in Solo, and also works in OS X Cube (which it previously didn't because I forgot to implement that bit of the front end!). [originally from svn r5774]
--- a/cube.c
+++ b/cube.c
@@ -1017,23 +1017,23 @@
struct solid *poly;
/*
- * All moves are made with the cursor keys.
+ * All moves are made with the cursor keys or numeric keypad.
*/
- if (button == CURSOR_UP)
+ if (button == CURSOR_UP || button == (MOD_NUM_KEYPAD | '8'))
direction = UP;
- else if (button == CURSOR_DOWN)
+ else if (button == CURSOR_DOWN || button == (MOD_NUM_KEYPAD | '2'))
direction = DOWN;
- else if (button == CURSOR_LEFT)
+ else if (button == CURSOR_LEFT || button == (MOD_NUM_KEYPAD | '4'))
direction = LEFT;
- else if (button == CURSOR_RIGHT)
+ else if (button == CURSOR_RIGHT || button == (MOD_NUM_KEYPAD | '6'))
direction = RIGHT;
- else if (button == CURSOR_UP_LEFT)
+ else if (button == (MOD_NUM_KEYPAD | '7'))
direction = UP_LEFT;
- else if (button == CURSOR_DOWN_LEFT)
+ else if (button == (MOD_NUM_KEYPAD | '1'))
direction = DOWN_LEFT;
- else if (button == CURSOR_UP_RIGHT)
+ else if (button == (MOD_NUM_KEYPAD | '9'))
direction = UP_RIGHT;
- else if (button == CURSOR_DOWN_RIGHT)
+ else if (button == (MOD_NUM_KEYPAD | '3'))
direction = DOWN_RIGHT;
else
return NULL;
--- a/gtk.c
+++ b/gtk.c
@@ -321,28 +321,36 @@
if (!fe->pixmap)
return TRUE;
- if (event->string[0] && !event->string[1])
- keyval = (unsigned char)event->string[0];
- else if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up ||
- event->keyval == GDK_KP_8)
+ if (event->keyval == GDK_Up)
keyval = CURSOR_UP;
- else if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down ||
- event->keyval == GDK_KP_2)
+ else if (event->keyval == GDK_KP_Up || event->keyval == GDK_KP_8)
+ keyval = MOD_NUM_KEYPAD | '8';
+ else if (event->keyval == GDK_Down)
keyval = CURSOR_DOWN;
- else if (event->keyval == GDK_Left || event->keyval == GDK_KP_Left ||
- event->keyval == GDK_KP_4)
+ else if (event->keyval == GDK_KP_Down || event->keyval == GDK_KP_2)
+ keyval = MOD_NUM_KEYPAD | '2';
+ else if (event->keyval == GDK_Left)
keyval = CURSOR_LEFT;
- else if (event->keyval == GDK_Right || event->keyval == GDK_KP_Right ||
- event->keyval == GDK_KP_6)
+ else if (event->keyval == GDK_KP_Left || event->keyval == GDK_KP_4)
+ keyval = MOD_NUM_KEYPAD | '4';
+ else if (event->keyval == GDK_Right)
keyval = CURSOR_RIGHT;
+ else if (event->keyval == GDK_KP_Right || event->keyval == GDK_KP_6)
+ keyval = MOD_NUM_KEYPAD | '6';
else if (event->keyval == GDK_KP_Home || event->keyval == GDK_KP_7)
- keyval = CURSOR_UP_LEFT;
+ keyval = MOD_NUM_KEYPAD | '7';
else if (event->keyval == GDK_KP_End || event->keyval == GDK_KP_1)
- keyval = CURSOR_DOWN_LEFT;
+ keyval = MOD_NUM_KEYPAD | '1';
else if (event->keyval == GDK_KP_Page_Up || event->keyval == GDK_KP_9)
- keyval = CURSOR_UP_RIGHT;
+ keyval = MOD_NUM_KEYPAD | '9';
else if (event->keyval == GDK_KP_Page_Down || event->keyval == GDK_KP_3)
- keyval = CURSOR_DOWN_RIGHT;
+ keyval = MOD_NUM_KEYPAD | '3';
+ else if (event->keyval == GDK_KP_Insert || event->keyval == GDK_KP_0)
+ keyval = MOD_NUM_KEYPAD | '0';
+ else if (event->keyval == GDK_KP_Begin || event->keyval == GDK_KP_5)
+ keyval = MOD_NUM_KEYPAD | '5';
+ else if (event->string[0] && !event->string[1])
+ keyval = (unsigned char)event->string[0];
else
keyval = -1;
--- a/osx.m
+++ b/osx.m
@@ -515,6 +515,9 @@
}
}
+ if (c >= '0' && c <= '9' && ([ev modifierFlags] & NSNumericPadKeyMask))
+ c |= MOD_NUM_KEYPAD;
+
[self processButton:c x:-1 y:-1];
}
}
--- a/puzzles.h
+++ b/puzzles.h
@@ -31,10 +31,8 @@
CURSOR_DOWN,
CURSOR_LEFT,
CURSOR_RIGHT,
- CURSOR_UP_LEFT,
- CURSOR_DOWN_LEFT,
- CURSOR_UP_RIGHT,
- CURSOR_DOWN_RIGHT
+
+ MOD_NUM_KEYPAD = 0x40000000
};
#define IS_MOUSE_DOWN(m) ( (unsigned)((m) - LEFT_BUTTON) <= \
--- a/solo.c
+++ b/solo.c
@@ -1781,6 +1781,8 @@
int tx, ty;
game_state *ret;
+ button &= ~MOD_NUM_KEYPAD; /* we treat this the same as normal */
+
tx = (x + TILE_SIZE - BORDER) / TILE_SIZE - 1;
ty = (y + TILE_SIZE - BORDER) / TILE_SIZE - 1;
--- a/windows.c
+++ b/windows.c
@@ -1035,36 +1035,64 @@
int key = -1;
switch (wParam) {
- case VK_LEFT: key = CURSOR_LEFT; break;
- case VK_RIGHT: key = CURSOR_RIGHT; break;
- case VK_UP: key = CURSOR_UP; break;
- case VK_DOWN: key = CURSOR_DOWN; break;
+ case VK_LEFT:
+ if (!(lParam & 0x01000000))
+ key = MOD_NUM_KEYPAD | '4';
+ else
+ key = CURSOR_LEFT;
+ break;
+ case VK_RIGHT:
+ if (!(lParam & 0x01000000))
+ key = MOD_NUM_KEYPAD | '6';
+ else
+ key = CURSOR_RIGHT;
+ break;
+ case VK_UP:
+ if (!(lParam & 0x01000000))
+ key = MOD_NUM_KEYPAD | '8';
+ else
+ key = CURSOR_UP;
+ break;
+ case VK_DOWN:
+ if (!(lParam & 0x01000000))
+ key = MOD_NUM_KEYPAD | '2';
+ else
+ key = CURSOR_DOWN;
+ break;
/*
* Diagonal keys on the numeric keypad.
*/
case VK_PRIOR:
- if (!(lParam & 0x01000000)) key = CURSOR_UP_RIGHT;
+ if (!(lParam & 0x01000000)) key = MOD_NUM_KEYPAD | '9';
break;
case VK_NEXT:
- if (!(lParam & 0x01000000)) key = CURSOR_DOWN_RIGHT;
+ if (!(lParam & 0x01000000)) key = MOD_NUM_KEYPAD | '3';
break;
case VK_HOME:
- if (!(lParam & 0x01000000)) key = CURSOR_UP_LEFT;
+ if (!(lParam & 0x01000000)) key = MOD_NUM_KEYPAD | '7';
break;
case VK_END:
- if (!(lParam & 0x01000000)) key = CURSOR_DOWN_LEFT;
+ if (!(lParam & 0x01000000)) key = MOD_NUM_KEYPAD | '1';
break;
+ case VK_INSERT:
+ if (!(lParam & 0x01000000)) key = MOD_NUM_KEYPAD | '0';
+ break;
+ case VK_CLEAR:
+ if (!(lParam & 0x01000000)) key = MOD_NUM_KEYPAD | '5';
+ break;
/*
* Numeric keypad keys with Num Lock on.
*/
- case VK_NUMPAD4: key = CURSOR_LEFT; break;
- case VK_NUMPAD6: key = CURSOR_RIGHT; break;
- case VK_NUMPAD8: key = CURSOR_UP; break;
- case VK_NUMPAD2: key = CURSOR_DOWN; break;
- case VK_NUMPAD9: key = CURSOR_UP_RIGHT; break;
- case VK_NUMPAD3: key = CURSOR_DOWN_RIGHT; break;
- case VK_NUMPAD7: key = CURSOR_UP_LEFT; break;
- case VK_NUMPAD1: key = CURSOR_DOWN_LEFT; break;
+ case VK_NUMPAD4: key = MOD_NUM_KEYPAD | '4'; break;
+ case VK_NUMPAD6: key = MOD_NUM_KEYPAD | '6'; break;
+ case VK_NUMPAD8: key = MOD_NUM_KEYPAD | '8'; break;
+ case VK_NUMPAD2: key = MOD_NUM_KEYPAD | '2'; break;
+ case VK_NUMPAD5: key = MOD_NUM_KEYPAD | '5'; break;
+ case VK_NUMPAD9: key = MOD_NUM_KEYPAD | '9'; break;
+ case VK_NUMPAD3: key = MOD_NUM_KEYPAD | '3'; break;
+ case VK_NUMPAD7: key = MOD_NUM_KEYPAD | '7'; break;
+ case VK_NUMPAD1: key = MOD_NUM_KEYPAD | '1'; break;
+ case VK_NUMPAD0: key = MOD_NUM_KEYPAD | '0'; break;
}
if (key != -1) {