Ticket #4648: cspace.patch

File cspace.patch, 2.6 KB (added by joshe, 10 years ago)

Fix Control-Space messages for KeyUp and KeyDown.

  • src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp

    commit 64e6956af2345973f4a091869d65ec9f7d91f70b
    Author: Joshua R. Elsasser <joshua@elsasser.org>
    Date:   Sat Sep 26 17:38:23 2009 +0000
    
        Fix key events containing ASCII NUL characters, ie: control-space.
    
    diff --git a/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp b/src/add-ons/input_server/devices/keyboard/KeyboardInputDevice.cpp
    index abc9f53..cc74149 100644
    a b KeyboardDevice::_ControlThread()  
    733733            msg->AddInt32("modifiers", fModifiers);
    734734            msg->AddData("states", B_UINT8_TYPE, states, 16);
    735735            if (numBytes > 0) {
     736                BString bytes;
     737                bytes.SetTo('\0', numBytes);
    736738                for (int i = 0; i < numBytes; i++) {
    737739                    msg->AddInt8("byte", (int8)string[i]);
     740                    bytes[i] = string[i];
    738741                }
    739                 msg->AddString("bytes", string);
     742                msg->AddString("bytes", bytes);
    740743
    741744                if (rawNumBytes <= 0) {
    742745                    rawNumBytes = 1;
  • src/kits/app/Message.cpp

    diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp
    index 3e1bd40..49025bc 100644
    a b BMessage::FindString(const char *name, int32 index, BString *string) const  
    25702570    if (string == NULL)
    25712571        return B_BAD_VALUE;
    25722572
     2573    ssize_t bytes;
    25732574    const char *cstr;
    2574     status_t error = FindString(name, index, &cstr);
     2575    status_t error = FindData(name, B_STRING_TYPE, index,
     2576        (const void **)&cstr, &bytes);
    25752577    if (error < B_OK)
    25762578        return error;
    25772579
    2578     *string = cstr;
     2580    string->SetTo('\0', bytes - 1);
     2581    while (--bytes > 0)
     2582        (*string)[bytes - 1] = cstr[bytes - 1];
    25792583    return B_OK;
    25802584}
    25812585
  • src/kits/interface/Window.cpp

    diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp
    index e464fb2..d8cd621 100644
    a b FrameMoved(origin);  
    11131113                    // TODO: cannot use "string" here if we support having
    11141114                    // different font encoding per view (it's supposed to be
    11151115                    // converted by _HandleKeyDown() one day)
    1116                     const char* string;
     1116                    BString string;
    11171117                    if (msg->FindString("bytes", &string) == B_OK)
    1118                         view->KeyDown(string, strlen(string));
     1118                        view->KeyDown(string.String(), string.Length());
    11191119                } else
    11201120                    target->MessageReceived(msg);
    11211121            }
    FrameMoved(origin);  
    11241124
    11251125        case B_KEY_UP:
    11261126        {
    1127             const char* string = NULL;
     1127            BString string;
    11281128            msg->FindString("bytes", &string);
    11291129
    11301130            // TODO: same as above
    11311131            if (BView* view = dynamic_cast<BView*>(target))
    1132                 view->KeyUp(string, strlen(string));
     1132                view->KeyUp(string.String(), string.Length());
    11331133            else
    11341134                target->MessageReceived(msg);
    11351135            break;