VirtualBox

Changeset 3945 in vbox for trunk/src


Ignore:
Timestamp:
Jul 31, 2007 5:41:28 PM (17 years ago)
Author:
vboxsync
Message:

Moved the Wine-based keyboard handler library into a separate shared object to make it absolutely clear that it is not a part of VirtualBox

Location:
trunk/src/VBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r3925 r3945  
    4141
    4242PROGRAMS = VirtualBox
     43DLLS.linux = VBoxKeyboard
    4344
    4445INSTALLS = VirtualBox.nls
     46
     47VBoxKeyboard_TEMPLATE = VBOXR3
     48VBoxKeyboard_SOURCES  = \
     49        src/linux/keyboard.c
     50VBoxKeyboard_CFLAGS   = -fPIC
    4551
    4652VirtualBox_TEMPLATE = VBOXQTGUIEXE
     
    146152
    147153VirtualBox_SOURCES.linux = \
    148         src/linux/XKeyboard.cpp \
    149         src/linux/keyboard.c
     154        src/linux/XKeyboard.cpp
    150155
    151156VirtualBox_SOURCES.darwin = \
     
    206211        $(PATH_SDK_DXSDK_LIB)/ddraw.lib \
    207212        $(PATH_SDK_DXSDK_LIB)/dxguid.lib
     213VirtualBox_LIBS.linux     = $(PATH_DLL)/VBoxKeyboard$(VBOX_SUFF_DLL)
     214
    208215
    209216ifdef VBOX_WITH_DEBUGGER_GUI
  • trunk/src/VBox/Frontends/VirtualBox/include/XKeyboard.h

    r3701 r3945  
    4444int getKeysymsPerKeycode();
    4545
    46 // initialize the X keyboard subsystem, safe for use on remote X servers
    47 bool initXKeyboardSafe(Display *dpy);
    48 // our custom keyboard handler, safe for use on remote X servers
    49 void handleXKeyEventSafe(Display *dpy, XEvent *event, WINEKEYBOARDINFO *wineKbdInfo);
    50 // returns the number of keysyms per keycode (only valid after initXKeyboard()), safe
    51 // for use on remote X servers
    52 int getKeysymsPerKeycodeSafe();
    53 
    54 
    5546#endif // __XKeyboard_h__
  • trunk/src/VBox/Frontends/VirtualBox/src/linux/XKeyboard.cpp

    r3908 r3945  
    3232#endif
    3333
    34 //
    35 // global variables
    36 //
    37 
    38 Display *dpy_global;
    39 BYTE InputKeyStateTable[256];
    40 
    4134// WINE keyboard prototypes
    4235extern "C"
    4336{
    44     void X11DRV_InitKeyboard( BYTE *key_state_table );
    45     void X11DRV_KeyEvent(XKeyEvent *event, WINEKEYBOARDINFO *wKbInfo);
     37    void X11DRV_InitKeyboard(Display *dpy);
     38    void X11DRV_KeyEvent(Display *dpy, XEvent *event, WINEKEYBOARDINFO *wKbInfo);
    4639    int X11DRV_GetKeysymsPerKeycode();
    4740}
     
    5851bool initXKeyboard(Display *dpy)
    5952{
    60     // update the global display pointer
    61     dpy_global = dpy;
    62     X11DRV_InitKeyboard(InputKeyStateTable);
     53    X11DRV_InitKeyboard(dpy);
    6354    return true;
    6455}
     
    6960void handleXKeyEvent(Display *dpy, XEvent *event, WINEKEYBOARDINFO *wineKbdInfo)
    7061{
    71     // update the global display pointer
    72     dpy_global = dpy;
    7362    // call the WINE event handler
    74     X11DRV_KeyEvent((XKeyEvent*)event, wineKbdInfo);
     63    X11DRV_KeyEvent(dpy, event, wineKbdInfo);
    7564}
    7665
  • trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard.c

    r3938 r3945  
    2323 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
    2424 */
    25 // our master define to make this module usable outside wine
     25/* our master define to make this module usable outside wine */
    2626
    2727#define OUTOFWINE
     
    3030#include "keyboard_outofwine.h"
    3131int use_xkb = 1;
    32 #endif // OUTOFWINE defined
     32#endif /* OUTOFWINE defined */
    3333
    3434#ifndef OUTOFWINE
    3535#include "config.h"
    36 #endif // OUTOFWINE not defined
     36#endif /* OUTOFWINE not defined */
    3737
    3838#include <X11/Xatom.h>
     
    6666WINE_DEFAULT_DEBUG_CHANNEL(keyboard);
    6767WINE_DECLARE_DEBUG_CHANNEL(key);
    68 #endif // OUTOFWINE not defined
    6968
    7069typedef union
     
    8887    unsigned long lp2;
    8988} KEYLP;
     89#endif /* OUTOFWINE not defined */
     90
    9091
    9192/* key state table bits:
     
    9697BYTE key_state_table[256];
    9798
     99#ifndef OUTOFWINE
    98100static BYTE TrackSysKey = 0; /* determine whether ALT key up will cause a WM_SYSKEYUP
    99101                                or a WM_KEYUP message */
     102#endif
    100103
    101104static int min_keycode, max_keycode, keysyms_per_keycode;
     
    108111
    109112#ifdef OUTOFWINE
    110 // Global variable to store the current display pointer which is defined
    111 // and updated in XKeyboard.cpp.
    112 // The wine keyboard handler isn't reentrant anyway...
    113 extern Display *dpy_global;
     113/* Global variable to store the current display pointer which is defined
     114 * and updated in XKeyboard.cpp.
     115 * The wine keyboard handler isn't reentrant anyway... */
     116Display *dpy_global;
     117
    114118inline static Display *thread_display(void) { return dpy_global; }
    115 // @@@AH without this, the event time calculations are all wrong. To fix it,
    116 // we also gotta supply GetCurrentTime
     119/* @@@AH without this, the event time calculations are all wrong. To fix it,
     120 * we also gotta supply GetCurrentTime */
    117121unsigned int X11DRV_server_startticks = 0;
    118 // our structure used to return keyboard event information
    119 typedef struct _WINEKEYBOARDINFO
    120 {
    121     unsigned short wVk;
    122     unsigned short wScan;
    123     unsigned long dwFlags;
    124     unsigned long time;
    125 } WINEKEYBOARDINFO;
    126122static WINEKEYBOARDINFO *wineKeyboardInfo = NULL;
    127123#endif
     
    11761172}
    11771173
     1174#ifndef OUTOFWINE
    11781175static BOOL NumState=FALSE, CapsState=FALSE;
     1176#endif
    11791177
    11801178
     
    11821180 *           X11DRV_send_keyboard_input
    11831181 */
    1184 void X11DRV_send_keyboard_input( WORD wVk, WORD wScan, DWORD dwFlags, DWORD time,
     1182static void X11DRV_send_keyboard_input( WORD wVk, WORD wScan, DWORD dwFlags, DWORD time,
    11851183                                 DWORD dwExtraInfo, UINT injected_flags )
    11861184{
     
    12721270    }
    12731271    SERVER_END_REQ;
    1274 #else // OUTOFWINE defined
    1275     // fill out our global structure
     1272#else /* OUTOFWINE defined */
     1273    /* fill out our global structure */
    12761274    wineKeyboardInfo->wVk = wVk;
    12771275    wineKeyboardInfo->wScan = wScan;
    12781276    wineKeyboardInfo->dwFlags = dwFlags;
    12791277    wineKeyboardInfo->time = time;
    1280 #endif // OUTOFWINE defined
     1278#endif /* OUTOFWINE defined */
    12811279}
    12821280
    12831281
     1282#ifndef OUTOFWINE
    12841283/**********************************************************************
    12851284 *              KEYBOARD_GenerateMsg
     
    13281327    }
    13291328}
     1329#endif /* OUTOFWINE not defined */
    13301330
    13311331/***********************************************************************
     
    13501350}
    13511351
     1352#ifndef OUTOFWINE
    13521353/***********************************************************************
    13531354 *           X11DRV_KeymapNotify
     
    13621363{
    13631364    int i, j, alt, control, shift;
    1364 #ifndef OUTOFWINE
    13651365    DWORD time = GetCurrentTime();
    1366 #else // OUTOFWINE defined
    1367     // @@@AH todo!
    1368     DWORD time = 0;
    1369 #endif // OUTOFWINE defined
    13701366
    13711367    alt = control = shift = 0;
     
    13911387    KEYBOARD_UpdateOneState( VK_SHIFT, shift, time );
    13921388}
     1389#endif /* OUTOFWINE defined */
    13931390
    13941391/***********************************************************************
     
    13991396#ifndef OUTOFWINE
    14001397void X11DRV_KeyEvent( HWND hwnd, XEvent *xev )
    1401 #else // OUTOFWINE defined
    1402 void X11DRV_KeyEvent(XEvent *xev, WINEKEYBOARDINFO *wKbInfo)
    1403 #endif // OUTOFWINE defined
     1398#else /* OUTOFWINE defined */
     1399void X11DRV_KeyEvent(Display *dpy, XEvent *xev, WINEKEYBOARDINFO *wKbInfo)
     1400#endif /* OUTOFWINE defined */
    14041401{
    14051402    XKeyEvent *event = &xev->xkey;
     
    14121409    XIC xic = X11DRV_get_ic( hwnd );
    14131410    DWORD event_time = EVENT_x11_time_to_win32_time(event->time);
    1414 #else // OUTOFWINE defined
    1415     // @@@AH do we need support for XIM?
     1411    Status status = 0;
     1412#else /* OUTOFWINE defined */
     1413    Status status = 0;
     1414    /* @@@AH do we need support for XIM? */
    14161415    XIC xic = 0;
    1417     // set our global pointer for the return data structure
    1418     // and initialize it with zeroes for the case of early return
    1419     // (this will mean that the event cannot be converted to a scancode)
     1416    /* We don't use this anyway. */
     1417    DWORD event_time = 0;
     1418    dpy_global = dpy;
     1419    /* set our global pointer for the return data structure
     1420     * and initialize it with zeroes for the case of early return
     1421     * (this will mean that the event cannot be converted to a scancode) */
    14201422    wineKeyboardInfo = wKbInfo;
    14211423    memset( wineKeyboardInfo, 0, sizeof( wineKeyboardInfo ) );
    1422     // We don't use this anyway.
    1423     DWORD event_time = 0;
    1424 #endif // OUTOFWINE defined
    1425     Status status = 0;
     1424#endif /* OUTOFWINE defined */
    14261425
    14271426    TRACE_(key)("type %d, window %lx, state 0x%04x, keycode 0x%04x\n",
     
    14471446        return;
    14481447    }
    1449 #endif // OUTOFWINE not defined
     1448#endif /* OUTOFWINE not defined */
    14501449
    14511450    /* If XKB extensions are used, the state mask for AltGr will use the group
     
    14861485   if (vkey)
    14871486   {
    1488     /// @todo (dmik):
    1489     //      KEYBOARD_GenerateMsg() does not work property because
    1490     //      send_keyboard_input() modifies our static WINEKEYBOARDINFO struct
    1491     //      directly, w/o any buffering. Moreover the purpose of
    1492     //      KEYBOARD_GenerateMsg() is not completely clear for me; in our case
    1493     //      it seems to be unnecessary, so disable the code below.
    1494 //    switch (vkey & 0xff)
    1495 //    {
    1496 //    case VK_NUMLOCK:
    1497 //      KEYBOARD_GenerateMsg( VK_NUMLOCK, 0x45, event->type, event_time );
    1498 //      break;
    1499 //    case VK_CAPITAL:
    1500 //      TRACE("Caps Lock event. (type %d). State before : %#.2x\n",event->type,key_state_table[vkey]);
    1501 //      KEYBOARD_GenerateMsg( VK_CAPITAL, 0x3A, event->type, event_time );
    1502 //      TRACE("State after : %#.2x\n",key_state_table[vkey]);
    1503 //      break;
    1504 //    default:
    1505 //        /* Adjust the NUMLOCK state if it has been changed outside wine */
    1506 //      if (!(key_state_table[VK_NUMLOCK] & 0x01) != !(event->state & NumLockMask))
    1507 //        {
    1508 //          TRACE("Adjusting NumLock state.\n");
    1509 //          KEYBOARD_GenerateMsg( VK_NUMLOCK, 0x45, KeyPress, event_time );
    1510 //          KEYBOARD_GenerateMsg( VK_NUMLOCK, 0x45, KeyRelease, event_time );
    1511 //        }
    1512 //        /* Adjust the CAPSLOCK state if it has been changed outside wine */
    1513 //      if (!(key_state_table[VK_CAPITAL] & 0x01) != !(event->state & LockMask))
    1514 //        {
    1515 //              TRACE("Adjusting Caps Lock state.\n");
    1516 //          KEYBOARD_GenerateMsg( VK_CAPITAL, 0x3A, KeyPress, event_time );
    1517 //          KEYBOARD_GenerateMsg( VK_CAPITAL, 0x3A, KeyRelease, event_time );
    1518 //        }
    1519 //      /* Not Num nor Caps : end of intermediary states for both. */
    1520 //      NumState = FALSE;
    1521 //      CapsState = FALSE;
     1487    /** @todo (dmik):
     1488     *      KEYBOARD_GenerateMsg() does not work property because
     1489     *      send_keyboard_input() modifies our static WINEKEYBOARDINFO struct
     1490     *      directly, w/o any buffering. Moreover the purpose of
     1491     *      KEYBOARD_GenerateMsg() is not completely clear for me; in our case
     1492     *      it seems to be unnecessary, so disable the code below. */
     1493#ifndef OUTOFWINE
     1494      switch (vkey & 0xff)
     1495      {
     1496      case VK_NUMLOCK:
     1497        KEYBOARD_GenerateMsg( VK_NUMLOCK, 0x45, event->type, event_time );
     1498        break;
     1499      case VK_CAPITAL:
     1500        TRACE("Caps Lock event. (type %d). State before : %#.2x\n",event->type,key_state_table[vkey]);
     1501        KEYBOARD_GenerateMsg( VK_CAPITAL, 0x3A, event->type, event_time );
     1502        TRACE("State after : %#.2x\n",key_state_table[vkey]);
     1503        break;
     1504      default:
     1505          /* Adjust the NUMLOCK state if it has been changed outside wine */
     1506          if (!(key_state_table[VK_NUMLOCK] & 0x01) != !(event->state & NumLockMask))
     1507          {
     1508            TRACE("Adjusting NumLock state.\n");
     1509            KEYBOARD_GenerateMsg( VK_NUMLOCK, 0x45, KeyPress, event_time );
     1510            KEYBOARD_GenerateMsg( VK_NUMLOCK, 0x45, KeyRelease, event_time );
     1511          }
     1512        /* Adjust the CAPSLOCK state if it has been changed outside wine */
     1513          if (!(key_state_table[VK_CAPITAL] & 0x01) != !(event->state & LockMask))
     1514          {
     1515              TRACE("Adjusting Caps Lock state.\n");
     1516            KEYBOARD_GenerateMsg( VK_CAPITAL, 0x3A, KeyPress, event_time );
     1517            KEYBOARD_GenerateMsg( VK_CAPITAL, 0x3A, KeyRelease, event_time );
     1518          }
     1519          /* Not Num nor Caps : end of intermediary states for both. */
     1520          NumState = FALSE;
     1521          CapsState = FALSE;
     1522#endif /* OUTOFWINE not defined */
    15221523
    15231524        bScan = keyc2scan[event->keycode] & 0xFF;
     
    15291530
    15301531        X11DRV_send_keyboard_input( vkey & 0xff, bScan, dwFlags, event_time, 0, 0 );
    1531 //    }
     1532#ifndef OUTOFWINE
     1533      }
     1534#endif
    15321535   }
    15331536}
     
    15981601        /* right now, we just find an absolute match for defined positions */
    15991602        /* (undefined positions are ignored, so if it's defined as "3#" in */
    1600         /* the table, it's okay that the X server has "3#�", for example) */
     1603        /* the table, it's okay that the X server has "3#£", for example) */
    16011604        /* however, the score will be higher for longer matches */
    16021605        for (key = 0; key < MAIN_LEN; key++) {
     
    16511654 *              X11DRV_InitKeyboard
    16521655 */
    1653 void X11DRV_InitKeyboard(void)
    1654 {
    1655     Display *display = thread_display();
     1656void X11DRV_InitKeyboard(Display *display)
     1657{
    16561658    KeySym *ksp;
    16571659    XModifierKeymap *mmp;
     
    16651667    char vkey_used[256] = { 0 };
    16661668
     1669    dpy_global = display;
    16671670    wine_tsx11_lock();
    16681671    XDisplayKeycodes(display, &min_keycode, &max_keycode);
     
    18251828        if (!vkey)
    18261829        {
    1827             // @@@AH VBOX hack for AltGr
     1830            /* @@@AH VBOX hack for AltGr */
    18281831            if (e2.keycode == 0x71)
    18291832            {
     
    18811884        if (!ksname) ksname = "NoSymbol";
    18821885
    1883     // @@@AH VBOX hack for AltGr
     1886    /* @@@AH VBOX hack for AltGr */
    18841887    if (keyc == 0x71)
    18851888    {
     
    23692372  return 0;
    23702373}
    2371 #endif // OUTOFWINE not defined
     2374#endif /* OUTOFWINE not defined */
    23722375
    23732376/***********************************************************************
     
    23882391#endif
    23892392            case 0x1000FE27 : /* Xfree's XK_Dacute_accent */
    2390                 return 0xb4;    /* '' */
     2393                return (char)0xb4;      /* '' */
    23912394#ifdef XK_dead_circumflex
    23922395            case XK_dead_circumflex:
     
    24032406#endif
    24042407            case 0x1000FE22 : /* Xfree's XK_Ddiaeresis */
    2405                 return 0xa8;    /* ': */
     2408                return (char)0xa8;      /* ': */
    24062409#ifdef XK_dead_cedilla
    24072410            case XK_dead_cedilla :
    2408                 return 0xb8;    /* ', */
     2411                return (char)0xb8;      /* ', */
    24092412#endif
    24102413#ifdef XK_dead_macron
     
    24142417#ifdef XK_dead_breve
    24152418            case XK_dead_breve :
    2416                 return 0xa2;    /* '( */
     2419                return (char)0xa2;      /* '( */
    24172420#endif
    24182421#ifdef XK_dead_abovedot
    24192422            case XK_dead_abovedot :
    2420                 return 0xff;    /* '. */
     2423                return (char)0xff;      /* '. */
    24212424#endif
    24222425#ifdef XK_dead_abovering
     
    24262429#ifdef XK_dead_doubleacute
    24272430            case XK_dead_doubleacute :
    2428                 return 0xbd;    /* '" */
     2431                return (char)0xbd;      /* '" */
    24292432#endif
    24302433#ifdef XK_dead_caron
    24312434            case XK_dead_caron :
    2432                 return 0xb7;    /* '< */
     2435                return (char)0xb7;      /* '< */
    24332436#endif
    24342437#ifdef XK_dead_ogonek
    24352438            case XK_dead_ogonek :
    2436                 return 0xb2;    /* '; */
     2439                return (char)0xb2;      /* '; */
    24372440#endif
    24382441/* FIXME: I don't know this three.
     
    27082711    wine_tsx11_unlock();
    27092712}
    2710 #else // OUTOFWINE defined
     2713#else /* OUTOFWINE defined */
    27112714int X11DRV_GetKeysymsPerKeycode()
    27122715{
    27132716    return keysyms_per_keycode;
    27142717}
    2715 #endif // OUTOFWINE defined
     2718#endif /* OUTOFWINE defined */
  • trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard_outofwine.h

    r2529 r3945  
    2020#define __H_KEYBOARD_OUTOFWINE
    2121
    22 // type definitions
     22#define HAVE_X11_XKBLIB_H
     23
     24#include <X11/Xatom.h>
     25#include <X11/keysym.h>
     26#include <X11/Xlib.h>
     27#include <X11/Xresource.h>
     28#include <X11/Xutil.h>
     29#ifdef HAVE_X11_XKBLIB_H
     30#include <X11/XKBlib.h>
     31#endif
     32
     33#include <ctype.h>
     34#include <stdarg.h>
     35#include <string.h>
     36
     37/** Our structure used to return keyboard event information */
     38typedef struct _WINEKEYBOARDINFO
     39{
     40    unsigned short wVk;
     41    unsigned short wScan;
     42    unsigned long dwFlags;
     43    unsigned long time;
     44} WINEKEYBOARDINFO;
     45
     46/* Exported definitions */
     47extern __attribute__((visibility("default"))) void X11DRV_InitKeyboard(Display *dpy);
     48extern __attribute__((visibility("default"))) void X11DRV_KeyEvent(Display *dpy, XEvent *event,
     49                                                                   WINEKEYBOARDINFO *wKbInfo);
     50extern __attribute__((visibility("default"))) int X11DRV_GetKeysymsPerKeycode(void);
     51
     52/* type definitions */
    2353typedef unsigned char BYTE, *LPBYTE;
    2454typedef unsigned short WORD;
     
    3262#define TRUE 1
    3363
    34 // debug macros
    35 #define TRACE
    36 //#define TRACE printf
    37 #define TRACE_(a)
    38 //#define TRACE_(ch) printf
     64/* debug macros */
     65inline static void noop(char *arg, ...)
     66{
     67}
     68
     69#define TRACE(...)
     70/* #define TRACE printf */
     71#define TRACE_(a) noop
     72/* #define TRACE_(ch) printf */
    3973#define TRACE_ON(a) 0
    40 #define WARN
    41 #define ERR
    42 
    43 // @@@AH do we need semaphore protection?
     74#define WARN(...)
     75#define ERR(...)
     76
     77/* @@@AH do we need semaphore protection? */
    4478#define wine_tsx11_lock(a)
    4579#define wine_tsx11_unlock(a)
    4680
    47 // global wine defines
     81/* global wine defines */
    4882#define HAVE_XKB
    4983
    50 //
    51 // x11drv.h
    52 //
    53 
    54 
    55 //
    56 // user.h
    57 //
    58 
    59 
    60 //
    61 // winuser.h
    62 //
     84/*
     85 * x11drv.h
     86 */
     87
     88
     89/*
     90 * user.h
     91 */
     92
     93
     94/*
     95 * winuser.h
     96 */
    6397
    6498
     
    246280#define VK_OEM_CLEAR        0xFE
    247281
    248 // ...
     282/* ... */
    249283
    250284  /* keybd_event flags */
     
    252286#define KEYEVENTF_KEYUP              0x0002
    253287
    254 // end of winuser.h
    255 
    256 
    257 #endif // __H_KEYBOARD_OUTOFWINE
     288/* end of winuser.h */
     289
     290
     291#endif /* __H_KEYBOARD_OUTOFWINE */
  • trunk/src/VBox/Installer/linux/Makefile.kmk

    r3906 r3945  
    4848        VBoxDD.so \
    4949        VBoxDD2.so \
     50        VBoxKeyboard.so \
    5051        VBoxManage \
    5152        VBoxREM.so \
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette