otclientv8 icon indicating copy to clipboard operation
otclientv8 copied to clipboard

Paste on OSX

Open MightyGoober opened this issue 11 months ago • 5 comments

When using the Mac client, you can copy with: CTRL + OPT + C Paste does not work with any combination of keys + V

MightyGoober avatar Jan 25 '25 03:01 MightyGoober

Can you create hotkeys using OPT key at all? I have no way to test Mac client unfortunately.

Oen44 avatar Jan 25 '25 09:01 Oen44

This problem also occurs on the linux version, paste does not always work.

punkice3407 avatar Jan 26 '25 13:01 punkice3407

Can you create hotkeys using OPT key at all? I have no way to test Mac client unfortunately.

no, the client does not detect the opt key. Although it detects ctrl, and it is assignable to hotkeys, ctrl+v does not work, it just inputs v.

eduardolbueno avatar Sep 22 '25 10:09 eduardolbueno

Can you create hotkeys using OPT key at all? I have no way to test Mac client unfortunately.

no, the client does not detect the opt key. Although it detects ctrl, and it is assignable to hotkeys, ctrl+v does not work, it just inputs v.

Check this code

std::string X11Window::getClipboardText()
{
    Atom clipboard = XInternAtom(m_display, "CLIPBOARD", False);
    Window ownerWindow = XGetSelectionOwner(m_display, clipboard);
    if(ownerWindow == m_window)
        return m_clipboardText;

    std::string clipboardText;
    if(ownerWindow != None) {
        Atom propertyAtom = XInternAtom(m_display, "OTCLIENT_CLIPBOARD", False);
        Atom target = XInternAtom(m_display, "UTF8_STRING", False);
        if(target == None)
            target = XA_STRING;

        XConvertSelection(m_display, clipboard, target, propertyAtom, m_window, CurrentTime);
        XFlush(m_display);

        // hack to wait SelectioNotify event, otherwise we will get wrong clipboard pastes
        // TODO: fix this in a correct way
        stdext::millisleep(100);

        Atom type;
        int format;
        unsigned long len = 0, bytesLeft = 0;
        unsigned char* data = nullptr;
        int result = XGetWindowProperty(m_display, m_window, propertyAtom, 0, 10000000L, False, target, &type, &format, &len, &bytesLeft, &data);
        if(result != Success || len == 0 || data == nullptr) {
            if(data)
                XFree(data);

            target = XA_STRING;
            XConvertSelection(m_display, clipboard, target, propertyAtom, m_window, CurrentTime);
            XFlush(m_display);
            stdext::millisleep(100);
            result = XGetWindowProperty(m_display, m_window, propertyAtom, 0, 10000000L, False, target, &type, &format, &len, &bytesLeft, &data);
        }

        if(result == Success && len > 0 && data) {
            clipboardText.assign(reinterpret_cast<char*>(data), len);

            if(stdext::is_valid_utf8(clipboardText))
                clipboardText = stdext::utf8_to_latin1(clipboardText);

            XFree(data);
        }
    }

    return clipboardText;
}

punkice3407 avatar Sep 22 '25 11:09 punkice3407

To whoever fixes this, keep in mind that Mac users are used to anything CTRL being mapped to CMD(windows key).

So the proper shortcut for copy/paste is CMD+C and CMD+V

MightyGoober avatar Sep 22 '25 14:09 MightyGoober