Ticket #7963: get_keyboard_id_1.diff

File get_keyboard_id_1.diff, 5.0 KB (added by jscipione, 8 years ago)

This patch represents my attempt to grab the keyboard id from the PS/2 driver. It is incomplete but can be a starting point to anyone interested in implementing this feature.

  • headers/os/add-ons/input_server/InputServerDevice.h

    diff --git headers/os/add-ons/input_server/InputServerDevice.h headers/os/add-ons/input_server/InputServerDevice.h
    index 3c33588..9add069 100644
    enum { 
    2323    // B_KEYBOARD_DEVICE notifications
    2424    B_KEY_MAP_CHANGED       = 1,
    2525    B_KEY_LOCKS_CHANGED,
     26    B_GET_KEYBOARD_ID,
    2627    B_KEY_REPEAT_DELAY_CHANGED,
    2728    B_KEY_REPEAT_RATE_CHANGED,
    2829
  • headers/private/input/kb_mouse_settings.h

    diff --git headers/private/input/kb_mouse_settings.h headers/private/input/kb_mouse_settings.h
    index e76db24..bb782c3 100644
     
    1212typedef struct {
    1313    bigtime_t   key_repeat_delay;
    1414    int32       key_repeat_rate;
     15    uint16      keyboard_id;
    1516} kb_settings;
    1617
    1718#define kb_default_key_repeat_delay 500000
  • src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp

    diff --git src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp
    index ef963d2..d8fd6cd 100644
    KeyboardDevice::_UpdateSettings(uint32 opcode) 
    512512{
    513513    KD_CALLED();
    514514
     515    if (opcode == 0 || opcode == B_GET_KEYBOARD_ID) {
     516        if (ioctl(fFD, KB_GET_KEYBOARD_ID, &fSettings.keyboard_id) != B_OK)
     517            LOG_ERR("error when KB_GET_KEYBOARD_ID, fd:%d\n", fFD);
     518    }
     519
    515520    if (opcode == 0 || opcode == B_KEY_REPEAT_RATE_CHANGED) {
    516521        if (get_key_repeat_rate(&fSettings.key_repeat_rate) != B_OK) {
    517522            LOG_ERR("error when get_key_repeat_rate\n");
  • src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.cpp

    diff --git src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.cpp src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.cpp
    index bfd492b..953794e 100644
    static bool sIsExtended = false; 
    6161
    6262static int32 sKeyboardRepeatRate;
    6363static bigtime_t sKeyboardRepeatDelay;
     64static uint16 sKeyboardId;
    6465
    6566
    6667static status_t
    keyboard_ioctl(void *_cookie, uint32 op, void *buffer, size_t length) 
    492493        }
    493494
    494495        case KB_GET_KEYBOARD_ID:
     496        {
     497            TRACE("ps2: ioctl KB_GET_KEYBOARD_ID\n");
     498            uint8 keyboard_id[2];
     499            // 0xf2 (Read keyboard ID) - Keyboard responds with "ack" (0xFA).
     500            if (ps2_dev_command(&ps2_device[PS2_DEVICE_KEYB],
     501                    PS2_CMD_GET_DEVICE_ID, NULL, 0, keyboard_id, 2) != B_OK);
     502                return B_ERROR;
     503            sKeyboardId = (uint16)((keyboard_id[1] << 8) & keyboard_id[0]);
     504            return user_memcpy(buffer, &sKeyboardId, sizeof(sKeyboardId));
     505        }
     506
    495507        case KB_SET_CONTROL_ALT_DEL_TIMEOUT:
    496508        case KB_CANCEL_CONTROL_ALT_DEL:
    497509        case KB_DELAY_CONTROL_ALT_DEL:
  • src/kits/interface/InterfaceDefs.cpp

    diff --git src/kits/interface/InterfaceDefs.cpp src/kits/interface/InterfaceDefs.cpp
    index ed61c2f..730ac73 100644
    get_keyboard_id(uint16 *id) 
    691691
    692692    _control_input_server_(&command, &reply);
    693693
    694     status_t err = reply.FindInt16("id", (int16 *)&kid);
     694    status_t err = reply.FindUInt16("id", &kid);
    695695    if (err != B_OK)
    696696        return err;
    697697    *id = kid;
  • src/servers/input/InputServer.cpp

    diff --git src/servers/input/InputServer.cpp src/servers/input/InputServer.cpp
    index 8b44ef8..ec65b64 100644
    InputServer::HandleGetSetMouseMap(BMessage* message, BMessage* reply) 
    872872status_t
    873873InputServer::HandleGetKeyboardID(BMessage* message, BMessage* reply)
    874874{
    875     return reply->AddInt16("id", fKeyboardID);
     875    BMessage msg(IS_CONTROL_DEVICES);
     876    msg.AddInt32("type", B_KEYBOARD_DEVICE);
     877    msg.AddInt32("code", B_GET_KEYBOARD_ID);
     878    if (fAddOnManager->PostMessage(&msg) == B_OK)
     879        return reply->AddUInt16("id", fKeyboardSettings.KeyboardId());
     880    else
     881        return B_ERROR;
    876882}
    877883
    878884
  • src/servers/input/KeyboardSettings.cpp

    diff --git src/servers/input/KeyboardSettings.cpp src/servers/input/KeyboardSettings.cpp
    index 96aff49..f65216d 100644
    KeyboardSettings::KeyboardSettings() 
    2626        goto err;
    2727    if (file.Read(&fSettings, sizeof(kb_settings)) != sizeof(kb_settings))
    2828        goto err;
    29        
     29   
    3030    return;
    3131err:
    3232    fSettings.key_repeat_delay = kb_default_key_repeat_delay;
    KeyboardSettings::SetKeyboardRepeatDelay(bigtime_t delay) 
    5656
    5757
    5858void
     59KeyboardSettings::SetKeyboardId(uint16 id)
     60{
     61    fSettings.keyboard_id = id;
     62}
     63
     64
     65void
    5966KeyboardSettings::Save()
    6067{
    6168    BPath path;
  • src/servers/input/KeyboardSettings.h

    diff --git src/servers/input/KeyboardSettings.h src/servers/input/KeyboardSettings.h
    index e67548c..84b5d34 100644
    public : 
    2222
    2323    void        SetKeyboardRepeatRate(int32 rate);
    2424    void        SetKeyboardRepeatDelay(bigtime_t delay);
    25    
     25    void        SetKeyboardId(uint16 id);
     26
    2627    int32       KeyboardRepeatRate() const      { return fSettings.key_repeat_rate; }
    2728    bigtime_t   KeyboardRepeatDelay() const     { return fSettings.key_repeat_delay; }
     29    uint16      KeyboardId() const              { return fSettings.keyboard_id; }
    2830
    2931    void        Save();
    3032