* configure.ac: Test for Xfixes

* configure: Regenerate
* config.h.in: Regenerate
* Tools/xpbs.m: If Xfixes is available, use it to receive notifications when the
owner of an X11 selection changes.

In the future we should invalidate the list of cached pasteboard types when this
happens, so, e.g. copying text from gnome-terminal, the general pasteboard will only
have the text type, but subsequently copying text from OpenOffice.org, the general
pasteboard will have plain text and RTF types (currently we don't do this, so
you can't paste RTF contents unless it is in the clipboard when gpbs starts.)

The above problem is also why DND from X to GNUstep doesn't work - the dragging
pasteboard types are never updated.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@33708 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ericwa 2011-08-07 21:38:42 +00:00
parent 66c1fa999a
commit defca0e36e
5 changed files with 138 additions and 0 deletions

View file

@ -1,3 +1,20 @@
2011-08-07 Eric Wasylishen <ewasylishen@gmail.com>
* configure.ac: Test for Xfixes
* configure: Regenerate
* config.h.in: Regenerate
* Tools/xpbs.m: If Xfixes is available, use it to receive notifications when the
owner of an X11 selection changes.
In the future we should invalidate the list of cached pasteboard types when this
happens, so, e.g. copying text from gnome-terminal, the general pasteboard will only
have the text type, but subsequently copying text from OpenOffice.org, the general
pasteboard will have plain text and RTF types (currently we don't do this, so
you can't paste RTF contents unless it is in the clipboard when gpbs starts.)
The above problem is also why DND from X to GNUstep doesn't work - the dragging
pasteboard types are never updated.
2011-08-04 Eric Wasylishen <ewasylishen@gmail.com>
* Tools/xpbs.m: Get copy and paste of rich text from OpenOffice.org

View file

@ -27,6 +27,8 @@
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include <Foundation/Foundation.h>
#include <Foundation/NSUserDefaults.h>
#include <AppKit/NSPasteboard.h>
@ -35,6 +37,9 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <x11/xdnd.h>
#if HAVE_XFIXES
#include <X11/extensions/Xfixes.h>
#endif
/*
* Non-predefined atoms that are used in the X selection mechanism
@ -167,6 +172,9 @@ static Atom atoms[sizeof(atom_names)/sizeof(char*)];
- (void) xSelectionClear;
- (void) xSelectionNotify: (XSelectionEvent*)xEvent;
- (void) xSelectionRequest: (XSelectionRequestEvent*)xEvent;
#if HAVE_XFIXES
+ (void) xFixesSelectionNotify: (XFixesSelectionNotifyEvent*)xEvent;
#endif
- (BOOL) xProvideSelection: (XSelectionRequestEvent*)xEvent;
- (Time) xTimeByAppending;
- (BOOL) xSendData: (unsigned char*) data format: (int) format
@ -193,6 +201,7 @@ static Window xAppWin;
static NSMapTable *ownByX;
static NSMapTable *ownByO;
static NSString *xWaitMode = @"XPasteboardWaitMode";
static int xFixesEventBase;
@implementation XPbOwner
@ -256,6 +265,32 @@ static NSString *xWaitMode = @"XPasteboardWaitMode";
forMode: xWaitMode];
XSelectInput(xDisplay, xAppWin, PropertyChangeMask);
#if HAVE_XFIXES
{
int error;
// Subscribe to notifications of when the X clipboard changes,
// so we can invalidate our cached list of types on it.
//
// FIXME: If we don't have Xfixes, we should really set up a polling timer.
if (XFixesQueryExtension(xDisplay, &xFixesEventBase, &error))
{
XFixesSelectSelectionInput(xDisplay, xAppWin, XA_CLIPBOARD,
XFixesSetSelectionOwnerNotifyMask |
XFixesSelectionWindowDestroyNotifyMask |
XFixesSelectionClientCloseNotifyMask );
XFixesSelectSelectionInput(xDisplay, xAppWin, XA_PRIMARY,
XFixesSetSelectionOwnerNotifyMask |
XFixesSelectionWindowDestroyNotifyMask |
XFixesSelectionClientCloseNotifyMask);
// FIXME: Also handle the dnd pasteboard
NSDebugLLog(@"Pbs", @"Subscribed to XFixes notifications");
}
}
#endif
XFlush(xDisplay);
/*
@ -381,6 +416,14 @@ static NSString *xWaitMode = @"XPasteboardWaitMode";
break;
default:
#if HAVE_XFIXES
if (xEvent->type == xFixesEventBase + XFixesSelectionNotify)
{
[self xFixesSelectionNotify: (XFixesSelectionNotifyEvent*)xEvent];
break;
}
#endif
NSDebugLLog(@"Pbs", @"Unexpected X event.");
break;
}
@ -475,6 +518,27 @@ static NSString *xWaitMode = @"XPasteboardWaitMode";
[o xSelectionNotify: xEvent];
}
#if HAVE_XFIXES
+ (void) xFixesSelectionNotify: (XFixesSelectionNotifyEvent*)xEvent
{
XPbOwner *o = [self ownerByXPb: xEvent->selection];
if (o != nil)
{
if (xEvent->owner != (Window)xAppWin)
{
NSDebugLLog(@"Pbs", @"Notified that selection %@ changed", [[o osPb] name]);
// FIXME: Invalidate the cached types in the pasteboard since they are no longer valid
}
else
{
// The notification is telling us that we became the selection owner,
// which we already know about since we must have initiated that change.
}
}
}
#endif
+ (void) xSelectionRequest: (XSelectionRequestEvent*)xEvent
{
XPbOwner *o;

View file

@ -95,6 +95,9 @@
/* Define to enable Xcursor support */
#undef HAVE_XCURSOR
/* Define to enable Xfixes support */
#undef HAVE_XFIXES
/* Define if you have a functional XFreeType installation, including libXft.
*/
#undef HAVE_XFT

47
configure vendored
View file

@ -4706,6 +4706,53 @@ $as_echo "$XMU_LIBS" >&6; }
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XFixesSelectSelectionInput in -lXfixes" >&5
$as_echo_n "checking for XFixesSelectSelectionInput in -lXfixes... " >&6; }
if test "${ac_cv_lib_Xfixes_XFixesSelectSelectionInput+set}" = set; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lXfixes $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char XFixesSelectSelectionInput ();
int
main ()
{
return XFixesSelectSelectionInput ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_Xfixes_XFixesSelectSelectionInput=yes
else
ac_cv_lib_Xfixes_XFixesSelectSelectionInput=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_Xfixes_XFixesSelectSelectionInput" >&5
$as_echo "$ac_cv_lib_Xfixes_XFixesSelectSelectionInput" >&6; }
if test "x$ac_cv_lib_Xfixes_XFixesSelectSelectionInput" = x""yes; then :
LIBS="-lXfixes $LIBS"
$as_echo "#define HAVE_XFIXES 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XcursorImageCreate in -lXcursor" >&5
$as_echo_n "checking for XcursorImageCreate in -lXcursor... " >&6; }
if test "${ac_cv_lib_Xcursor_XcursorImageCreate+set}" = set; then :

View file

@ -152,6 +152,13 @@ if test $set_x_paths = yes; then
PKG_CHECK_MODULES([XMU], [xmu])
fi
AC_CHECK_LIB(Xfixes, XFixesSelectSelectionInput,
[
LIBS="-lXfixes $LIBS"
AC_DEFINE(HAVE_XFIXES, 1, [Define to enable Xfixes support])
]
,)
AC_CHECK_LIB(Xcursor, XcursorImageCreate,
[
LIBS="-lXcursor $LIBS"