Karsten Hopp 61369e
To: vim-dev@vim.org
Karsten Hopp 61369e
Subject: Patch 7.3.011
Karsten Hopp 61369e
Fcc: outbox
Karsten Hopp 61369e
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 61369e
Mime-Version: 1.0
Karsten Hopp 61369e
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 61369e
Content-Transfer-Encoding: 8bit
Karsten Hopp 61369e
------------
Karsten Hopp 61369e
Karsten Hopp 61369e
Patch 7.3.011
Karsten Hopp 61369e
Problem:    X11 clipboard doesn't work in Athena/Motif GUI.  First selection
Karsten Hopp 61369e
	    after a shell command doesn't work.
Karsten Hopp 61369e
Solution:   When using the GUI use XtLastTimestampProcessed() instead of
Karsten Hopp 61369e
	    changing a property.  (partly by Toni Ronkko)
Karsten Hopp 61369e
	    When executing a shell command disown the selection.
Karsten Hopp 61369e
Files:	    src/ui.c, src/os_unix.c
Karsten Hopp 61369e
Karsten Hopp 61369e
Karsten Hopp 61369e
*** ../vim-7.3.010/src/ui.c	2010-08-15 21:57:31.000000000 +0200
Karsten Hopp 61369e
--- src/ui.c	2010-09-21 22:08:22.000000000 +0200
Karsten Hopp 61369e
***************
Karsten Hopp 61369e
*** 469,475 ****
Karsten Hopp 61369e
       */
Karsten Hopp 61369e
  #ifdef FEAT_X11
Karsten Hopp 61369e
      /* Always own the selection, we might have lost it without being
Karsten Hopp 61369e
!      * notified. */
Karsten Hopp 61369e
      if (cbd->available)
Karsten Hopp 61369e
      {
Karsten Hopp 61369e
  	int was_owned = cbd->owned;
Karsten Hopp 61369e
--- 469,475 ----
Karsten Hopp 61369e
       */
Karsten Hopp 61369e
  #ifdef FEAT_X11
Karsten Hopp 61369e
      /* Always own the selection, we might have lost it without being
Karsten Hopp 61369e
!      * notified, e.g. during a ":sh" command. */
Karsten Hopp 61369e
      if (cbd->available)
Karsten Hopp 61369e
      {
Karsten Hopp 61369e
  	int was_owned = cbd->owned;
Karsten Hopp 61369e
***************
Karsten Hopp 61369e
*** 1944,1953 ****
Karsten Hopp 61369e
   */
Karsten Hopp 61369e
  
Karsten Hopp 61369e
  static Boolean	clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *));
Karsten Hopp 61369e
- 
Karsten Hopp 61369e
  static void  clip_x11_lose_ownership_cb __ARGS((Widget, Atom *));
Karsten Hopp 61369e
- 
Karsten Hopp 61369e
  static void clip_x11_timestamp_cb __ARGS((Widget w, XtPointer n, XEvent *event, Boolean *cont));
Karsten Hopp 61369e
  
Karsten Hopp 61369e
  /*
Karsten Hopp 61369e
   * Property callback to get a timestamp for XtOwnSelection.
Karsten Hopp 61369e
--- 1944,1952 ----
Karsten Hopp 61369e
   */
Karsten Hopp 61369e
  
Karsten Hopp 61369e
  static Boolean	clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *));
Karsten Hopp 61369e
  static void  clip_x11_lose_ownership_cb __ARGS((Widget, Atom *));
Karsten Hopp 61369e
  static void clip_x11_timestamp_cb __ARGS((Widget w, XtPointer n, XEvent *event, Boolean *cont));
Karsten Hopp 61369e
+ static void  clip_x11_request_selection_cb __ARGS((Widget, XtPointer, Atom *, Atom *, XtPointer, long_u *, int *));
Karsten Hopp 61369e
  
Karsten Hopp 61369e
  /*
Karsten Hopp 61369e
   * Property callback to get a timestamp for XtOwnSelection.
Karsten Hopp 61369e
***************
Karsten Hopp 61369e
*** 1985,1992 ****
Karsten Hopp 61369e
  	return;
Karsten Hopp 61369e
  
Karsten Hopp 61369e
      /* Get the selection, using the event timestamp. */
Karsten Hopp 61369e
!     XtOwnSelection(w, xproperty->atom, xproperty->time,
Karsten Hopp 61369e
! 	    clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, NULL);
Karsten Hopp 61369e
  }
Karsten Hopp 61369e
  
Karsten Hopp 61369e
      void
Karsten Hopp 61369e
--- 1984,2000 ----
Karsten Hopp 61369e
  	return;
Karsten Hopp 61369e
  
