Changeset 192
- Timestamp:
- 12/05/07 15:36:24 (1 year ago)
- Files:
-
- xsel/trunk/xsel.1x (modified) (2 diffs)
- xsel/trunk/xsel.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
xsel/trunk/xsel.1x
r188 r192 81 81 82 82 .PP 83 \fBEncoding options\fR 84 .TP 85 \fB\-u\fR, \fB\-\-utf8\fR 86 Request selection in UTF8 if possible. 87 This option is useful when working with selections in national 88 (non Latin-1) charsets. If your X-server and target application 89 support UTF8_STRING exchange, then selection is returned as 90 UTF8 string. If your X-server doesn't support this extension, 91 option has no effect. If target application doesn's support 92 UTF8 selection target, empty selection is returned. 93 94 .PP 83 95 \fBX options\fR 84 96 .TP … … 109 121 debugging level, ie. print more information. 110 122 .TP 111 \fB\- v\fR, \fB\-\-version\fR123 \fB\-\-version\fR 112 124 output version information and exit 113 125 .PP xsel/trunk/xsel.c
r191 r192 57 57 static Atom null_atom; /* The NULL atom */ 58 58 static Atom text_atom; /* The TEXT atom */ 59 static Atom utf8_atom; /* The UTF8 atom */ 60 static Atom local_target; /* UTF8_STRING or STRING */ 59 61 60 62 /* Number of selection targets served by this. 61 * (MULTIPLE, INCR, TARGETS, TIMESTAMP, DELETE, TEXT and STRING) */ 62 #define NUM_TARGETS 7 63 static Atom supported_targets[NUM_TARGETS]; 63 * (MULTIPLE, INCR, TARGETS, TIMESTAMP, DELETE, TEXT, UTF8_STRING and STRING) */ 64 #define MAX_NUM_TARGETS 8 65 static int NUM_TARGETS; 66 static Atom supported_targets[MAX_NUM_TARGETS]; 64 67 65 68 /* do_follow: Follow mode for output */ … … 109 112 printf (" -d, --delete Request that the selection be cleared and that\n"); 110 113 printf (" the application owning it delete its contents\n\n"); 114 printf ("Encoding options\n"); 115 printf (" -u, --utf8 Request selection in UTF-8 if possible\n\n"); 111 116 printf ("Selection options\n"); 112 117 printf (" -p, --primary Operate on the PRIMARY selection (default)\n"); … … 226 231 if (atom == null_atom) return "NULL"; 227 232 if (atom == text_atom) return "TEXT"; 233 if (utf8_atom!=XA_STRING && atom == utf8_atom) return "UTF8_STRING"; 228 234 if (atom == XInternAtom (display, "XSEL_DATA", True)) return "XSEL_DATA"; 229 235 … … 598 604 *(int *)value); 599 605 keep_waiting = False; 600 } else if (target != XA_STRING && request_target != delete_atom) {606 } else if (target != utf8_atom && target != XA_STRING && request_target != delete_atom) { 601 607 /* Report non-TEXT atoms */ 602 608 print_debug (D_WARN, "Selection (type %s) is not a string.", … … 1266 1272 1267 1273 /* 1274 * handle_utf8_string (display, requestor, property, sel) 1275 * 1276 * Handle a UTF8_STRING request; setting 'sel' as the data 1277 */ 1278 static HandleResult 1279 handle_utf8_string (Display * display, Window requestor, Atom property, 1280 unsigned char * sel, Atom selection, Time time, 1281 MultTrack * mparent) 1282 { 1283 return 1284 change_property (display, requestor, property, utf8_atom, 8, 1285 PropModeReplace, sel, strlen(sel), 1286 selection, time, mparent); 1287 } 1288 1289 /* 1268 1290 * handle_delete (display, requestor, property) 1269 1291 * … … 1310 1332 } else if (mt->atoms[i] == XA_STRING || mt->atoms[i] == text_atom) { 1311 1333 retval |= handle_string (mt->display, mt->requestor, mt->atoms[i+1], 1334 mt->sel, mt->selection, mt->time, mt); 1335 } else if (mt->atoms[i] == utf8_atom) { 1336 retval |= handle_utf8_string (mt->display, mt->requestor, mt->atoms[i+1], 1312 1337 mt->sel, mt->selection, mt->time, mt); 1313 1338 } else if (mt->atoms[i] == delete_atom) { … … 1482 1507 ev.property = xsr->property; 1483 1508 hr = handle_string (ev.display, ev.requestor, ev.property, sel, 1509 ev.selection, ev.time, NULL); 1510 } else if (ev.target == utf8_atom) { 1511 /* Received UTF8_STRING request */ 1512 ev.property = xsr->property; 1513 hr = handle_utf8_string (ev.display, ev.requestor, ev.property, sel, 1484 1514 ev.selection, ev.time, NULL); 1485 1515 } else if (ev.target == delete_atom) { … … 1695 1725 unsigned char * text1, * text2; 1696 1726 1697 text1 = get_selection (XA_PRIMARY, XA_STRING);1698 text2 = get_selection (XA_SECONDARY, XA_STRING);1727 text1 = get_selection (XA_PRIMARY, local_target); 1728 text2 = get_selection (XA_SECONDARY, local_target); 1699 1729 1700 1730 set_selection_pair__daemon (text1, text2); … … 1713 1743 unsigned char * text1, * text2; 1714 1744 1715 text1 = get_selection (XA_PRIMARY, XA_STRING);1716 text2 = get_selection (XA_SECONDARY, XA_STRING);1745 text1 = get_selection (XA_PRIMARY, local_target); 1746 text2 = get_selection (XA_SECONDARY, local_target); 1717 1747 1718 1748 set_selection_pair__daemon (text2, text1); … … 1753 1783 char * display_name = NULL; 1754 1784 long timeout_ms = 0L; 1785 int need_utf8 = False; 1755 1786 1756 1787 progname = argv[0]; … … 1778 1809 do_append = True; 1779 1810 dont_output = True; 1811 } else if (OPT("--utf8") || OPT("-u")) { 1812 need_utf8 = True; 1780 1813 } else if (OPT("--input") || OPT("-i")) { 1781 1814 do_input = True; … … 1880 1913 print_debug (D_WARN, "XA_SECONDARY not named \"SECONDARY\"\n"); 1881 1914 1915 NUM_TARGETS=0; 1882 1916 /* Get the TIMESTAMP atom */ 1883 1917 timestamp_atom = XInternAtom (display, "TIMESTAMP", False); 1884 1918 supported_targets[s++] = timestamp_atom; 1919 NUM_TARGETS++; 1885 1920 1886 1921 /* Get the MULTIPLE atom */ 1887 1922 multiple_atom = XInternAtom (display, "MULTIPLE", False); 1888 1923 supported_targets[s++] = multiple_atom; 1924 NUM_TARGETS++; 1889 1925 1890 1926 /* Get the TARGETS atom */ 1891 1927 targets_atom = XInternAtom (display, "TARGETS", False); 1892 1928 supported_targets[s++] = targets_atom; 1929 NUM_TARGETS++; 1893 1930 1894 1931 /* Get the DELETE atom */ 1895 1932 delete_atom = XInternAtom (display, "DELETE", False); 1896 1933 supported_targets[s++] = delete_atom; 1934 NUM_TARGETS++; 1897 1935 1898 1936 /* Get the INCR atom */ 1899 1937 incr_atom = XInternAtom (display, "INCR", False); 1900 1938 supported_targets[s++] = incr_atom; 1939 NUM_TARGETS++; 1901 1940 1902 1941 /* Get the NULL atom */ 1903 1942 null_atom = XInternAtom (display, "NULL", False); 1943 NUM_TARGETS++; 1904 1944 1905 1945 /* Get the TEXT atom */ 1906 1946 text_atom = XInternAtom (display, "TEXT", False); 1907 1947 supported_targets[s++] = text_atom; 1948 NUM_TARGETS++; 1949 1950 /* Get the UTF8_STRING atom */ 1951 utf8_atom = XInternAtom (display, "UTF8_STRING", True); 1952 if( utf8_atom != None) 1953 { 1954 supported_targets[s++] = utf8_atom; 1955 NUM_TARGETS++; 1956 } 1957 else 1958 { 1959 utf8_atom = XA_STRING; 1960 } 1908 1961 1909 1962 supported_targets[s++] = XA_STRING; 1910 1963 NUM_TARGETS++; 1964 1965 if( need_utf8 == True) 1966 { 1967 local_target=utf8_atom; 1968 } 1969 else 1970 { 1971 local_target=XA_STRING; 1972 } 1911 1973 /* handle selection keeping and exit if so */ 1912 1974 if (do_keep) { … … 1929 1991 if (do_output || !dont_output) { 1930 1992 /* Get the current selection */ 1931 old_sel = get_selection (selection, XA_STRING);1993 old_sel = get_selection (selection, local_target); 1932 1994 if (old_sel) printf ("%s", old_sel); 1933 1995 } … … 1941 2003 else if (do_input || !dont_input) { 1942 2004 if (do_append) { 1943 if (!old_sel) old_sel = get_selection (selection, XA_STRING);2005 if (!old_sel) old_sel = get_selection (selection, local_target); 1944 2006 new_sel = copy_sel (old_sel); 1945 2007 }
