Changeset 199

Show
Ignore:
Timestamp:
01/12/08 23:09:19 (1 year ago)
Author:
conrad
Message:

automatically determine whether or not the selection owner can handle
UTF8_STRING, rather than requiring the user to decide.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • xsel/trunk/xsel.c

    r198 r199  
    6262static Atom text_atom; /* The TEXT atom */ 
    6363static Atom utf8_atom; /* The UTF8 atom */ 
    64 static Atom local_target; /* UTF8_STRING or STRING */ 
    6564 
    6665/* Number of selection targets served by this. 
     
    629628                                        *(int *)value); 
    630629          keep_waiting = False; 
    631         } else if (target != utf8_atom && target != XA_STRING && request_target != delete_atom) { 
     630        } else if (target != utf8_atom && target != XA_STRING && 
     631                   request_target != delete_atom) { 
    632632          /* Report non-TEXT atoms */ 
    633633          print_debug (D_WARN, "Selection (type %s) is not a string.", 
     
    705705  return retval; 
    706706} 
     707 
     708/* 
     709 * get_selection_text (Atom selection) 
     710 * 
     711 * Retrieve a text selection. First attempt to retrieve it as UTF_STRING, 
     712 * and if that fails attempt to retrieve it as a plain XA_STRING. 
     713 * 
     714 * NB. Before implementing this, an attempt was made to query TARGETS and 
     715 * request UTF8_STRING only if listed there, as described in: 
     716 * http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/UTF8_STRING.text 
     717 * However, that did not seem to work reliably when tested against various 
     718 * applications (eg. Mozilla Firefox). This method is of course more 
     719 * reliable. 
     720 */ 
     721static unsigned char * 
     722get_selection_text (Atom selection) 
     723{ 
     724  unsigned char * retval; 
     725 
     726  if ((retval = get_selection (selection, utf8_atom)) == NULL) 
     727    retval = get_selection (selection, XA_STRING); 
     728 
     729  return retval; 
     730} 
     731 
    707732 
    708733/* 
     
    13031328static HandleResult 
    13041329handle_utf8_string (Display * display, Window requestor, Atom property, 
    1305                unsigned char * sel, Atom selection, Time time, 
    1306                MultTrack * mparent) 
     1330                    unsigned char * sel, Atom selection, Time time, 
     1331                    MultTrack * mparent) 
    13071332{ 
    13081333  return 
     
    13601385    } else if (mt->atoms[i] == utf8_atom) { 
    13611386      retval |= handle_utf8_string (mt->display, mt->requestor, mt->atoms[i+1], 
    1362                                mt->sel, mt->selection, mt->time, mt); 
     1387                                    mt->sel, mt->selection, mt->time, mt); 
    13631388    } else if (mt->atoms[i] == delete_atom) { 
    13641389      retval |= handle_delete (mt->display, mt->requestor, mt->atoms[i+1]); 
     
    15371562    ev.property = xsr->property; 
    15381563    hr = handle_utf8_string (ev.display, ev.requestor, ev.property, sel, 
    1539                         ev.selection, ev.time, NULL); 
     1564                             ev.selection, ev.time, NULL); 
    15401565  } else if (ev.target == delete_atom) { 
    15411566    /* Received DELETE request */ 
     
    17501775  unsigned char * text1, * text2; 
    17511776 
    1752   text1 = get_selection (XA_PRIMARY, local_target); 
    1753   text2 = get_selection (XA_SECONDARY, local_target); 
     1777  text1 = get_selection_text (XA_PRIMARY); 
     1778  text2 = get_selection_text (XA_SECONDARY); 
    17541779 
    17551780  set_selection_pair__daemon (text1, text2); 
     
    17681793  unsigned char * text1, * text2; 
    17691794 
    1770   text1 = get_selection (XA_PRIMARY, local_target); 
    1771   text2 = get_selection (XA_SECONDARY, local_target); 
     1795  text1 = get_selection_text (XA_PRIMARY); 
     1796  text2 = get_selection_text (XA_SECONDARY); 
    17721797 
    17731798  set_selection_pair__daemon (text2, text1); 
     
    19451970 
    19461971  NUM_TARGETS=0; 
     1972 
    19471973  /* Get the TIMESTAMP atom */ 
    19481974  timestamp_atom = XInternAtom (display, "TIMESTAMP", False); 
     
    19912017  NUM_TARGETS++; 
    19922018 
    1993   if( need_utf8 == True) { 
    1994     local_target=utf8_atom; 
    1995   } else { 
    1996     local_target=XA_STRING; 
    1997   } 
    1998  
    19992019  /* handle selection keeping and exit if so */ 
    20002020  if (do_keep) { 
     
    20172037  if (do_output || !dont_output) { 
    20182038    /* Get the current selection */ 
    2019     old_sel = get_selection (selection, local_target); 
     2039    old_sel = get_selection_text (selection); 
    20202040    if (old_sel) printf ("%s", old_sel); 
    20212041  } 
     
    20292049  else if (do_input || !dont_input) { 
    20302050    if (do_append) { 
    2031       if (!old_sel) old_sel = get_selection (selection, local_target); 
     2051      if (!old_sel) old_sel = get_selection_text (selection); 
    20322052      new_sel = copy_sel (old_sel); 
    20332053    }