Karsten Hopp 61369e
      /* Get the selection, using the event timestamp. */
Karsten Hopp 61369e
!     if (XtOwnSelection(w, xproperty->atom, xproperty->time,
Karsten Hopp 61369e
! 	    clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb,
Karsten Hopp 61369e
! 	    NULL) == OK)
Karsten Hopp 61369e
!     {
Karsten Hopp 61369e
! 	/* Set the "owned" flag now, there may have been a call to
Karsten Hopp 61369e
! 	 * lose_ownership_cb in between. */
Karsten Hopp 61369e
! 	if (xproperty->atom == clip_plus.sel_atom)
Karsten Hopp 61369e
! 	    clip_plus.owned = TRUE;
Karsten Hopp 61369e
! 	else
Karsten Hopp 61369e
! 	    clip_star.owned = TRUE;
Karsten Hopp 61369e
!     }
Karsten Hopp 61369e
  }
Karsten Hopp 61369e
  
Karsten Hopp 61369e
      void
Karsten Hopp 61369e
***************
Karsten Hopp 61369e
*** 1997,2004 ****
Karsten Hopp 61369e
  	    /*(XtEventHandler)*/clip_x11_timestamp_cb, (XtPointer)NULL);
Karsten Hopp 61369e
  }
Karsten Hopp 61369e
  
Karsten Hopp 61369e
- static void  clip_x11_request_selection_cb __ARGS((Widget, XtPointer, Atom *, Atom *, XtPointer, long_u *, int *));
Karsten Hopp 61369e
- 
Karsten Hopp 61369e
      static void
Karsten Hopp 61369e
  clip_x11_request_selection_cb(w, success, sel_atom, type, value, length,
Karsten Hopp 61369e
  			      format)
Karsten Hopp 61369e
--- 2005,2010 ----
Karsten Hopp 61369e
***************
Karsten Hopp 61369e
*** 2336,2342 ****
Karsten Hopp 61369e
  
Karsten Hopp 61369e
      void
Karsten Hopp 61369e
  clip_x11_lose_selection(myShell, cbd)
Karsten Hopp 61369e
!     Widget	myShell;
Karsten Hopp 61369e
      VimClipboard	*cbd;
