diff --git a/legacy/ecore/src/Ecore.h b/legacy/ecore/src/Ecore.h index 1d05660f32..3dce1672a2 100644 --- a/legacy/ecore/src/Ecore.h +++ b/legacy/ecore/src/Ecore.h @@ -275,6 +275,7 @@ void e_keyboard_grab(Window win); void e_keyboard_ungrab(void); Window e_selection_request(void); +Window e_selection_set(char *string); typedef struct _eev Eevent; typedef struct _ev_fd_handler Ev_Fd_Handler; diff --git a/legacy/ecore/src/e_ev_x.c b/legacy/ecore/src/e_ev_x.c index fdc4687030..262a9dd9c7 100644 --- a/legacy/ecore/src/e_ev_x.c +++ b/legacy/ecore/src/e_ev_x.c @@ -892,10 +892,12 @@ e_ev_x_handle_selection_request(XEvent * xevent) { static Atom atom_xdndselection = 0; static Atom atom_text_plain = 0; + static Atom atom_text_selection = 0; Ev_Dnd_Data_Request *e; E_ATOM(atom_xdndselection, "XdndSelection"); E_ATOM(atom_text_plain, "text/plain"); + E_ATOM(atom_text_selection, "TEXT_SELECTION"); if (xevent->xselectionrequest.selection == atom_xdndselection) { e = NEW(Ev_Dnd_Data_Request, 1); @@ -909,6 +911,67 @@ e_ev_x_handle_selection_request(XEvent * xevent) e->destination_atom = xevent->xselectionrequest.property; e_add_event(EV_DND_DATA_REQUEST, e, e_ev_generic_free); } + else + { + XEvent ev; + Atom target_list[2]; + static Atom xa_targets = None; + + if (xa_targets == None) + xa_targets = XInternAtom(xevent->xselectionrequest.display, + "TARGETS", False); + ev.xselection.type = SelectionNotify; + ev.xselection.property = None; + ev.xselection.display = xevent->xselectionrequest.display; + ev.xselection.requestor = xevent->xselectionrequest.requestor; + ev.xselection.selection = xevent->xselectionrequest.selection; + ev.xselection.target = xevent->xselectionrequest.target; + ev.xselection.time = xevent->xselectionrequest.time; + if (xevent->xselectionrequest.target == xa_targets) + { + target_list[0] = (Atom) xa_targets; + target_list[1] = (Atom) XA_STRING; + XChangeProperty(xevent->xselectionrequest.display, + xevent->xselectionrequest.requestor, + xevent->xselectionrequest.property, + xevent->xselectionrequest.target, + (8 * sizeof(target_list[0])), + PropModeReplace, + (unsigned char *) target_list, + (sizeof(target_list) / sizeof(target_list[0]))); + ev.xselection.property = xevent->xselectionrequest.property; + } + else if (xevent->xselectionrequest.target == XA_STRING) + { + void *data; + int size; + + data = e_window_property_get(xevent->xselectionrequest.owner, + atom_text_selection, XA_STRING, + &size); + if (data) + { + XChangeProperty(xevent->xselectionrequest.display, + xevent->xselectionrequest.requestor, + xevent->xselectionrequest.property, + xevent->xselectionrequest.target, + 8, + PropModeReplace, + data, size); + FREE(data); + } + ev.xselection.property = xevent->xselectionrequest.property; + } + XSendEvent(xevent->xselectionrequest.display, + xevent->xselectionrequest.requestor, False, 0, &ev); + printf("%i %i %i : %i, %i (%x %x %x)\n", + xevent->xselectionrequest.selection, /* XA_PRIMARY */ + xevent->xselectionrequest.target, /* XA_STRING */ + xevent->xselectionrequest.property, /* the destination atiom */ + atom_text_selection, XA_STRING, + xevent->xselectionrequest.owner, /* the window we put it on */ + xevent->xselectionrequest.requestor /* where to put the prop */); + } } static void diff --git a/legacy/ecore/src/e_x.c b/legacy/ecore/src/e_x.c index eff2da9c2b..cb64d577b6 100644 --- a/legacy/ecore/src/e_x.c +++ b/legacy/ecore/src/e_x.c @@ -2899,17 +2899,41 @@ e_keyboard_ungrab(void) #define X_CLIPBOARD_PROP XA_CUT_BUFFER0 #endif +Window +e_selection_set(char *string) +{ + Window target = 0; + static Atom dest = 0; + Atom selection; + + selection = X_CLIPBOARD_SELECTION; + E_ATOM(dest, "TEXT_SELECTION"); + target = e_window_new(0, 0, 0, 77, 7); + e_window_add_events(target, XEV_CONFIGURE | XEV_PROPERTY); + XSetSelectionOwner(disp, selection, target, CurrentTime); + if (XGetSelectionOwner(disp, XA_PRIMARY) != target) + { + e_window_destroy(target); + return 0; + } + XChangeProperty(disp, target, dest, + XA_STRING, 8, PropModeReplace, + string, strlen(string)); + printf("window %x\n", target); + return target; +} + Window e_selection_request(void) { - Atom selection, dest = 0; - static Window target = 0; + static Atom dest = 0; + Atom selection; + Window target = 0; selection = X_CLIPBOARD_SELECTION; E_ATOM(dest, "TEXT_SELECTION"); target = e_window_new(0, 0, 0, 7, 77); - e_window_add_events(target, - XEV_CONFIGURE | XEV_PROPERTY); + e_window_add_events(target, XEV_CONFIGURE | XEV_PROPERTY); XConvertSelection(disp, XA_PRIMARY, XA_STRING, dest, target,