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