@@ -76,6 +76,21 @@ static Atom& _NET_WM_STATE_FULLSCREEN(){
7676 return w;
7777 }
7878
79+ static Atom& CLIPBOARD (){
80+ static Atom w = XInternAtom ( dpy, " CLIPBOARD" , 0 );
81+ return w;
82+ }
83+
84+ static Atom& UTF8_STRING (){
85+ static Atom w = XInternAtom ( dpy, " UTF8_STRING" , 0 );
86+ return w;
87+ }
88+
89+ static Atom& XSEL_DATA (){
90+ static Atom w = XInternAtom ( dpy, " XSEL_DATA" , 0 );
91+ return w;
92+ }
93+
7994static bool nativeIsFullscreen (SystemApi::Window *iw) {
8095 HWND w (iw);
8196
@@ -627,7 +642,19 @@ void X11Api::implProcessEvents(SystemApi::AppCallBack &cb) {
627642 uint32_t scan = xev.xkey .keycode ;
628643 // printf("%s\n",txt);
629644
630- Tempest::KeyEvent e (Event::KeyType (key),uint32_t (u16 .size ()>0 ? u16 [0 ] : 0 ),Event::M_NoModifier,(xev.type ==KeyPress) ? Event::KeyDown : Event::KeyUp);
645+ Tempest::KeyEvent e (
646+ Event::KeyType (key),
647+ uint32_t (u16 .size ()>0 ? u16 [0 ] : 0 ),
648+ xev.xkey .state & ControlMask ? Event::M_Ctrl : Event::M_NoModifier,
649+ (xev.type ==KeyPress) ? Event::KeyDown : Event::KeyUp
650+ );
651+
652+ // Ctrl+V - Request clipboard insert
653+ if (e.modifier == Event::M_Ctrl and e.type () == Event::KeyDown and e.key == Event::K_V ) {
654+ XConvertSelection (dpy, CLIPBOARD (), UTF8_STRING (), XSEL_DATA (), hWnd, CurrentTime);
655+ break ;
656+ }
657+
631658 if (xev.type ==KeyPress)
632659 SystemApi::dispatchKeyDown (cb,e,scan); else
633660 SystemApi::dispatchKeyUp (cb,e,scan);
@@ -643,6 +670,27 @@ void X11Api::implProcessEvents(SystemApi::AppCallBack &cb) {
643670 SystemApi::dispatchFocus (cb, e);
644671 break ;
645672 }
673+ case SelectionNotify: {
674+ if (xev.xselection .property != None) {
675+ Atom actual_type;
676+ int actual_format;
677+ unsigned long nitems, bytes_after;
678+ unsigned char * data;
679+
680+ XGetWindowProperty (xev.xselection .display , xev.xselection .requestor ,
681+ xev.xselection .property , 0L , ~0L , False, AnyPropertyType,
682+ &actual_type, &actual_format, &nitems, &bytes_after, &data);
683+
684+ if (actual_type == UTF8_STRING () || actual_type == XA_STRING ) {
685+ ClipboardEvent e (std::string (reinterpret_cast <char *>(data)));
686+ SystemApi::dispatchClipboardPaste (cb,e);
687+ XFree (data);
688+ }
689+
690+ XDeleteProperty (dpy, xev.xselection .requestor , xev.xselection .property );
691+ }
692+ break ;
693+ }
646694 }
647695
648696 std::this_thread::yield ();
0 commit comments