--- rxvt-unicode/src/rxvttoolkit.C 2011/02/12 00:50:04 1.118 +++ rxvt-unicode/src/rxvttoolkit.C 2011/05/11 18:41:33 1.125 @@ -3,7 +3,7 @@ *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. - * Copyright (c) 2003-2007 Marc Lehmann + * Copyright (c) 2003-2011 Marc Lehmann * Copyright (c) 2011 Emanuele Giaquinta * * This program is free software; you can redistribute it and/or modify @@ -705,10 +705,16 @@ c.color.blue = color.b; c.color.alpha = alpha; - c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) - | insert_component (color.g, format->direct.greenMask, format->direct.green) - | insert_component (color.b, format->direct.blueMask , format->direct.blue ) - | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); + // Xft wants premultiplied alpha, but abuses the alpha channel + // as blend factor, and doesn't allow us to set the alpha channel + c.color.red = c.color.red * alpha / 0xffff; + c.color.green = c.color.green * alpha / 0xffff; + c.color.blue = c.color.blue * alpha / 0xffff; + + c.pixel = insert_component (c.color.red , format->direct.redMask , format->direct.red ) + | insert_component (c.color.green, format->direct.greenMask, format->direct.green) + | insert_component (c.color.blue , format->direct.blueMask , format->direct.blue ) + | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); return true; } @@ -894,8 +900,8 @@ ); } -rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, sel_cb cb, void *ptr) -: display (disp), request_time (tm), request_win (win), request_prop (prop), request_cb (cb), user_data (ptr) +rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, rxvt_term *term) +: display (disp), request_time (tm), request_win (win), request_prop (prop), term (term) { assert (selnum >= Sel_Primary && selnum <= Sel_Clipboard); @@ -910,10 +916,35 @@ } void +rxvt_selection::stop () +{ + free (incr_buf); + incr_buf = 0; + timer_ev.stop (); + x_ev.stop (display); +} + +rxvt_selection::~rxvt_selection () +{ + stop (); +} + +void rxvt_selection::run () { int selnum = selection_type; +#if ENABLE_FRILLS + if (selnum == Sel_Primary && display->selection_owner) + { + /* internal selection */ + char *str = rxvt_wcstombs (display->selection_owner->selection.text, display->selection_owner->selection.len); + finish (str, strlen (str)); + free (str); + return; + } +#endif + #if X_HAVE_UTF8_STRING selection_type = Sel_UTF8String; if (request (display->xa[XA_UTF8_STRING], selnum)) @@ -928,18 +959,24 @@ handle_selection (display->root, XA_CUT_BUFFER0, false); } -rxvt_selection::~rxvt_selection () -{ - stop (); -} - void -rxvt_selection::stop () +rxvt_selection::finish (char *data, unsigned int len) { - free (incr_buf); - incr_buf = 0; - timer_ev.stop (); - x_ev.stop (display); + if (term) + { + if (data) + term->paste (data, len); + + term->selection_req = 0; + delete this; + } +#if ENABLE_PERL + else + { + stop (); // we do not really trust perl callbacks + rxvt_perl.selection_finish (this, data, len); + } +#endif } bool @@ -1114,8 +1151,7 @@ if (selection_wait == Sel_normal) { - stop (); - request_cb (data, data_len, this); + finish (data, data_len); free (data); } } @@ -1126,8 +1162,7 @@ if (selection_wait == Sel_incr) rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); - stop (); - request_cb (NULL, 0, this); + finish (); } void