winex11.drv: Move key and AltGr state into a per thread data

Dmitry Timoshkov dmitry at codeweavers.com
Mon Nov 5 23:07:19 CST 2007


Hello,

Changelog:
    winex11.drv: Move key and AltGr state into a per thread data.
---
 dlls/winex11.drv/keyboard.c |   23 ++++++++++++-----------
 dlls/winex11.drv/mouse.c    |    4 ++++
 dlls/winex11.drv/x11drv.h   |    8 ++++++--
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/dlls/winex11.drv/keyboard.c b/dlls/winex11.drv/keyboard.c
index 31b4542..613a868 100644
--- a/dlls/winex11.drv/keyboard.c
+++ b/dlls/winex11.drv/keyboard.c
@@ -75,20 +75,13 @@ typedef union
     unsigned long lp2;
 } KEYLP;
 
-/* key state table bits:
-  0x80 -> key is pressed
-  0x40 -> key got pressed since last time
-  0x01 -> key is toggled
-*/
-BYTE key_state_table[256];
-
 static BYTE TrackSysKey = 0; /* determine whether ALT key up will cause a WM_SYSKEYUP
                                 or a WM_KEYUP message */
 
 static int min_keycode, max_keycode, keysyms_per_keycode;
 static WORD keyc2vkey[256], keyc2scan[256];
 
-static int NumLockMask, AltGrMask; /* mask in the XKeyEvent state */
+static int NumLockMask; /* mask in the XKeyEvent state */
 static int kcControl, kcAlt, kcShift, kcNumLock, kcCapsLock; /* keycodes */
 
 static char KEYBOARD_MapDeadKeysym(KeySym keysym);
@@ -1154,6 +1147,7 @@ void X11DRV_send_keyboard_input( WORD wVk, WORD wScan, DWORD dwFlags, DWORD time
     KEYLP keylp;
     KBDLLHOOKSTRUCT hook;
     WORD wVkStripped;
+    BYTE *key_state_table = x11drv_thread_data()->key_state_table;
 
     wVk = LOBYTE(wVk);
 
@@ -1249,6 +1243,7 @@ void X11DRV_send_keyboard_input( WORD wVk, WORD wScan, DWORD dwFlags, DWORD time
  */
 static void KEYBOARD_GenerateMsg( WORD vkey, WORD scan, int Evtype, DWORD event_time )
 {
+  BYTE *key_state_table = x11drv_thread_data()->key_state_table;
   BOOL * State = (vkey==VK_NUMLOCK? &NumState : &CapsState);
   DWORD up, down;
 
@@ -1294,6 +1289,8 @@ static void KEYBOARD_GenerateMsg( WORD vkey, WORD scan, int Evtype, DWORD event_
  */
 static inline void KEYBOARD_UpdateOneState ( int vkey, int state, DWORD time )
 {
+    BYTE *key_state_table = x11drv_thread_data()->key_state_table;
+
     /* Do something if internal table state != X state for keycode */
     if (((key_state_table[vkey] & 0x80)!=0) != state)
     {
@@ -1360,6 +1357,7 @@ void X11DRV_KeyEvent( HWND hwnd, XEvent *xev )
     XIC xic = X11DRV_get_ic( hwnd );
     DWORD event_time = EVENT_x11_time_to_win32_time(event->time);
     Status status = 0;
+    BYTE *key_state_table;
 
     TRACE_(key)("type %d, window %lx, state 0x%04x, keycode 0x%04x\n",
 		event->type, event->window, event->state, event->keycode);
@@ -1393,7 +1391,9 @@ void X11DRV_KeyEvent( HWND hwnd, XEvent *xev )
 
        Ref: X Keyboard Extension: Library specification (section 14.1.1 and 17.1.1) */
     /* Save also all possible modifier states. */
-    AltGrMask = event->state & (0x6000 | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
+    x11drv_thread_data()->alt_gr_mask = event->state & (0x6000 | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask);
+
+    key_state_table = x11drv_thread_data()->key_state_table;
 
     if (TRACE_ON(key)){
 	const char *ksname;
@@ -1824,6 +1824,7 @@ void X11DRV_InitKeyboard(void)
 SHORT X11DRV_GetAsyncKeyState(INT key)
 {
     SHORT retval;
+    BYTE *key_state_table = x11drv_thread_data()->key_state_table;
 
     /* Photoshop livelocks unless mouse events are included here */
     X11DRV_MsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_KEY | QS_MOUSE, 0 );
@@ -2440,8 +2441,8 @@ INT X11DRV_ToUnicodeEx(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
     }
 
     /* Restore saved AltGr state */
-    TRACE("AltGrMask = %04x\n", AltGrMask);
-    e.state |= AltGrMask;
+    TRACE("AltGrMask = %04x\n", x11drv_thread_data()->alt_gr_mask);
+    e.state |= x11drv_thread_data()->alt_gr_mask;
 
     TRACE_(key)("(%04X, %04X) : faked state = 0x%04x\n",
 		virtKey, scanCode, e.state);
diff --git a/dlls/winex11.drv/mouse.c b/dlls/winex11.drv/mouse.c
index b175c6b..07419f0 100644
--- a/dlls/winex11.drv/mouse.c
+++ b/dlls/winex11.drv/mouse.c
@@ -149,6 +149,8 @@ static inline void clip_point_to_rect( LPCRECT rect, LPPOINT pt )
  */
 static inline void update_button_state( unsigned int state )
 {
+    BYTE *key_state_table = x11drv_thread_data()->key_state_table;
+
     key_state_table[VK_LBUTTON] = (state & Button1Mask ? 0x80 : 0);
     key_state_table[VK_MBUTTON] = (state & Button2Mask ? 0x80 : 0);
     key_state_table[VK_RBUTTON] = (state & Button3Mask ? 0x80 : 0);
@@ -207,6 +209,7 @@ static void update_mouse_state( HWND hwnd, Window window, int x, int y, unsigned
  */
 static WORD get_key_state(void)
 {
+    BYTE *key_state_table = x11drv_thread_data()->key_state_table;
     WORD ret = 0;
 
     if (GetSystemMetrics( SM_SWAPBUTTON ))
@@ -271,6 +274,7 @@ void X11DRV_send_mouse_input( HWND hwnd, DWORD flags, DWORD x, DWORD y,
                               DWORD data, DWORD time, DWORD extra_info, UINT injected_flags )
 {
     POINT pt;
+    BYTE *key_state_table = x11drv_thread_data()->key_state_table;
 
     if (flags & MOUSEEVENTF_MOVE && flags & MOUSEEVENTF_ABSOLUTE)
     {
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index ec03e71..463a761 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -513,6 +513,12 @@ struct x11drv_thread_data
     HWND     last_focus;           /* last window that had focus */
     XIM      xim;                  /* input method */
     Window   selection_wnd;        /* window used for selection interactions */
+    BYTE     key_state_table[256]; /* key state table bits:
+                                    * 0x80 -> key is pressed
+                                    * 0x40 -> key got pressed since last time
+                                    * 0x01 -> key is toggled
+                                    */
+    unsigned alt_gr_mask;          /* mask in the XKeyEvent state */
 };
 
 extern struct x11drv_thread_data *x11drv_init_thread_data(void);
@@ -544,8 +550,6 @@ extern int primary_monitor;
 extern int copy_default_colors;
 extern int alloc_system_colors;
 extern int xrender_error_base;
-
-extern BYTE key_state_table[256];
 extern POINT cursor_pos;
 
 /* atoms */
-- 
1.5.3.4






More information about the wine-patches mailing list