… | |
… | |
2435 | rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop) |
2435 | rxvt_selection_paste(pR_ Window win, Atom prop, Bool delete_prop) |
2436 | { |
2436 | { |
2437 | long nread = 0; |
2437 | long nread = 0; |
2438 | unsigned long bytes_after; |
2438 | unsigned long bytes_after; |
2439 | XTextProperty ct; |
2439 | XTextProperty ct; |
2440 | int dummy_count; |
|
|
2441 | char **cl; |
|
|
2442 | |
2440 | |
2443 | D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait)); |
2441 | D_SELECT((stderr, "rxvt_selection_paste(%08lx, %lu, %d), wait=%2x", win, (unsigned long)prop, (int)delete_prop, R->selection_wait)); |
2444 | |
2442 | |
2445 | if (prop == None) /* check for failed XConvertSelection */ |
2443 | if (prop == None) /* check for failed XConvertSelection */ |
2446 | { |
2444 | { |
… | |
… | |
2449 | int selnum = R->selection_type & Sel_whereMask; |
2447 | int selnum = R->selection_type & Sel_whereMask; |
2450 | |
2448 | |
2451 | R->selection_type = 0; |
2449 | R->selection_type = 0; |
2452 | if (selnum != Sel_direct) |
2450 | if (selnum != Sel_direct) |
2453 | rxvt_selection_request_other(aR_ XA_STRING, selnum); |
2451 | rxvt_selection_request_other(aR_ XA_STRING, selnum); |
|
|
2452 | } |
|
|
2453 | |
|
|
2454 | if ((R->selection_type & Sel_UTF8String)) |
|
|
2455 | { |
|
|
2456 | int selnum = R->selection_type & Sel_whereMask; |
|
|
2457 | |
|
|
2458 | R->selection_type = Sel_CompoundText; |
|
|
2459 | if (selnum != Sel_direct) |
|
|
2460 | rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], selnum); |
|
|
2461 | else |
|
|
2462 | R->selection_type = 0; |
2454 | } |
2463 | } |
2455 | |
2464 | |
2456 | return 0; |
2465 | return 0; |
2457 | } |
2466 | } |
2458 | |
2467 | |
… | |
… | |
2493 | nread = -1; /* discount any previous stuff */ |
2502 | nread = -1; /* discount any previous stuff */ |
2494 | break; |
2503 | break; |
2495 | } |
2504 | } |
2496 | |
2505 | |
2497 | nread += ct.nitems; |
2506 | nread += ct.nitems; |
|
|
2507 | |
|
|
2508 | char **cl; |
|
|
2509 | int cr; |
2498 | if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl, |
2510 | if (XmbTextPropertyToTextList (R->Xdisplay, &ct, &cl, |
2499 | &dummy_count) == Success && cl) |
2511 | &cr) >= 0 && cl) |
2500 | { |
2512 | { |
|
|
2513 | for (int i = 0; i < cr; i++) |
2501 | R->paste ((unsigned char *)cl[0], STRLEN (cl[0])); |
2514 | R->paste ((unsigned char *)cl[i], STRLEN (cl[i])); |
|
|
2515 | |
2502 | XFreeStringList (cl); |
2516 | XFreeStringList (cl); |
2503 | } |
2517 | } |
2504 | else |
2518 | else |
2505 | R->paste (ct.value, ct.nitems); |
2519 | R->paste (ct.value, ct.nitems); |
2506 | |
2520 | |
… | |
… | |
2599 | int i; |
2613 | int i; |
2600 | |
2614 | |
2601 | R->selection_request_time = tm; |
2615 | R->selection_request_time = tm; |
2602 | R->selection_wait = Sel_normal; |
2616 | R->selection_wait = Sel_normal; |
2603 | for (i = Sel_Primary; i <= Sel_Clipboard; i++) { |
2617 | for (i = Sel_Primary; i <= Sel_Clipboard; i++) { |
|
|
2618 | #if X_HAVE_UTF8_STRING |
|
|
2619 | R->selection_type = Sel_UTF8String; |
|
|
2620 | if (rxvt_selection_request_other(aR_ R->xa[XA_UTF8_STRING], i)) |
|
|
2621 | return; |
|
|
2622 | #else |
2604 | R->selection_type = Sel_CompoundText; |
2623 | R->selection_type = Sel_CompoundText; |
2605 | if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i)) |
2624 | if (rxvt_selection_request_other(aR_ R->xa[XA_COMPOUND_TEXT], i)) |
2606 | return; |
2625 | return; |
|
|
2626 | #endif |
2607 | } |
2627 | } |
2608 | } |
2628 | } |
2609 | R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */ |
2629 | R->selection_wait = Sel_none; /* don't loop in rxvt_selection_paste() */ |
2610 | D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0")); |
2630 | D_SELECT((stderr, "rxvt_selection_request: pasting CUT_BUFFER0")); |
2611 | rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False); |
2631 | rxvt_selection_paste(aR_ Xroot, XA_CUT_BUFFER0, False); |
… | |
… | |
2743 | { |
2763 | { |
2744 | free (new_selection_text); |
2764 | free (new_selection_text); |
2745 | return; |
2765 | return; |
2746 | } |
2766 | } |
2747 | |
2767 | |
2748 | // due to MB_MAX_CUR, selection wastage is usually high |
2768 | // due to MB_MAX_CUR, selection wastage is usually high, so realloc |
2749 | if (str - (char *)new_selection_text > 1024) |
2769 | if (str - (char *)new_selection_text > 1024) |
2750 | new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); |
2770 | new_selection_text = (unsigned char *)rxvt_realloc (new_selection_text, i + 1); |
2751 | |
2771 | |
2752 | R->selection.len = i; |
2772 | R->selection.len = i; |
|
|
2773 | |
2753 | if (R->selection.text) |
2774 | if (R->selection.text) |
2754 | free (R->selection.text); |
2775 | free (R->selection.text); |
2755 | |
2776 | |
2756 | R->selection.text = new_selection_text; |
2777 | R->selection.text = new_selection_text; |
2757 | |
2778 | |
2758 | XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm); |
2779 | XSetSelectionOwner(R->Xdisplay, XA_PRIMARY, R->TermWin.vt, tm); |
2759 | if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt) |
2780 | if (XGetSelectionOwner(R->Xdisplay, XA_PRIMARY) != R->TermWin.vt) |
2760 | rxvt_print_error("can't get primary selection"); |
2781 | rxvt_print_error("can't get primary selection"); |
|
|
2782 | |
|
|
2783 | |
|
|
2784 | { |
|
|
2785 | XTextProperty ct; |
|
|
2786 | char *cl = (char *)R->selection.text; |
|
|
2787 | |
|
|
2788 | if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, XStringStyle, &ct) >= 0) |
|
|
2789 | { |
|
|
2790 | XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, |
|
|
2791 | PropModeReplace, ct.value, ct.nitems); |
|
|
2792 | XFree (ct.value); |
|
|
2793 | } |
|
|
2794 | else |
2761 | XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, |
2795 | XChangeProperty(R->Xdisplay, Xroot, XA_CUT_BUFFER0, XA_STRING, 8, |
2762 | PropModeReplace, R->selection.text, (int)R->selection.len); |
2796 | PropModeReplace, R->selection.text, (int)R->selection.len); |
|
|
2797 | } |
|
|
2798 | |
2763 | R->selection_time = tm; |
2799 | R->selection_time = tm; |
2764 | D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len)); |
2800 | D_SELECT((stderr, "rxvt_selection_make(): R->selection.len=%d", R->selection.len)); |
2765 | } |
2801 | } |
2766 | |
2802 | |
2767 | /* ------------------------------------------------------------------------- */ |
2803 | /* ------------------------------------------------------------------------- */ |
… | |
… | |
3219 | /* |
3255 | /* |
3220 | * On some systems, the Atom typedef is 64 bits wide. We need to have a type |
3256 | * On some systems, the Atom typedef is 64 bits wide. We need to have a type |
3221 | * that is exactly 32 bits wide, because a format of 64 is not allowed by |
3257 | * that is exactly 32 bits wide, because a format of 64 is not allowed by |
3222 | * the X11 protocol. |
3258 | * the X11 protocol. |
3223 | */ |
3259 | */ |
3224 | typedef CARD32 Atom32; |
3260 | typedef CARD32 Atom32; |
3225 | |
3261 | |
3226 | /* ------------------------------------------------------------------------- */ |
3262 | /* ------------------------------------------------------------------------- */ |
3227 | /* |
3263 | /* |
3228 | * Respond to a request for our current selection |
3264 | * Respond to a request for our current selection |
3229 | * EXT: SelectionRequest |
3265 | * EXT: SelectionRequest |
… | |
… | |
3231 | /* EXTPROTO */ |
3267 | /* EXTPROTO */ |
3232 | void |
3268 | void |
3233 | rxvt_selection_send(pR_ const XSelectionRequestEvent *rq) |
3269 | rxvt_selection_send(pR_ const XSelectionRequestEvent *rq) |
3234 | { |
3270 | { |
3235 | XSelectionEvent ev; |
3271 | XSelectionEvent ev; |
3236 | #ifdef USE_XIM |
|
|
3237 | Atom32 target_list[4]; |
|
|
3238 | #else |
|
|
3239 | Atom32 target_list[3]; |
|
|
3240 | #endif |
|
|
3241 | Atom target; |
|
|
3242 | XTextProperty ct; |
3272 | XTextProperty ct; |
3243 | XICCEncodingStyle style; |
3273 | XICCEncodingStyle style; |
3244 | char *cl[2], dummy[1]; |
3274 | Atom target; |
3245 | |
3275 | |
3246 | ev.type = SelectionNotify; |
3276 | ev.type = SelectionNotify; |
3247 | ev.property = None; |
3277 | ev.property = None; |
3248 | ev.display = rq->display; |
3278 | ev.display = rq->display; |
3249 | ev.requestor = rq->requestor; |
3279 | ev.requestor = rq->requestor; |
3250 | ev.selection = rq->selection; |
3280 | ev.selection = rq->selection; |
3251 | ev.target = rq->target; |
3281 | ev.target = rq->target; |
3252 | ev.time = rq->time; |
3282 | ev.time = rq->time; |
3253 | |
3283 | |
3254 | if (rq->target == R->xa[XA_TARGETS]) { |
3284 | if (rq->target == R->xa[XA_TARGETS]) { |
|
|
3285 | Atom32 target_list[5]; |
|
|
3286 | Atom32 *target = target_list; |
|
|
3287 | |
3255 | target_list[0] = (Atom32) R->xa[XA_TARGETS]; |
3288 | *target++ = (Atom32) R->xa[XA_TARGETS]; |
3256 | target_list[1] = (Atom32) XA_STRING; |
3289 | *target++ = (Atom32) XA_STRING; |
3257 | target_list[2] = (Atom32) R->xa[XA_TEXT]; |
3290 | *target++ = (Atom32) R->xa[XA_TEXT]; |
3258 | #ifdef USE_XIM |
|
|
3259 | target_list[3] = (Atom32) R->xa[XA_COMPOUND_TEXT]; |
3291 | *target++ = (Atom32) R->xa[XA_COMPOUND_TEXT]; |
|
|
3292 | #if X_HAVE_UTF8_STRING |
|
|
3293 | *target++ = (Atom32) R->xa[XA_UTF8_STRING]; |
3260 | #endif |
3294 | #endif |
3261 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM, |
3295 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_ATOM, |
3262 | (8 * sizeof(target_list[0])), PropModeReplace, |
3296 | (8 * sizeof(target_list[0])), PropModeReplace, |
3263 | (unsigned char *)target_list, |
3297 | (unsigned char *)target_list, |
3264 | (sizeof(target_list) / sizeof(target_list[0]))); |
3298 | target - target_list); |
3265 | ev.property = rq->property; |
3299 | ev.property = rq->property; |
3266 | } else if (rq->target == R->xa[XA_MULTIPLE]) { |
3300 | } else if (rq->target == R->xa[XA_MULTIPLE]) { |
3267 | /* TODO: Handle MULTIPLE */ |
3301 | /* TODO: Handle MULTIPLE */ |
3268 | } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) { |
3302 | } else if (rq->target == R->xa[XA_TIMESTAMP] && R->selection.text) { |
3269 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER, |
3303 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, XA_INTEGER, |
3270 | (8 * sizeof(Time)), PropModeReplace, |
3304 | (8 * sizeof(Time)), PropModeReplace, |
3271 | (unsigned char *)&R->selection_time, 1); |
3305 | (unsigned char *)&R->selection_time, 1); |
3272 | ev.property = rq->property; |
3306 | ev.property = rq->property; |
3273 | } else if (rq->target == XA_STRING |
3307 | } else if (rq->target == XA_STRING |
|
|
3308 | || rq->target == R->xa[XA_TEXT] |
3274 | || rq->target == R->xa[XA_COMPOUND_TEXT] |
3309 | || rq->target == R->xa[XA_COMPOUND_TEXT] |
3275 | || rq->target == R->xa[XA_TEXT]) { |
3310 | || rq->target == R->xa[XA_UTF8_STRING] |
3276 | #ifdef USE_XIM |
3311 | ) { |
3277 | short freect = 0; |
3312 | short freect = 0; |
3278 | #endif |
|
|
3279 | int selectlen; |
3313 | int selectlen; |
|
|
3314 | char *cl; |
3280 | |
3315 | |
3281 | #ifdef USE_XIM |
3316 | target = rq->target; |
|
|
3317 | |
3282 | if (rq->target != XA_STRING) { |
3318 | if (target == XA_STRING) |
|
|
3319 | // we actually don't do XA_STRING, but who cares, as i18n clients |
|
|
3320 | // will ask for another format anyways. |
|
|
3321 | style = XStringStyle; |
|
|
3322 | else if (target == R->xa[XA_TEXT]) |
|
|
3323 | style = XTextStyle; |
|
|
3324 | else if (target == R->xa[XA_COMPOUND_TEXT]) |
|
|
3325 | style = XCompoundTextStyle; |
|
|
3326 | #if X_HAVE_UTF8_STRING |
|
|
3327 | else if (target == R->xa[XA_UTF8_STRING]) |
|
|
3328 | style = XUTF8StringStyle; |
|
|
3329 | #endif |
|
|
3330 | else |
|
|
3331 | { |
3283 | target = R->xa[XA_COMPOUND_TEXT]; |
3332 | target = R->xa[XA_COMPOUND_TEXT]; |
3284 | style = (rq->target == R->xa[XA_COMPOUND_TEXT]) |
|
|
3285 | ? XCompoundTextStyle : XStdICCTextStyle; |
|
|
3286 | } else |
|
|
3287 | #endif |
|
|
3288 | { |
|
|
3289 | target = XA_STRING; |
|
|
3290 | style = XStringStyle; |
3333 | style = XCompoundTextStyle; |
3291 | } |
3334 | } |
|
|
3335 | |
3292 | if (R->selection.text) { |
3336 | if (R->selection.text) { |
3293 | cl[0] = (char *)R->selection.text; |
3337 | cl = (char *)R->selection.text; |
3294 | selectlen = R->selection.len; |
3338 | selectlen = R->selection.len; |
3295 | } else { |
3339 | } else { |
3296 | cl[0] = dummy; |
3340 | cl = ""; |
3297 | *dummy = '\0'; |
|
|
3298 | selectlen = 0; |
3341 | selectlen = 0; |
3299 | } |
3342 | } |
3300 | #ifdef USE_XIM |
3343 | |
3301 | if (XmbTextListToTextProperty(R->Xdisplay, cl, 1, style, &ct) |
3344 | if (XmbTextListToTextProperty(R->Xdisplay, &cl, 1, style, &ct) >= 0) |
3302 | == Success) /* if we failed to convert then send it raw */ |
|
|
3303 | freect = 1; |
3345 | freect = 1; |
3304 | else |
3346 | else |
3305 | #endif |
|
|
3306 | { |
3347 | { |
|
|
3348 | /* if we failed to convert then send it raw */ |
3307 | ct.value = (unsigned char *)cl[0]; |
3349 | ct.value = (unsigned char *)cl; |
3308 | ct.nitems = selectlen; |
3350 | ct.nitems = selectlen; |
3309 | } |
3351 | } |
|
|
3352 | |
3310 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, |
3353 | XChangeProperty(R->Xdisplay, rq->requestor, rq->property, |
3311 | target, 8, PropModeReplace, |
3354 | target, 8, PropModeReplace, |
3312 | ct.value, (int)ct.nitems); |
3355 | ct.value, (int)ct.nitems); |
3313 | ev.property = rq->property; |
3356 | ev.property = rq->property; |
3314 | #ifdef USE_XIM |
3357 | |
3315 | if (freect) |
3358 | if (freect) |
3316 | XFree(ct.value); |
3359 | XFree (ct.value); |
3317 | #endif |
|
|
3318 | } |
3360 | } |
3319 | XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev); |
3361 | XSendEvent(R->Xdisplay, rq->requestor, False, 0L, (XEvent *)&ev); |
3320 | } |
3362 | } |
3321 | |
3363 | |
3322 | /* ------------------------------------------------------------------------- * |
3364 | /* ------------------------------------------------------------------------- * |