Karsten Hopp 61369e
  {
Karsten Hopp 61369e
      XtDisownSelection(myShell, cbd->sel_atom, CurrentTime);
Karsten Hopp 61369e
--- 2342,2348 ----
Karsten Hopp 61369e
  
Karsten Hopp 61369e
      void
Karsten Hopp 61369e
  clip_x11_lose_selection(myShell, cbd)
Karsten Hopp 61369e
!     Widget		myShell;
Karsten Hopp 61369e
      VimClipboard	*cbd;
Karsten Hopp 61369e
  {
Karsten Hopp 61369e
      XtDisownSelection(myShell, cbd->sel_atom, CurrentTime);
Karsten Hopp 61369e
***************
Karsten Hopp 61369e
*** 2344,2357 ****
Karsten Hopp 61369e
  
Karsten Hopp 61369e
      int
Karsten Hopp 61369e
  clip_x11_own_selection(myShell, cbd)
Karsten Hopp 61369e
!     Widget	myShell;
Karsten Hopp 61369e
      VimClipboard	*cbd;
Karsten Hopp 61369e
  {
Karsten Hopp 61369e
!     /* Get the time by a zero-length append, clip_x11_timestamp_cb will be
Karsten Hopp 61369e
!      * called with the current timestamp.  */
Karsten Hopp 61369e
!     if (!XChangeProperty(XtDisplay(myShell), XtWindow(myShell), cbd->sel_atom,
Karsten Hopp 61369e
! 	    timestamp_atom, 32, PropModeAppend, NULL, 0))
Karsten Hopp 61369e
  	return FAIL;
Karsten Hopp 61369e
      /* Flush is required in a terminal as nothing else is doing it. */
Karsten Hopp 61369e
      XFlush(XtDisplay(myShell));
Karsten Hopp 61369e
      return OK;
Karsten Hopp 61369e
--- 2350,2378 ----
Karsten Hopp 61369e
  
Karsten Hopp 61369e
      int
Karsten Hopp 61369e
  clip_x11_own_selection(myShell, cbd)
Karsten Hopp 61369e
!     Widget		myShell;
Karsten Hopp 61369e
      VimClipboard	*cbd;
Karsten Hopp 61369e
  {
Karsten Hopp 61369e
!     /* When using the GUI we have proper timestamps, use the one of the last
Karsten Hopp 61369e
!      * event.  When in the console we don't get events (the terminal gets
Karsten Hopp 61369e
!      * them), Get the time by a zero-length append, clip_x11_timestamp_cb will
Karsten Hopp 61369e
!      * be called with the current timestamp.  */
Karsten Hopp 61369e
! #ifdef FEAT_GUI
Karsten Hopp 61369e
!     if (gui.in_use)
Karsten Hopp 61369e
!     {
Karsten Hopp 61369e
! 	if (XtOwnSelection(myShell, cbd->sel_atom,
Karsten Hopp 61369e
! 	       XtLastTimestampProcessed(XtDisplay(myShell)),
Karsten Hopp 61369e
! 	       clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb,
Karsten Hopp 61369e
! 	       NULL) == False)
Karsten Hopp 61369e
  	return FAIL;
Karsten Hopp 61369e
+     }
Karsten Hopp 61369e
+     else
Karsten Hopp 61369e
+ #endif
Karsten Hopp 61369e
+     {
Karsten Hopp 61369e
+ 	if (!XChangeProperty(XtDisplay(myShell), XtWindow(myShell),
Karsten Hopp 61369e
+ 		  cbd->sel_atom, timestamp_atom, 32, PropModeAppend, NULL, 0))
Karsten Hopp 61369e
+ 	return FAIL;
Karsten Hopp 61369e
+     }
Karsten Hopp 61369e
      /* Flush is required in a terminal as nothing else is doing it. */
Karsten Hopp 61369e
      XFlush(XtDisplay(myShell));
Karsten Hopp 61369e
      return OK;
Karsten Hopp 61369e
*** ../vim-7.3.010/src/os_unix.c	2010-08-15 21:57:30.000000000 +0200
Karsten Hopp 61369e
--- src/os_unix.c	2010-09-21 21:59:25.000000000 +0200
Karsten Hopp 61369e
***************
Karsten Hopp 61369e
*** 1123,1128 ****
Karsten Hopp 61369e
--- 1123,1152 ----
Karsten Hopp 61369e
  }
Karsten Hopp 61369e
  #endif
Karsten Hopp 61369e
  
Karsten Hopp 61369e
+ # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
Karsten Hopp 61369e
+ static void loose_clipboard __ARGS((void));
Karsten Hopp 61369e
+ 
Karsten Hopp 61369e
+ /*
Karsten Hopp 61369e
+  * Called when Vim is going to sleep or execute a shell command.
Karsten Hopp 61369e
+  * We can't respond to requests for the X selections.  Lose them, otherwise
Karsten Hopp 61369e
+  * other applications will hang.  But first copy the text to cut buffer 0.
Karsten Hopp 61369e
+  */
Karsten Hopp 61369e
+     static void
Karsten Hopp 61369e
+ loose_clipboard()
Karsten Hopp 61369e
+ {
Karsten Hopp 61369e
+     if (clip_star.owned || clip_plus.owned)
Karsten Hopp 61369e
+     {
Karsten Hopp 61369e
+ 	x11_export_final_selection();
Karsten Hopp 61369e
+ 	if (clip_star.owned)
Karsten Hopp 61369e
+ 	    clip_lose_selection(&clip_star);
Karsten Hopp 61369e
+ 	if (clip_plus.owned)
Karsten Hopp 61369e
+ 	    clip_lose_selection(&clip_plus);
Karsten Hopp 61369e
+ 	if (x11_display != NULL)
Karsten Hopp 61369e
+ 	    XFlush(x11_display);
Karsten Hopp 61369e
+     }
Karsten Hopp 61369e
+ }
Karsten Hopp 61369e
+ #endif
Karsten Hopp 61369e
+ 
Karsten Hopp 61369e
  /*
Karsten Hopp 61369e
   * If the machine has job control, use it to suspend the program,
Karsten Hopp 61369e
   * otherwise fake it by starting a new shell.
Karsten Hopp 61369e
***************
Karsten Hopp 61369e
*** 1137,1155 ****
Karsten Hopp 61369e
      out_flush();	    /* needed to disable mouse on some systems */
Karsten Hopp 61369e
  
Karsten Hopp 61369e
  # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
Karsten Hopp 61369e
!     /* Since we are going to sleep, we can't respond to requests for the X
Karsten Hopp 61369e
!      * selections.  Lose them, otherwise other applications will hang.  But
Karsten Hopp 61369e
!      * first copy the text to cut buffer 0. */
Karsten Hopp 61369e
!     if (clip_star.owned || clip_plus.owned)
Karsten Hopp 61369e
!     {
Karsten Hopp 61369e
! 	x11_export_final_selection();
Karsten Hopp 61369e
! 	if (clip_star.owned)
Karsten Hopp 61369e
! 	    clip_lose_selection(&clip_star);
Karsten Hopp 61369e
! 	if (clip_plus.owned)
Karsten Hopp 61369e
! 	    clip_lose_selection(&clip_plus);
Karsten Hopp 61369e
! 	if (x11_display != NULL)
Karsten Hopp 61369e
! 	    XFlush(x11_display);
Karsten Hopp 61369e
!     }
Karsten Hopp 61369e
  # endif
Karsten Hopp 61369e
  
Karsten Hopp 61369e
  # if defined(_REENTRANT) && defined(SIGCONT)
Karsten Hopp 61369e
--- 1161,1167 ----
Karsten Hopp 61369e
      out_flush();	    /* needed to disable mouse on some systems */
Karsten Hopp 61369e
  
Karsten Hopp 61369e
  # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
Karsten Hopp 61369e
!     loose_clipboard();
Karsten Hopp 61369e
  # endif
Karsten Hopp 61369e
  
Karsten Hopp 61369e
  # if defined(_REENTRANT) && defined(SIGCONT)
Karsten Hopp 61369e
***************
Karsten Hopp 61369e
*** 3706,3711 ****
Karsten Hopp 61369e
--- 3718,3727 ----
Karsten Hopp 61369e
      if (options & SHELL_COOKED)
Karsten Hopp 61369e
  	settmode(TMODE_COOK);	    /* set to normal mode */
Karsten Hopp 61369e
  
Karsten Hopp 61369e
+ # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
Karsten Hopp 61369e
+     loose_clipboard();
Karsten Hopp 61369e
+ # endif
Karsten Hopp 61369e
+ 
Karsten Hopp 61369e
  # ifdef __EMX__
Karsten Hopp 61369e
      if (cmd == NULL)
Karsten Hopp 61369e
  	x = system("");	/* this starts an interactive shell in emx */
Karsten Hopp 61369e
***************
Karsten Hopp 61369e
*** 3814,3826 ****
Karsten Hopp 61369e
  # endif
Karsten Hopp 61369e
      int		did_settmode = FALSE;	/* settmode(TMODE_RAW) called */
Karsten Hopp 61369e
  
Karsten Hopp 61369e
      out_flush();
Karsten Hopp 61369e
      if (options & SHELL_COOKED)
Karsten Hopp 61369e
  	settmode(TMODE_COOK);		/* set to normal mode */
Karsten Hopp 61369e
  
Karsten Hopp 61369e
!     newcmd = vim_strsave(p_sh);
Karsten Hopp 61369e
!     if (newcmd == NULL)		/* out of memory */
Karsten Hopp 61369e
! 	goto error;
Karsten Hopp 61369e
  
Karsten Hopp 61369e
      /*
Karsten Hopp 61369e
       * Do this loop twice:
Karsten Hopp 61369e
--- 3830,3846 ----
Karsten Hopp 61369e
  # endif
Karsten Hopp 61369e
      int		did_settmode = FALSE;	/* settmode(TMODE_RAW) called */
Karsten Hopp 61369e
  
Karsten Hopp 61369e
+     newcmd = vim_strsave(p_sh);
Karsten Hopp 61369e
+     if (newcmd == NULL)		/* out of memory */
Karsten Hopp 61369e
+ 	goto error;
Karsten Hopp 61369e
+ 
Karsten Hopp 61369e
      out_flush();
Karsten Hopp 61369e
      if (options & SHELL_COOKED)
Karsten Hopp 61369e
  	settmode(TMODE_COOK);		/* set to normal mode */
Karsten Hopp 61369e
  
Karsten Hopp 61369e
! # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
Karsten Hopp 61369e
!     loose_clipboard();
Karsten Hopp 61369e
! # endif
Karsten Hopp 61369e
  
Karsten Hopp 61369e
      /*
Karsten Hopp 61369e
       * Do this loop twice:
Karsten Hopp 61369e
*** ../vim-7.3.010/src/version.c	2010-09-21 17:34:26.000000000 +0200
Karsten Hopp 61369e
--- src/version.c	2010-09-21 20:45:02.000000000 +0200
Karsten Hopp 61369e
***************
Karsten Hopp 61369e
*** 716,717 ****
Karsten Hopp 61369e
--- 716,719 ----
Karsten Hopp 61369e
  {   /* Add new patch number below this line */
Karsten Hopp 61369e
+ /**/
Karsten Hopp 61369e
+     11,
Karsten Hopp 61369e
  /**/
Karsten Hopp 61369e
Karsten Hopp 61369e
-- 
Karsten Hopp 61369e
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 61369e
184. You no longer ask prospective dates what their sign is, instead
Karsten Hopp 61369e
     your line is "Hi, what's your URL?"
Karsten Hopp 61369e
Karsten Hopp 61369e
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 61369e
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 61369e
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 61369e
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///