jvcleave / ofxImGui

Use ImGui in openFrameworks
293 stars 124 forks source link

ctrl-c / ctrl-v clipboard callbacks never called on OSX #43

Open cgimenez opened 7 years ago

cgimenez commented 7 years ago

Hi, on OSX I can't have TextInput copy/paste working. Dunno if it's me but BaseEngine::getClipboardString() and BaseEngine::setClipboardString() are never called...

I tried with ctrl-c ctrl-v keys, also with cmd-c cmd-v keys (with io.ShortcutsUseSuperKey = true)

Using cmd-c or cmd-v erases the input's content and add a 'c' or a 'v'

borg commented 7 years ago

A few steps towards a solution. The is_super_down mod to imgui above and this does seem to work. It seems just returning &ofGetWindowPtr()->getClipboardString()[0] returns a variable that goes out of scope. Creating a static instance helps with that, but I'm not sure if it is being released somewhere else after. Another pair of eyes wouldn't hurt. In general it seems because keyboard inputs are platform specific this is a bit unsupported in imgui.

    //--------------------------------------------------------------
    const char* BaseEngine::getClipboardString()
    {
        static string str = ofGetWindowPtr()->getClipboardString();
        if(str.size()){
            str = &ofGetWindowPtr()->getClipboardString()[0];
            return str.c_str();
       }
        return "";
    }

    //--------------------------------------------------------------
    void BaseEngine::setClipboardString(const char * text)
    {
        static string str = ofToString(text);
        ofGetWindowPtr()->setClipboardString(str.c_str());
    }
rjx-ray commented 7 years ago

Ctrl-C & Ctrl-V work OK on Win32 , but direct calls to getClipBoardString don't.

See https://github.com/jvcleave/ofxImGui/issues/56