Ticket #30: mc-4.6.1-xclip.patch
File mc-4.6.1-xclip.patch, 24.6 KB (added by angel_il, 15 years ago) |
---|
-
config.h.in
diff -Naur mc-4.6.1-orig/config.h.in mc-4.6.1/config.h.in
old new 472 472 /* Define to 1 if you have the <utime.h> header file. */ 473 473 #undef HAVE_UTIME_H 474 474 475 /* Define to 1 if you enable xclipboard support */ 476 #undef HAVE_XCLIP 477 475 478 /* Define to 1 if you have the `__argz_count' function. */ 476 479 #undef HAVE___ARGZ_COUNT 477 480 -
configure.ac
diff -Naur mc-4.6.1-orig/configure.ac mc-4.6.1/configure.ac
old new 548 548 fi 549 549 fi 550 550 551 dnl 552 dnl Support xclipboard 553 dnl 554 AC_ARG_ENABLE([xclipboard], 555 [ --with-xclip Support xwindow clipboard [[no]]]) 556 have_xclip= 557 xclip_msg="no" 558 if test "x$with_xclip" = xyes; then 559 AC_DEFINE(HAVE_XCLIP, 1, [Define to enable xclipboard support]) 560 have_xclip=yes 561 xclip_msg="yes" 562 fi 563 564 565 551 566 if test "$GLIBC21" != yes; then 552 567 AC_DEFINE(USE_INCLUDED_REGEX, 1, [Use the regex included here]) 553 568 fi -
edit/editcmd.c
diff -Naur mc-4.6.1-orig/edit/editcmd.c mc-4.6.1/edit/editcmd.c
old new 41 41 #include "../src/dialog.h" /* do_refresh() */ 42 42 #include "../src/wtools.h" /* message() */ 43 43 #include "../src/charsets.h" 44 #ifdef HAVE_XCLIP 45 #include "../src/xclipb.h" 46 #endif /* HAVE_XCLIP */ 44 47 45 48 #define edit_get_load_file(f,h) input_expand_dialog (h, _(" Enter file name: "), f) 46 49 #define edit_get_save_file(f,h) input_expand_dialog (h, _(" Enter file name: "), f) … … 252 255 if (!savename) 253 256 return 0; 254 257 /* FIXME: 255 * Close for now because mc_mkstemps use pure open system call 258 * Close for now because mc_mkstemps use pure open system call 256 259 * to create temporary file and it needs to be reopened by 257 260 * VFS-aware mc_open(). 258 261 */ … … 404 407 /* OK/Cancel buttons */ 405 408 l1 = strlen (_(widgets[0].text)) + strlen (_(widgets[1].text)) + 5; 406 409 maxlen = max (maxlen, l1); 407 410 408 411 for (i = 0; i < 3; i++ ) { 409 412 str[i] = _(str[i]); 410 413 maxlen = max (maxlen, strlen (str[i]) + 7); … … 494 497 if (!edit->locked && !edit->delete_file) 495 498 save_lock = edit_lock_file (exp); 496 499 } 497 500 498 501 if (edit_save_file (edit, exp)) { 499 502 /* Succesful, so unlock both files */ 500 503 if (strcmp (edit->filename, exp)) { … … 506 509 if (edit->locked || save_lock) 507 510 edit->locked = edit_unlock_file (edit->filename); 508 511 } 509 512 510 513 edit_set_filename (edit, exp); 511 514 g_free (exp); 512 515 edit->modified = 0; … … 550 553 } 551 554 552 555 /* gets a raw key from the keyboard. Passing cancel = 1 draws 553 a cancel button thus allowing c-c etc. Alternatively, cancel = 0 556 a cancel button thus allowing c-c etc. Alternatively, cancel = 0 554 557 will return the next key pressed. ctrl-a (=B_CANCEL), ctrl-g, ctrl-c, 555 558 and Esc are cannot returned */ 556 559 int … … 778 781 edit_save_cmd (WEdit *edit) 779 782 { 780 783 int res, save_lock = 0; 781 784 782 785 if (!edit->locked && !edit->delete_file) 783 786 save_lock = edit_lock_file (edit->filename); 784 787 res = edit_save_file (edit, edit->filename); 785 788 786 789 /* Maintain modify (not save) lock on failure */ 787 790 if ((res && edit->locked) || save_lock) 788 791 edit->locked = edit_unlock_file (edit->filename); 789 792 790 793 /* On failure try 'save as', it does locking on its own */ 791 if (!res) 794 if (!res) 792 795 return edit_save_as_cmd (edit); 793 796 edit->force |= REDRAW_COMPLETELY; 794 797 edit->delete_file = 0; … … 820 823 { 821 824 int prev_locked = edit->locked; 822 825 char *prev_filename = g_strdup (edit->filename); 823 826 824 827 if (!edit_reload (edit, exp)) { 825 828 g_free (prev_filename); 826 829 return 1; … … 1488 1491 } 1489 1492 } else { /* regexp matching */ 1490 1493 long offset = 0; 1491 int found_start, match_bol, move_win = 0; 1494 int found_start, match_bol, move_win = 0; 1492 1495 1493 1496 while (start + offset < last_byte) { 1494 1497 match_bol = (offset == 0 || (*get_byte) (data, start + offset - 1) == '\n'); … … 2211 2214 return edit_save_block (edit, catstrs (home_dir, CLIP_FILE, (char *) NULL), start, finish); 2212 2215 } 2213 2216 2217 #ifdef HAVE_XCLIP 2218 #ifdef OTHER_VARIANT 2219 static int edit_save_block_to_X_buf (WEdit * edit, long start, long finish) 2220 { 2221 unsigned char *buff; //for first time 2222 int len, retval; 2223 2224 if ( (finish - start) > 4096) 2225 return 0; 2226 //if ( start >= finish ) { 2227 /* for ( ; i < finish ; i++ ) { 2228 buff[i - start] = edit_get_byte (edit, i); 2229 }*/ 2230 buff = edit_get_block (edit, start, finish, &len); 2231 //} 2232 retval = set_xclipb(buff, 0); 2233 g_free(buff); 2234 return retval; 2235 } 2236 #endif /* OTHER_VARIANT */ 2237 #endif /* HAVE_XCLIP */ 2214 2238 2215 2239 void edit_paste_from_history (WEdit *edit) 2216 2240 { … … 2221 2245 long start_mark, end_mark; 2222 2246 if (eval_marks (edit, &start_mark, &end_mark)) 2223 2247 return 0; 2248 #ifdef HAVE_XCLIP 2249 #ifdef OTHER_VARIANT 2250 if (!edit_save_block_to_X_buf (edit, start_mark, end_mark)) { 2251 edit_error_dialog (_(" Copy to clipboard "), _(" Unable to save to X clipboard. ")); 2252 return 1; 2253 } 2254 #else /* !OTHER_VARIANT */ 2224 2255 if (!edit_save_block_to_clip_file (edit, start_mark, end_mark)) { 2225 2256 edit_error_dialog (_(" Copy to clipboard "), get_sys_error (_(" Unable to save to file. "))); 2226 2257 return 1; 2227 2258 } 2259 set_xclipb(NULL, 1); 2260 #endif /* !OTHER_VARIANT */ 2261 #else /* !HAVE_XCLIP */ 2262 if (!edit_save_block_to_clip_file (edit, start_mark, end_mark)) { 2263 edit_error_dialog (_(" Copy to clipboard "), get_sys_error (_(" Unable to save to file. "))); 2264 return 1; 2265 } 2266 #endif /* !HAVE_XCLIP */ 2228 2267 edit_mark_cmd (edit, 1); 2229 2268 return 0; 2230 2269 } … … 2234 2273 long start_mark, end_mark; 2235 2274 if (eval_marks (edit, &start_mark, &end_mark)) 2236 2275 return 0; 2276 #ifdef HAVE_XCLIP 2277 #ifdef OTHER_VARIANT 2278 if (!edit_save_block_to_X_buf (edit, start_mark, end_mark)) { 2279 edit_error_dialog (_(" Copy to clipboard "), _(" Unable to save to X clipboard. ")); 2280 return 1; 2281 } 2282 #else /* !OTHER_VARIANT */ 2237 2283 if (!edit_save_block_to_clip_file (edit, start_mark, end_mark)) { 2238 2284 edit_error_dialog (_(" Cut to clipboard "), _(" Unable to save to file. ")); 2239 2285 return 1; 2240 2286 } 2287 set_xclipb(NULL, 1); 2288 #endif /* !OTHER_VARIANT */ 2289 #else /* !HAVE_XCLIP */ 2290 if (!edit_save_block_to_clip_file (edit, start_mark, end_mark)) { 2291 edit_error_dialog (_(" Cut to clipboard "), _(" Unable to save to file. ")); 2292 return 1; 2293 } 2294 #endif /* !HAVE_XCLIP */ 2241 2295 edit_block_delete_cmd (edit); 2242 2296 edit_mark_cmd (edit, 1); 2243 2297 return 0; … … 2245 2299 2246 2300 void edit_paste_from_X_buf_cmd (WEdit * edit) 2247 2301 { 2302 #ifdef HAVE_XCLIP 2303 #ifdef OTHER_VARIANT 2304 int i = 0, len; 2305 long current = edit->curs1; 2306 unsigned char *buff = get_xclipb(0); 2307 2308 len = strlen(buff); 2309 for ( ; i < len ; i++ ) { 2310 edit_insert (edit, buff[i]); 2311 } 2312 edit_cursor_move (edit, current - edit->curs1); 2313 g_free(buff); 2314 #else /* !OTHER_VARIANT */ 2315 get_xclipb(1); 2316 edit_insert_file (edit, catstrs (home_dir, CLIP_FILE, (char *) NULL)); 2317 #endif /* !OTHER_VARIANT */ 2318 #else /* !HAVE_XCLIP */ 2248 2319 edit_insert_file (edit, catstrs (home_dir, CLIP_FILE, (char *) NULL)); 2320 #endif /* !HAVE_XCLIP */ 2249 2321 } 2250 2322 2251 2323 … … 2366 2438 2367 2439 exp = old ? old : ""; 2368 2440 2369 exp = input_dialog (_(" Run Sort "), 2441 exp = input_dialog (_(" Run Sort "), 2370 2442 _(" Enter sort options (see manpage) separated by whitespace: "), exp); 2371 2443 2372 2444 if (!exp) … … 2377 2449 e = system (catstrs (" sort ", exp, " ", home_dir, BLOCK_FILE, " > ", home_dir, TEMP_FILE, (char *) NULL)); 2378 2450 if (e) { 2379 2451 if (e == -1 || e == 127) { 2380 edit_error_dialog (_(" Sort "), 2452 edit_error_dialog (_(" Sort "), 2381 2453 get_sys_error (_(" Cannot execute sort command "))); 2382 2454 } else { 2383 2455 char q[8]; 2384 2456 sprintf (q, "%d ", e); 2385 edit_error_dialog (_(" Sort "), 2457 edit_error_dialog (_(" Sort "), 2386 2458 catstrs (_(" Sort returned non-zero: "), q, (char *) NULL)); 2387 2459 } 2388 2460 return -1; … … 2636 2708 static int edit_find_word_start (WEdit *edit, long *word_start, int *word_len) 2637 2709 { 2638 2710 int i, c, last; 2639 2711 2640 2712 /* return if at begin of file */ 2641 2713 if (edit->curs1 <= 0) 2642 2714 return 0; … … 2644 2716 c = (unsigned char) edit_get_byte (edit, edit->curs1 - 1); 2645 2717 /* return if not at end or in word */ 2646 2718 if (isspace (c) || !(isalnum (c) || c == '_')) 2647 return 0; 2719 return 0; 2648 2720 2649 2721 /* search start of word to be completed */ 2650 2722 for (i = 2;; i++) { 2651 2723 /* return if at begin of file */ 2652 if (edit->curs1 - i < 0) 2724 if (edit->curs1 - i < 0) 2653 2725 return 0; 2654 2726 2655 2727 last = c; 2656 2728 c = (unsigned char) edit_get_byte (edit, edit->curs1 - i); 2657 2729 -
src/main.c
diff -Naur mc-4.6.1-orig/src/main.c mc-4.6.1/src/main.c
old new 1 1 /* Main program for the Midnight Commander 2 2 Copyright (C) 1994, 1995, 1996, 1997 The Free Software Foundation 3 3 4 4 Written by: 1994, 1995, 1996, 1997 Miguel de Icaza 5 5 1994, 1995 Janne Kukonlehto 6 6 1997 Norbert Warmuth 7 7 8 8 This program is free software; you can redistribute it and/or modify 9 9 it under the terms of the GNU General Public License as published by 10 10 the Free Software Foundation; either version 2 of the License, or 11 11 (at your option) any later version. 12 12 13 13 This program is distributed in the hope that it will be useful, 14 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the … … 92 92 #include "../vfs/gc.h" 93 93 #endif 94 94 95 #ifdef HAVE_XCLIP 96 #include "xclipb.h" 97 #endif /* HAVE_XCLIP */ 98 95 99 #include "popt.h" 96 100 97 101 /* When the modes are active, left_panel, right_panel and tree_panel */ … … 134 138 /* If true, at startup the user-menu is invoked */ 135 139 int auto_menu = 0; 136 140 137 /* If true, use + and \ keys normally and select/unselect do if M-+ / M-\ 141 /* If true, use + and \ keys normally and select/unselect do if M-+ / M-\ 138 142 and M-- and keypad + / - */ 139 143 int alternate_plus_minus = 0; 140 144 … … 174 178 /* If true use +, -, | for line drawing */ 175 179 int force_ugly_line_drawing = 0; 176 180 177 /* If true program softkeys (HP terminals only) on startup and after every 178 command ran in the subshell to the description found in the termcap/terminfo 181 /* If true program softkeys (HP terminals only) on startup and after every 182 command ran in the subshell to the description found in the termcap/terminfo 179 183 database */ 180 184 int reset_hp_softkeys = 0; 181 185 … … 710 714 winput_set_origin ((WInput *) cmdline, prompt_len, 711 715 COLS - prompt_len); 712 716 713 /* since the prompt has changed, and we are called from one of the 717 /* since the prompt has changed, and we are called from one of the 714 718 * get_event channels, the prompt updating does not take place 715 719 * automatically: force a cursor update and a screen refresh 716 720 */ … … 1526 1530 return MSG_HANDLED; 1527 1531 } 1528 1532 } else if (!command_prompt || !cmdline->buffer[0]) { 1529 /* Special treatement '+', '-', '\', '*' only when this is 1533 /* Special treatement '+', '-', '\', '*' only when this is 1530 1534 * first char on input line 1531 1535 */ 1532 1536 … … 2212 2216 /* Removing this from the X code let's us type C-c */ 2213 2217 load_key_defs (); 2214 2218 2219 #ifdef HAVE_XCLIP 2220 init_xclipb(); 2221 #endif 2215 2222 /* Also done after init_subshell, to save any shell init file messages */ 2216 2223 if (console_flag) 2217 2224 handle_console (CONSOLE_SAVE); -
src/Makefile.am
diff -Naur mc-4.6.1-orig/src/Makefile.am mc-4.6.1/src/Makefile.am
old new 60 60 tree.c tree.h treestore.c treestore.h tty.h user.c user.h \ 61 61 util.c util.h utilunix.c view.c view.h vfsdummy.h widget.c \ 62 62 widget.h win.c win.h wtools.c wtools.h \ 63 x11conn.h x11conn.c 63 x11conn.h x11conn.c xclip.h xclip.c 64 64 65 65 if CHARSET 66 66 mc_SOURCES = $(SRCS) $(CHARSET_SRC) -
src/xclipb.c
diff -Naur mc-4.6.1-orig/src/xclipb.c mc-4.6.1/src/xclipb.c
old new 1 /* X11 clipboard module for the Midnight Commander 2 Copyright (C) 2005 Likhota Vadim <vadim-lvv[at]yandex.ru> 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 */ 18 19 /* Based on gtk/gdk and qt source. 20 21 At all can use only "xclip" or analog, but it don't work with KDE 22 You will can find xclip on http://people.debian.org/~kims/xclip/ 23 and qtclipb on http://www.klv.lg.ua/~vadim/ 24 25 For optimization man write me, but use GTK or QT not propose. 26 Ideal - only external program or only internal realization. 27 28 29 */ 30 31 #include <config.h> 32 33 #ifdef HAVE_XCLIP 34 35 #ifdef HAVE_TEXTMODE_X11_SUPPORT 36 #define WITH_X 1 37 #endif 38 39 #include <stdio.h> 40 #include <errno.h> 41 #include "global.h" 42 43 #ifdef WITH_X 44 45 #include <X11/Xlib.h> 46 #include <X11/Xatom.h> 47 #include <X11/Xmu/Atoms.h> 48 49 #endif /* WITH_X */ 50 51 #include "execute.h" 52 #include "wtools.h" 53 #include "xclipb.h" 54 55 #define XCLIP_BUFF 1024 56 57 58 #ifdef WITH_X 59 60 /* #define WAIT_1 */ 61 62 /* from key.c 63 extern Display *x11_display; 64 extern Window x11_window; */ 65 66 static Display *x11_display; 67 static Window x11_window, w, retw; 68 static Atom utf8str, clipboard, incr, multiple, compound, timestamp, gdk_timestamp_prop, targets, gdk_property, qt_property, 69 atom_pair, save_targets, text, plain_text_utf8, plain_text_curr, plain_text_iso, plain_text; 70 static guint32 mc_time; 71 72 static char *xclip_cach = NULL; 73 74 #endif /* WITH_X */ 75 76 static char mc_cl_file [256]; 77 //static FILE *fl = NULL; 78 static int en_xcl = 0; /* 1 -> enable xclipboard , -1 -> found kde */ 79 80 81 void 82 init_xclipb (void) 83 { 84 char *disp = getenv("DISPLAY"); 85 char *dsess = getenv("DESKTOP_SESSION"); 86 87 if (!disp || strlen(disp) == 0) { 88 en_xcl = 0; 89 return; 90 } 91 else { 92 en_xcl = 1; 93 } 94 sprintf(mc_cl_file, "%s/.mc/%s", home_dir, XCLIPB_FILE); 95 #ifndef WITH_X 96 if ( dsess && !strcmp(dsess, "kde") ) { 97 en_xcl = -1; 98 } 99 #else /* WITH_X */ 100 // if ( dsess && !strcmp(dsess, "kde") ) { 101 Atom type; 102 int format; 103 unsigned long nbytes, nitems; 104 unsigned char *data = NULL; 105 106 x11_display = XOpenDisplay(NULL); 107 108 if (!x11_display) { 109 en_xcl = 0; 110 return; 111 } 112 113 mc_time = CurrentTime; 114 115 utf8str = XInternAtom(x11_display, "UTF8_STRING", False); 116 clipboard = XInternAtom(x11_display, "CLIPBOARD", False); 117 incr = XInternAtom(x11_display, "INCR", False); 118 multiple = XInternAtom(x11_display, "MULTIPLE", False); 119 compound = XInternAtom(x11_display, "COMPOUND_TEXT", False); 120 timestamp = XInternAtom(x11_display, "TIMESTAMP", False); 121 gdk_timestamp_prop = XInternAtom(x11_display, "GDK_TIMESTAMP_PROP", False); 122 targets = XInternAtom(x11_display, "TARGETS", False); 123 save_targets = XInternAtom(x11_display, "SAVE_TARGETS", False); 124 text = XInternAtom(x11_display, "TEXT", False); 125 plain_text_utf8 = XInternAtom(x11_display, "text/plain;charset=UTF-8", False); 126 plain_text_curr = XInternAtom(x11_display, "text/plain;charset=CP1251", False); 127 plain_text_iso = XInternAtom(x11_display, "text/plain;charset=ISO-8859-1", False); 128 plain_text = XInternAtom(x11_display, "text/plain", False); 129 gdk_property = XInternAtom(x11_display, "GDK_SELECTION", False); 130 qt_property = XInternAtom(x11_display, "_QT_SELECTION", False); 131 atom_pair = XInternAtom(x11_display, "ATOM_PAIR", False); 132 133 x11_window = DefaultRootWindow(x11_display); 134 w = XCreateSimpleWindow(x11_display, x11_window, 0, 0, 2, 2, 0, 0, 0); 135 XSelectInput(x11_display, w, PropertyChangeMask); 136 XFlush(x11_display); 137 retw = XGetSelectionOwner (x11_display, clipboard); 138 XConvertSelection (x11_display, clipboard, utf8str, None, retw, mc_time); 139 XFlush (x11_display); 140 XGetWindowProperty(x11_display, retw, utf8str, 0, 0x1FFFFFFF, False, AnyPropertyType, &type, &format, &nitems, &nbytes, &data); 141 if (data) 142 XFree(data); 143 144 /* TO DO: don't open/close display allways and check (retw = XGetSelectionOwner) with mc's window before insert to clipboard */ 145 XCloseDisplay(x11_display); 146 147 // } 148 #endif /* WITH_X */ 149 150 } 151 152 /* #ifdef WAIT_1 153 154 static Bool 155 wait_for_event (int type, XEvent *event, int timeout) // qt_xclb_wait_for_event 156 { 157 time_t started = time(NULL); 158 time_t now = started; 159 160 int flushed = False; 161 //int nn = 0; 162 do { 163 164 if ( XCheckTypedWindowEvent(x11_display, x11_window, type, event) ) 165 return True; 166 167 now = time(NULL); 168 169 if(!flushed) { 170 XFlush( x11_display ); 171 flushed = True; 172 } 173 174 // sleep 50ms, so we don't use up CPU cycles all the time. 175 struct timeval usleep_tv; 176 usleep_tv.tv_sec = 0; 177 usleep_tv.tv_usec = 50000; 178 select(0, 0, 0, 0, &usleep_tv); 179 //nn++; 180 } while ( (now - started) < timeout ); 181 182 return False; 183 } 184 185 #endif */ 186 187 188 char * 189 get_xclipb (const int use_cl_file) 190 { 191 char *get_str; 192 if ( !en_xcl ) 193 return NULL; 194 195 #ifdef WITH_X 196 Atom type; 197 int format, len = 0, ii = 0; 198 unsigned long nbytes, nitems; 199 unsigned char *data = NULL; 200 201 202 x11_display = XOpenDisplay(NULL); 203 if (!x11_display) 204 return 0; 205 206 for ( ; ii < 64 ; ii++) { 207 retw = XGetSelectionOwner (x11_display, clipboard); 208 fprintf (fl, "%i, Selection owner %li, old window = %li\n", ii, retw, w); 209 /* if ( retw == w) { 210 get_str = g_strdup(xclip_cach); 211 return get_str; 212 } */ 213 if ( retw != 0) { 214 XConvertSelection (x11_display, clipboard, utf8str, None, retw, mc_time); 215 XFlush (x11_display); 216 XGetWindowProperty (x11_display, retw, utf8str, 0, 0, 0, AnyPropertyType, &type, &format, &nitems, &nbytes, &data); 217 if ( nbytes > 0 ) { 218 if (data) 219 XFree(data); 220 break; 221 } 222 } 223 } 224 225 if ( nbytes > 0 ) 226 if ( XGetWindowProperty(x11_display, retw, utf8str, 0, 0x1FFFFFFF, False, AnyPropertyType, &type, &format, &nitems, &nbytes, &data) != Success) 227 return NULL; 228 else { 229 230 if (type == XA_ATOM || type == atom_pair) { 231 return NULL; 232 } 233 else if (type == incr) { 234 return NULL; 235 } 236 else if (type == compound) { 237 /* TO DO */ 238 return NULL; 239 } 240 else { 241 /* Now I not have AMD64 for test with 64bit OS */ 242 if (data) { 243 switch (format) { 244 case 8: 245 len = nitems; 246 break; 247 case 16: 248 len = sizeof(short) * nitems; 249 break; 250 case 32: 251 len = sizeof(long) * nitems; 252 break; 253 } 254 get_str = g_strdup(data); 255 } 256 } 257 } 258 259 if (data) 260 XFree(data); 261 262 XFlush(x11_display); 263 XCloseDisplay(x11_display); 264 #else /* !WITH_X */ 265 char cmd[256], buf[1024]; 266 FILE *f; 267 268 if ( use_cl_file ) { 269 if ( en_xcl > 0 ) 270 sprintf(cmd, "xclip -sel cl -o > %s/.mc/cedit/%s", home_dir, "cooledit.clip"); // need use CLIP_FILE from edit/edit.h 271 else 272 sprintf(cmd, "qtclipb > %s/.mc/cedit/%s", home_dir, "cooledit.clip"); 273 } 274 else { 275 if ( en_xcl > 0 ) 276 sprintf(cmd, "xclip -sel cl -o > %s", mc_cl_file); 277 else 278 sprintf(cmd, "qtclipb > %s", mc_cl_file); 279 } 280 shell_execute(cmd, 0); 281 if ( !use_cl_file ) { 282 f = fopen(mc_cl_file, "r"); 283 if ( f == NULL ) { 284 message (1, MSG_ERROR, _(" Cannot open clipboard file \n %s "), unix_error_string (errno)); 285 return NULL; 286 } 287 if /*while*/ ( fgets(buf, 1023, f) ) 288 get_str = g_strdup(buf); 289 fclose(f); 290 } 291 #endif /* WITH_X */ 292 return get_str; 293 }; 294 295 296 #ifdef WITH_X 297 static int 298 sizeof_format(int format) 299 { 300 int sz; 301 switch (format) { 302 default: 303 case 8: sz = sizeof( char); break; 304 case 16: sz = sizeof(short); break; 305 case 32: sz = sizeof( long); break; 306 } 307 return sz; 308 } 309 #endif 310 311 /* return 1 if OK */ 312 int 313 set_xclipb (const char *clip_str, const int use_cl_file) 314 { 315 if ( !en_xcl ) 316 return 0; 317 #ifdef WITH_X 318 unsigned long len = strlen(clip_str); 319 Atom type, property; 320 XSelectionRequestEvent *req; 321 XEvent e, respond;; 322 int ii = 0, retval, format, result; 323 Atom xatoms[11]; 324 325 x11_display = XOpenDisplay(NULL); 326 if (!x11_display) 327 return 0; 328 w = XCreateSimpleWindow(x11_display, DefaultRootWindow(x11_display), 0, 0, 2, 2, 0, 0, 0); 329 XSelectInput(x11_display, w, PropertyChangeMask); 330 XFlush(x11_display); 331 332 for ( ; ii < 64; ii++) { 333 retval = XSetSelectionOwner (x11_display, clipboard, w, mc_time); 334 XFlush (x11_display); 335 XNextEvent (x11_display, &e); 336 if (e.type == SelectionRequest && (req->property == qt_property || req->property == None) ) { 337 property = req->property; 338 req=&(e.xselectionrequest); 339 if (req->target == None || property == None) { 340 ; 341 } 342 else if (req->target == targets) { 343 Atom xatoms[11]; 344 345 xatoms[0] = timestamp; 346 xatoms[1] = targets; 347 xatoms[2] = multiple; 348 xatoms[3] = save_targets; 349 xatoms[4] = utf8str; 350 xatoms[5] = XA_STRING; 351 xatoms[6] = text; 352 xatoms[7] = plain_text; 353 xatoms[8] = plain_text_utf8; 354 xatoms[9] = plain_text_curr; 355 xatoms[10] = compound; 356 357 retval = XChangeProperty(x11_display, req->requestor, property, XA_ATOM, 32, PropModeReplace, (unsigned char *) xatoms, 11); 358 } 359 else if (req->target == text || req->target == compound) { 360 XTextProperty textprop; 361 char *list[] = { clip_str, NULL }; 362 XICCEncodingStyle style = (req->target == compound) ? XCompoundTextStyle : XStdICCTextStyle; 363 364 if ( list[0] != NULL && XmbTextListToTextProperty(x11_display, list, 1, style, &textprop) == Success ) { 365 char ssss[strlen(textprop.value)+1]; 366 367 strcpy(ssss, textprop.value); 368 if (textprop.value) 369 XFree(textprop.value); 370 XChangeProperty(x11_display, req->requestor, property, textprop.encoding, textprop.format, PropModeReplace, 371 (unsigned char *) ssss, strlen(ssss) / sizeof_format(textprop.format)); 372 } 373 else 374 property = None; 375 //ii = 64; 376 } 377 else if (req->target == XA_STRING || req->target == utf8str) { 378 XChangeProperty(x11_display, req->requestor, property, req->target, 8, PropModeReplace, (unsigned char *) clip_str, len); 379 ii = 64; 380 } 381 else { 382 property = None; 383 } 384 respond.xselection.type = SelectionNotify; 385 respond.xselection.display = req->display; 386 respond.xselection.requestor = req->requestor; 387 respond.xselection.selection = req->selection; 388 respond.xselection.target = req->target; 389 respond.xselection.property = property; 390 respond.xselection.time = req->time; 391 392 XSendEvent (x11_display, req->requestor, 0, NoEventMask, &respond); 393 XFlush (x11_display); 394 } 395 } 396 XFlush (x11_display); 397 XCloseDisplay(x11_display); 398 if ( xclip_cach ) 399 g_free(xclip_cach); 400 xclip_cach = g_strdup(clip_str); 401 402 #else /* ! WITH_X */ 403 char cmd[256]; 404 405 if ( !use_cl_file ) { 406 FILE *xclip_file = fopen(mc_cl_file, "w"); /* to do: use mc_open */ 407 408 if ( xclip_file == NULL ) { 409 message (1, MSG_ERROR, _(" Cannot open clipboard file \n %s "), unix_error_string (errno)); 410 return 0; 411 } 412 fprintf(xclip_file, "%s", clip_str); 413 fclose(xclip_file); 414 if ( en_xcl > 0 ) 415 sprintf(cmd, "xclip -sel cl %s", mc_cl_file); 416 else 417 sprintf(cmd, "qtclipb -i %s", mc_cl_file); 418 } 419 else { 420 if ( en_xcl > 0 ) 421 sprintf(cmd, "xclip -sel cl %s/.mc/cedit/%s", home_dir, "cooledit.clip"); // need use CLIP_FILE from edit/edit.h 422 else 423 sprintf(cmd, "qtclipb -i %s/.mc/cedit/%s", home_dir, "cooledit.clip"); 424 } 425 shell_execute(cmd, 0); 426 427 #endif /* WITH_X */ 428 return 1; 429 }; 430 431 432 #endif /* HAVE_XCLIP */ 433 434 -
src/xclipb.h
diff -Naur mc-4.6.1-orig/src/xclipb.h mc-4.6.1/src/xclipb.h
old new 1 #ifndef __MC_XCLIPB_H 2 #define __MC_XCLIPB_H 3 4 #ifdef HAVE_XCLIP 5 6 // void init_xclipb (const char *home_dir); 7 void init_xclipb (void); 8 char *get_xclipb (const int use_cl_file); 9 int set_xclipb (const char *text, const int use_cl_file); 10 11 #define XCLIPB_FILE "xclip.txt" 12 13 #endif /* HAVE_XCLIP */ 14 15 #endif /* __MC_CLIPB_H */