--- /dev/null
+From 35540106538b24ca1765e752fe9d6efc968a88fa Mon Sep 17 00:00:00 2001
+From: Egbert Eich <eich@linux-p1mv.site>
+Date: Wed, 7 Oct 2009 16:31:44 +0200
+Subject: [PATCH] Check harder for primary PCI device.
+
+Primary PCI devices are identified by checking for an 'PCIINFOCLASSES'
+device which is VGA and has access to the memory bars enabled.
+If there should be more than one device for which this is true
+redo the check and also check if IO resoures are also enabled,
+if this still doesn't turn up a unique result also check for
+the presence of a BIOS rom.
+================================================================================
+--- xorg-server-1.7.99/hw/xfree86/common/xf86pciBus.c
++++ xorg-server-1.7.99/hw/xfree86/common/xf86pciBus.c
+@@ -140,9 +140,49 @@
+ primaryBus.type = BUS_PCI;
+ primaryBus.id.pci = info;
+ } else {
+- xf86Msg(X_NOTICE,
+- "More than one possible primary device found\n");
+- primaryBus.type ^= (BusType)(-1);
++ /*
++ * Ok, we found more than one possible primary device with this heuristic
++ * Now also check if IO is enabled.
++ */
++ int j;
++
++ primaryBus.type = BUS_NONE;
++ for (j = 0; j < num; j++) {
++ info = xf86PciVideoInfo[j];
++ pci_device_cfg_read_u16(info, & command, 4);
++
++ if ((command & PCI_CMD_MEM_ENABLE)
++ && (command & PCI_CMD_IO_ENABLE)
++ && (IS_VGA(info->device_class))) {
++ if (primaryBus.type == BUS_NONE) {
++ primaryBus.type = BUS_PCI;
++ primaryBus.id.pci = info;
++ } else {
++ primaryBus.type = BUS_NONE;
++ for (j = 0; j < num; j++) {
++ info = xf86PciVideoInfo[j];
++ pci_device_cfg_read_u16(info, & command, 4);
++
++ if ((command & PCI_CMD_MEM_ENABLE)
++ && (command & PCI_CMD_IO_ENABLE)
++ && (IS_VGA(info->device_class))
++ && info->rom_size) {
++ if (primaryBus.type == BUS_NONE) {
++ primaryBus.type = BUS_PCI;
++ primaryBus.id.pci = info;
++ } else {
++ xf86Msg(X_NOTICE,
++ "More than one possible primary device found\n");
++ primaryBus.type ^= (BusType)(-1);
++ break;
++ }
++ }
++ }
++ break;
++ }
++ }
++ }
++ break;
+ }
+ }
+ }
--- /dev/null
+--- xorg-server-1.9.0/mi/misprite.c.orig 2010-07-23 21:40:56.000000000 +0200
++++ xorg-server-1.9.0/mi/misprite.c 2010-08-23 15:44:51.000000000 +0200
+@@ -384,6 +384,7 @@ miSpriteCloseScreen (int i, ScreenPtr pS
+ pScreen->InstallColormap = pScreenPriv->InstallColormap;
+ pScreen->StoreColors = pScreenPriv->StoreColors;
+
++ miSpriteDisableDamage(pScreen, pScreenPriv);
+ DamageDestroy (pScreenPriv->pDamage);
+
+ free(pScreenPriv);
--- /dev/null
+From d1d9d4e5f8f9ac1d22e1258759d6ee9e49c7fe90 Mon Sep 17 00:00:00 2001
+From: Egbert Eich <eich@freedesktop.org>
+Date: Fri, 9 Apr 2010 15:10:32 +0200
+Subject: [PATCH] Prevent XSync Alarms from senslessly calling CheckTrigger() when inactive.
+
+If an XSync Alarm is set to inactive there is no need to check if a trigger
+needs to fire. Doing so if the counter is the IdleCounter will put the
+server on 100 percent CPU load since the select timeout is set to 0.
+---
+ xorg-server-1.8.0/Xext/sync.c | 11 +++++++++--
+ xorg-server-1.8.0/Xext/syncsrv.h | 1 +
+ 2 files changed, 10 insertions(+), 2 deletions(-)
+
+Index: xorg-server-1.8.0/Xext/sync.c
+===================================================================
+--- xorg-server-1.8.0.orig/Xext/sync.c
++++ xorg-server-1.8.0/Xext/sync.c
+@@ -518,6 +518,10 @@ SyncAlarmTriggerFired(SyncTrigger *pTrig
+ pAlarm->state = XSyncAlarmInactive;
+ }
+ }
++ /* Stop server from looping! */
++ if (pAlarm->state == XSyncAlarmInactive)
++ SyncDeleteTriggerFromCounter(&pAlarm->trigger);
++
+ /* The AlarmNotify event has to have the "new state of the alarm"
+ * which we can't be sure of until this point. However, it has
+ * to have the "old" trigger test value. That's the reason for
+@@ -730,7 +734,7 @@ SyncChangeAlarmAttributes(ClientPtr clie
+ XSyncCounter counter;
+ Mask origmask = mask;
+
+- counter = pAlarm->trigger.pCounter ? pAlarm->trigger.pCounter->id : None;
++ counter = pAlarm->counter_id;
+
+ while (mask)
+ {
+@@ -741,7 +745,7 @@ SyncChangeAlarmAttributes(ClientPtr clie
+ case XSyncCACounter:
+ mask &= ~XSyncCACounter;
+ /* sanity check in SyncInitTrigger */
+- counter = *values++;
++ counter = pAlarm->counter_id = *values++;
+ break;
+
+ case XSyncCAValueType:
+@@ -808,6 +812,14 @@ SyncChangeAlarmAttributes(ClientPtr clie
+ return BadMatch;
+ }
+ }
++ if (pAlarm->state == XSyncAlarmInactive) {
++ /*
++ * If we are inactive the trigger has been deleted from the counter.
++ * Persuade SyncInitTrigger() to readd it.
++ */
++ origmask |= XSyncCACounter;
++ pAlarm->trigger.pCounter = NULL;
++ }
+
+ /* postpone this until now, when we're sure nothing else can go wrong */
+ if ((status = SyncInitTrigger(client, &pAlarm->trigger, counter,
+@@ -815,6 +827,7 @@ SyncChangeAlarmAttributes(ClientPtr clie
+ return status;
+
+ /* XXX spec does not really say to do this - needs clarification */
++ /* It's the only place where it is set to XSyncAlarmActive! */
+ pAlarm->state = XSyncAlarmActive;
+ return Success;
+ }
+@@ -1617,8 +1630,10 @@ ProcSyncCreateAlarm(ClientPtr client)
+
+ pAlarm->client = client;
+ pAlarm->alarm_id = stuff->id;
++ pAlarm->counter_id = None;
+ XSyncIntToValue(&pAlarm->delta, 1L);
+ pAlarm->events = TRUE;
++ /* SyncChangeAlarmAttributes() changes this - no need to set this here! */
+ pAlarm->state = XSyncAlarmInactive;
+ pAlarm->pEventClients = NULL;
+ status = SyncChangeAlarmAttributes(client, pAlarm, vmask,
+Index: xorg-server-1.8.0/Xext/syncsrv.h
+===================================================================
+--- xorg-server-1.8.0.orig/Xext/syncsrv.h
++++ xorg-server-1.8.0/Xext/syncsrv.h
+@@ -129,6 +129,7 @@ typedef struct _SyncAlarm {
+ int events;
+ int state;
+ SyncAlarmClientList *pEventClients;
++ XSyncCounter counter_id;
+ } SyncAlarm;
+
+ typedef struct {
--- /dev/null
+>From 829037395f8b93e69a30852a95e378f78c3ccd6b Mon Sep 17 00:00:00 2001
+From: Luc Verhaegen <libv@skynet.be>
+Date: Wed, 12 Nov 2008 17:09:33 +0100
+Subject: [PATCH] Xinput: Catch missing configlayout when deleting device.
+
+In DeleteInputDeviceRequest (xf86Xinput.c), we access idev members
+even if idev is null. This takes down the xserver hard in some cases
+(kernel SIGABRT), and segfaults on other cases.
+================================================================================
+--- xorg-server-1.7.99/hw/xfree86/common/xf86Xinput.c
++++ xorg-server-1.7.99/hw/xfree86/common/xf86Xinput.c
+@@ -870,17 +870,20 @@
+ else
+ xf86DeleteInput(pInfo, 0);
+
+- /* devices added through HAL aren't in the config layout */
+- it = xf86ConfigLayout.inputs;
+- while(*it && *it != idev)
+- it++;
+-
+- if (!(*it)) /* end of list, not in the layout */
++ if (idev)
+ {
+- free(idev->driver);
+- free(idev->identifier);
+- xf86optionListFree(idev->commonOptions);
+- free(idev);
++ /* devices added through HAL aren't in the config layout */
++ it = xf86ConfigLayout.inputs;
++ while(*it && *it != idev)
++ it++;
++
++ if (!(*it)) /* end of list, not in the layout */
++ {
++ free(idev->driver);
++ free(idev->identifier);
++ xf86optionListFree(idev->commonOptions);
++ free(idev);
++ }
+ }
+ }
+ OsReleaseSignals();
--- /dev/null
+# This file contains configuration of libvnc.so module
+#
+# To get libvnc.so module working, do this:
+# 1. run "vncpasswd" as root user
+# 2. uncomment configuration lines below
+#
+# Please note you can specify any option which Xvnc accepts.
+# Refer to `Xvnc -help` output for detailed list of options.
+
+#Section "Module"
+# Load "vnc"
+#EndSection
+
+#Section "Screen"
+# Identifier "Screen0
+# DefaultDepth 16
+# Option "SecurityTypes" "VncAuth"
+# Option "PasswordFile" "/root/.vnc/passwd"
+#EndSection
--- /dev/null
+>From fedf91eeabcfdd6d26b52529a16a64f744aa42ad Mon Sep 17 00:00:00 2001
+From: Matthieu Herrb <matthieu.herrb@laas.fr>
+Date: Mon, 28 Jun 2010 23:54:13 +0200
+Subject: [PATCH] Workaround for CVE-2010-2240.
+
+By limiting the address space that the X server can use,
+it prevents stack and mmap()ed areas to become so close that
+the stack will grow over a mmaped area.
+
+Credits: Rafal Wojtczuk <rafal@invisiblethingslab.com>
+---
+ doc/Xserver.man.pre | 7 +++++++
+ include/opaque.h | 3 +++
+ os/osinit.c | 24 ++++++++++++++++++++++++
+ os/utils.c | 16 ++++++++++++++++
+ 4 files changed, 50 insertions(+), 0 deletions(-)
+
+diff --git a/doc/Xserver.man.pre b/doc/Xserver.man.pre
+index ce3b3a1..91c595f 100644
+--- a/doc/Xserver.man.pre
++++ b/doc/Xserver.man.pre
+@@ -285,6 +285,13 @@ sets the stack space limit of the server to the specified number of kilobytes.
+ A value of zero makes the stack size as large as possible. The default value
+ of \-1 leaves the stack space limit unchanged.
+ .TP 8
++.B \-la \fIkilobytes\fP
++sets the address space limit of the server to the specified number of
++kilobytes.
++A value of zero makes address space as large as possible.
++The default value is 1572864 (1.5GB) on 32 bit architectures and
++10485760 (10GB) on 64 bit architectures.
++.TP 8
+ .B \-logo
+ turns on the X Window System logo display in the screen-saver.
+ There is currently no way to change this from a client.
+diff --git a/include/opaque.h b/include/opaque.h
+index b3c7c70..4208d03 100644
+--- a/include/opaque.h
++++ b/include/opaque.h
+@@ -67,6 +67,9 @@ extern _X_EXPORT int limitStackSpace;
+ #ifdef RLIMIT_NOFILE
+ extern _X_EXPORT int limitNoFile;
+ #endif
++#ifdef RLIMIT_AS
++extern _X_EXPORT int limitAddressSpace;
++#endif
+ extern _X_EXPORT Bool defeatAccessControl;
+ extern _X_EXPORT long maxBigRequestSize;
+ extern _X_EXPORT Bool party_like_its_1989;
+diff --git a/os/osinit.c b/os/osinit.c
+index 32747df..723fb14 100644
+--- a/os/osinit.c
++++ b/os/osinit.c
+@@ -96,6 +96,14 @@ int limitStackSpace = -1;
+ #ifdef RLIMIT_NOFILE
+ int limitNoFile = -1;
+ #endif
++#ifdef RLIMIT_AS
++#ifdef _XSERVER64
++#define XORG_AS_LIMIT 10737418240LL
++#else
++#define XORG_AS_LIMIT 1610612736
++#endif
++long limitAddressSpace = XORG_AS_LIMIT;
++#endif
+
+ static OsSigWrapperPtr OsSigWrapper = NULL;
+
+@@ -301,6 +309,22 @@ OsInit(void)
+ }
+ }
+ #endif
++#ifdef RLIMIT_AS
++ if (limitAddressSpace >= 0)
++ {
++ struct rlimit rlim;
++
++ if (!getrlimit(RLIMIT_AS, &rlim))
++ {
++ if ((limitAddressSpace > 0)
++ && (limitAddressSpace < rlim.rlim_max))
++ rlim.rlim_cur = limitAddressSpace;
++ else
++ rlim.rlim_cur = rlim.rlim_max;
++ (void)setrlimit(RLIMIT_AS, &rlim);
++ }
++ }
++#endif
+ LockServer();
+ been_here = TRUE;
+ }
+diff --git a/os/utils.c b/os/utils.c
+index 51455cc..4af0cb3 100644
+--- a/os/utils.c
++++ b/os/utils.c
+@@ -745,6 +745,22 @@ ProcessCommandLine(int argc, char *argv[])
+ UseMsg();
+ }
+ #endif
++#ifdef RLIMIT_AS
++ else if ( strcmp( argv[i], "-la") == 0)
++ {
++ if (getuid() != geteuid()) {
++ FatalError("The '-la' option can only be used by root.\n");
++ }
++ if(++i < argc)
++ {
++ limitAddressSpace = atol(argv[i]);
++ if (limitAddressSpace > 0)
++ limitAddressSpace *= 1024;
++ }
++ else
++ UseMsg();
++ }
++#endif
+ else if ( strcmp ( argv[i], "-nolock") == 0)
+ {
+ #if !defined(WIN32) && !defined(__CYGWIN__)
+--
+1.7.0.5
+
--- /dev/null
+--- xorg-server-1.9.0/dix/window.c.orig 2010-08-23 16:07:24.000000000 +0200
++++ xorg-server-1.9.0/dix/window.c 2010-08-23 16:14:09.000000000 +0200
+@@ -535,6 +535,48 @@ RealChildHead(WindowPtr pWin)
+ return NullWindow;
+ }
+
++static int
++TreeDepth(WindowPtr pWin)
++{
++ int depth = 1;
++ int max_depth = 1;
++ WindowPtr pChild;
++
++ if (!(pChild = pWin))
++ return 0;
++ while (1)
++ {
++ if (pChild->firstChild)
++ {
++ ++depth;
++ pChild = pChild->firstChild;
++ continue;
++ } else if (depth > max_depth)
++ max_depth = depth;
++ while (!pChild->nextSib && (pChild != pWin)) {
++ --depth;
++ pChild = pChild->parent;
++ }
++ if (pChild == pWin)
++ break;
++ pChild = pChild->nextSib;
++ }
++ return max_depth;
++}
++
++static int
++WindowDepth(WindowPtr pWin)
++{
++ int depth = 0;
++ while (pWin) {
++ ++depth;
++ pWin = pWin->parent;
++ }
++ return depth;
++}
++
++#define MAX_TREE_DEPTH 256
++
+ /*****
+ * CreateWindow
+ * Makes a window in response to client request
+@@ -555,6 +597,11 @@ CreateWindow(Window wid, WindowPtr pPare
+ PixmapFormatRec *format;
+ WindowOptPtr ancwopt;
+
++ if (WindowDepth(pParent) >= MAX_TREE_DEPTH - 1) {
++ *error = BadAlloc;
++ return NullWindow;
++ }
++
+ if (class == CopyFromParent)
+ class = pParent->drawable.class;
+
+@@ -2434,6 +2481,9 @@ ReparentWindow(WindowPtr pWin, WindowPtr
+ int bw = wBorderWidth (pWin);
+ ScreenPtr pScreen;
+
++ if (WindowDepth(pParent) + TreeDepth(pWin) >= MAX_TREE_DEPTH)
++ return BadAlloc;
++
+ pScreen = pWin->drawable.pScreen;
+ if (TraverseTree(pWin, CompareWIDs, (pointer)&pParent->drawable.id) == WT_STOPWALKING)
+ return BadMatch;
--- /dev/null
+From 7b3b7efe78dec87c8059ea0d0985f08a97f0633d Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Michel=20D=C3=A4nzer?= <daenzer@vmware.com>
+Date: Thu, 24 Feb 2011 12:17:57 +0100
+Subject: [PATCH] EXA/mixed: ModifyPixmapHeader pitch fixes. (bug #33929)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+If there's a GPU copy and a non-zero devKind was passed in, set the GPU copy
+pitch to that instead of to a possibly bogus value derived from the new width.
+This is e.g. used by the radeon driver's drmmode_xf86crtc_resize hook, fixes
+https://bugs.freedesktop.org/show_bug.cgi?id=33929 .
+
+On the other hand, the system memory copy doesn't need the pitch to be aligned
+beyond the PixmapBytePad of the width.
+
+Signed-off-by: Michel Dänzer <daenzer@vmware.com>
+Acked-by: Cyril Brulebois <kibi@debian.org>
+Tested-by: Cyril Brulebois <kibi@debian.org>
+Reported-by: Thierry Vignaud <thierry.vignaud@gmail.com>
+Tested-by: Thierry Vignaud <thierry.vignaud@gmail.com>
+Signed-off-by: Keith Packard <keithp@keithp.com>
+(cherry picked from commit 31704510f448706524b7b7085cc4ff0ada7bfe7e)
+---
+ exa/exa_mixed.c | 9 +++++----
+ 1 files changed, 5 insertions(+), 4 deletions(-)
+
+diff --git a/exa/exa_mixed.c b/exa/exa_mixed.c
+index 606f1e1..fd1afb2 100644
+--- a/exa/exa_mixed.c
++++ b/exa/exa_mixed.c
+@@ -175,8 +175,10 @@ exaModifyPixmapHeader_mixed(PixmapPtr pPixmap, int width, int height, int depth,
+ depth != pPixmap->drawable.depth ||
+ bitsPerPixel != pPixmap->drawable.bitsPerPixel) {
+ if (pExaPixmap->driverPriv) {
+- exaSetFbPitch(pExaScr, pExaPixmap,
+- width, height, bitsPerPixel);
++ if (devKind > 0)
++ pExaPixmap->fb_pitch = devKind;
++ else
++ exaSetFbPitch(pExaScr, pExaPixmap, width, height, bitsPerPixel);
+
+ exaSetAccelBlock(pExaScr, pExaPixmap,
+ width, height, bitsPerPixel);
+@@ -187,8 +189,7 @@ exaModifyPixmapHeader_mixed(PixmapPtr pPixmap, int width, int height, int depth,
+ if (has_gpu_copy && pExaPixmap->sys_ptr) {
+ free(pExaPixmap->sys_ptr);
+ pExaPixmap->sys_ptr = NULL;
+- pExaPixmap->sys_pitch = devKind > 0 ? devKind :
+- PixmapBytePad(width, depth);
++ pExaPixmap->sys_pitch = PixmapBytePad(width, depth);
+ DamageUnregister(&pPixmap->drawable, pExaPixmap->pDamage);
+ DamageDestroy(pExaPixmap->pDamage);
+ pExaPixmap->pDamage = NULL;
+--
+1.7.4.1
+
--- /dev/null
+From: Julien Cristau <jcristau@debian.org>
+Date: Sat Jul 3 19:42:26 2010 +0100
+Subject: [PATCH] glx: make sure screen is non-negative in validGlxScreen
+Patch-Mainline: Upstream
+Git-commit: 3f0d3f4d97bce75c1828635c322b6560a45a037f
+References: bnc #648278, CVE-2010-4818
+Signed-off-by: Egbert Eich <eich@suse.de>
+
+Reviewed-by: Adam Jackson <ajax@redhat.com>
+Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
+Reviewed-by: Daniel Stone <daniel@fooishbar.org>
+Signed-off-by: Julien Cristau <jcristau@debian.org>
+---
+ glx/glxcmds.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- xorg-server-1.6.5.orig/glx/glxcmds.c
++++ xorg-server-1.6.5/glx/glxcmds.c
+@@ -65,7 +65,7 @@ validGlxScreen(ClientPtr client, int scr
+ /*
+ ** Check if screen exists.
+ */
+- if (screen >= screenInfo.numScreens) {
++ if (screen < 0 || screen >= screenInfo.numScreens) {
+ client->errorValue = screen;
+ *err = BadValue;
+ return FALSE;
--- /dev/null
+From: Julien Cristau <jcristau@debian.org>
+Date: Sat Jul 3 19:47:55 2010 +0100
+Subject: [PATCH] glx: validate request lengths
+Patch-Mainline: Upstream
+Git-commit: ec9c97c6bf70b523bc500bd3adf62176f1bb33a4
+References: bnc #648278, CVE-2010-4818
+Signed-off-by: Egbert Eich <eich@suse.de>
+
+Reviewed-by: Adam Jackson <ajax@redhat.com>
+Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
+Reviewed-by: Daniel Stone <daniel@fooishbar.org>
+Signed-off-by: Julien Cristau <jcristau@debian.org>
+
+--- xorg-server-1.6.5.orig/glx/xfont.c
++++ xorg-server-1.6.5/glx/xfont.c
+@@ -161,6 +161,8 @@ int __glXDisp_UseXFont(__GLXclientState
+ __GLXcontext *cx;
+ int error;
+
++ REQUEST_SIZE_MATCH(xGLXUseXFontReq);
++
+ req = (xGLXUseXFontReq *) pc;
+ cx = __glXForceCurrent(cl, req->contextTag, &error);
+ if (!cx) {
+--- xorg-server-1.9.3/glx/glxcmds.c.orig 2012-02-06 14:45:15.000000000 +0100
++++ xorg-server-1.9.3/glx/glxcmds.c 2012-02-06 15:09:00.000000000 +0100
+@@ -315,11 +315,14 @@ DoCreateContext(__GLXclientState *cl, GL
+
+ int __glXDisp_CreateContext(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateContextReq *req = (xGLXCreateContextReq *) pc;
+ __GLXconfig *config;
+ __GLXscreen *pGlxScreen;
+ int err;
+
++ REQUEST_SIZE_MATCH(xGLXCreateContextReq);
++
+ if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
+ return err;
+ if (!validGlxVisual(cl->client, pGlxScreen, req->visual, &config, &err))
+@@ -331,11 +334,14 @@ int __glXDisp_CreateContext(__GLXclientS
+
+ int __glXDisp_CreateNewContext(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateNewContextReq *req = (xGLXCreateNewContextReq *) pc;
+ __GLXconfig *config;
+ __GLXscreen *pGlxScreen;
+ int err;
+
++ REQUEST_SIZE_MATCH(xGLXCreateNewContextReq);
++
+ if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
+ return err;
+ if (!validGlxFBConfig(cl->client, pGlxScreen, req->fbconfig, &config, &err))
+@@ -347,12 +353,15 @@ int __glXDisp_CreateNewContext(__GLXclie
+
+ int __glXDisp_CreateContextWithConfigSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateContextWithConfigSGIXReq *req =
+ (xGLXCreateContextWithConfigSGIXReq *) pc;
+ __GLXconfig *config;
+ __GLXscreen *pGlxScreen;
+ int err;
+
++ REQUEST_SIZE_MATCH(xGLXCreateContextWithConfigSGIXReq);
++
+ if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
+ return err;
+ if (!validGlxFBConfig(cl->client, pGlxScreen, req->fbconfig, &config, &err))
+@@ -372,6 +372,7 @@ int __glXDisp_CreateContextWithConfigSGI
+ }
+ int __glXDisp_DestroyContext(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXDestroyContextReq *req = (xGLXDestroyContextReq *) pc;
+ __GLXcontext *glxc;
+ int err;
+@@ -367,6 +376,8 @@ int __glXDisp_DestroyContext(__GLXclient
+ __GLXcontext *glxc;
+ int err;
+
++ REQUEST_SIZE_MATCH(xGLXDestroyContextReq);
++
+ if (!validGlxContext(cl->client, req->context, DixDestroyAccess,
+ &glxc, &err))
+ return err;
+@@ -686,24 +697,33 @@ DoMakeCurrent(__GLXclientState *cl,
+
+ int __glXDisp_MakeCurrent(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXMakeCurrentReq *req = (xGLXMakeCurrentReq *) pc;
+
++ REQUEST_SIZE_MATCH(xGLXMakeCurrentReq);
++
+ return DoMakeCurrent( cl, req->drawable, req->drawable,
+ req->context, req->oldContextTag );
+ }
+
+ int __glXDisp_MakeContextCurrent(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXMakeContextCurrentReq *req = (xGLXMakeContextCurrentReq *) pc;
+
++ REQUEST_SIZE_MATCH(xGLXMakeContextCurrentReq);
++
+ return DoMakeCurrent( cl, req->drawable, req->readdrawable,
+ req->context, req->oldContextTag );
+ }
+
+ int __glXDisp_MakeCurrentReadSGI(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXMakeCurrentReadSGIReq *req = (xGLXMakeCurrentReadSGIReq *) pc;
+
++ REQUEST_SIZE_MATCH(xGLXMakeCurrentReadSGIReq);
++
+ return DoMakeCurrent( cl, req->drawable, req->readable,
+ req->context, req->oldContextTag );
+ }
+@@ -716,6 +736,8 @@ int __glXDisp_IsDirect(__GLXclientState
+ __GLXcontext *glxc;
+ int err;
+
++ REQUEST_SIZE_MATCH(xGLXIsDirectReq);
++
+ if (!validGlxContext(cl->client, req->context, DixReadAccess, &glxc, &err))
+ return err;
+
+@@ -740,6 +762,8 @@ int __glXDisp_QueryVersion(__GLXclientSt
+ xGLXQueryVersionReply reply;
+ GLuint major, minor;
+
++ REQUEST_SIZE_MATCH(xGLXQueryVersionReq);
++
+ major = req->majorVersion;
+ minor = req->minorVersion;
+ (void)major;
+@@ -766,11 +790,15 @@ int __glXDisp_QueryVersion(__GLXclientSt
+
+ int __glXDisp_WaitGL(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXWaitGLReq *req = (xGLXWaitGLReq *)pc;
+- GLXContextTag tag = req->contextTag;
++ GLXContextTag tag;
+ __GLXcontext *glxc = NULL;
+ int error;
+
++ REQUEST_SIZE_MATCH(xGLXWaitGLReq);
++
++ tag = req->contextTag;
+ if (tag) {
+ glxc = __glXLookupContextByTag(cl, tag);
+ if (!glxc)
+@@ -790,11 +818,15 @@ int __glXDisp_WaitGL(__GLXclientState *c
+
+ int __glXDisp_WaitX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXWaitXReq *req = (xGLXWaitXReq *)pc;
+- GLXContextTag tag = req->contextTag;
++ GLXContextTag tag;
+ __GLXcontext *glxc = NULL;
+ int error;
+
++ REQUEST_SIZE_MATCH(xGLXWaitXReq);
++
++ tag = req->contextTag;
+ if (tag) {
+ glxc = __glXLookupContextByTag(cl, tag);
+ if (!glxc)
+@@ -814,13 +846,21 @@ int __glXDisp_CopyContext(__GLXclientSta
+ {
+ ClientPtr client = cl->client;
+ xGLXCopyContextReq *req = (xGLXCopyContextReq *) pc;
+- GLXContextID source = req->source;
+- GLXContextID dest = req->dest;
+- GLXContextTag tag = req->contextTag;
+- unsigned long mask = req->mask;
++ GLXContextID source;
++ GLXContextID dest;
++ GLXContextTag tag;
++ unsigned long mask;
++
+ __GLXcontext *src, *dst;
+ int error;
+
++ REQUEST_SIZE_MATCH(xGLXCopyContextReq);
++
++ source = req->source;
++ dest = req->dest;
++ tag = req->contextTag;
++ mask = req->mask;
++
+ if (!validGlxContext(cl->client, source, DixReadAccess, &src, &error))
+ return error;
+ if (!validGlxContext(cl->client, dest, DixWriteAccess, &dst, &error))
+@@ -903,6 +943,8 @@ int __glXDisp_GetVisualConfigs(__GLXclie
+ __GLX_DECLARE_SWAP_VARIABLES;
+ __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXGetVisualConfigsReq);
++
+ if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
+ return err;
+
+@@ -1082,13 +1124,17 @@ DoGetFBConfigs(__GLXclientState *cl, uns
+
+ int __glXDisp_GetFBConfigs(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXGetFBConfigsReq *req = (xGLXGetFBConfigsReq *) pc;
++ REQUEST_SIZE_MATCH(xGLXGetFBConfigsReq);
+ return DoGetFBConfigs(cl, req->screen);
+ }
+
+ int __glXDisp_GetFBConfigsSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXGetFBConfigsSGIXReq *req = (xGLXGetFBConfigsSGIXReq *) pc;
++ REQUEST_SIZE_MATCH(xGLXGetFBConfigsSGIXReq);
+ return DoGetFBConfigs(cl, req->screen);
+ }
+
+@@ -1214,11 +1260,14 @@ determineTextureTarget(ClientPtr client,
+
+ int __glXDisp_CreateGLXPixmap(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateGLXPixmapReq *req = (xGLXCreateGLXPixmapReq *) pc;
+ __GLXconfig *config;
+ __GLXscreen *pGlxScreen;
+ int err;
+
++ REQUEST_SIZE_MATCH(xGLXCreateGLXPixmapReq);
++
+ if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
+ return err;
+ if (!validGlxVisual(cl->client, pGlxScreen, req->visual, &config, &err))
+@@ -1230,11 +1279,14 @@ int __glXDisp_CreateGLXPixmap(__GLXclien
+
+ int __glXDisp_CreatePixmap(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreatePixmapReq *req = (xGLXCreatePixmapReq *) pc;
+ __GLXconfig *config;
+ __GLXscreen *pGlxScreen;
+ int err;
+
++ REQUEST_FIXED_SIZE(xGLXCreatePixmapReq, req->numAttribs << 3);
++
+ if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
+ return err;
+ if (!validGlxFBConfig(cl->client, pGlxScreen, req->fbconfig, &config, &err))
+@@ -1253,12 +1305,15 @@ int __glXDisp_CreatePixmap(__GLXclientSt
+
+ int __glXDisp_CreateGLXPixmapWithConfigSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateGLXPixmapWithConfigSGIXReq *req =
+ (xGLXCreateGLXPixmapWithConfigSGIXReq *) pc;
+ __GLXconfig *config;
+ __GLXscreen *pGlxScreen;
+ int err;
+
++ REQUEST_SIZE_MATCH(xGLXCreateGLXPixmapWithConfigSGIXReq);
++
+ if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
+ return err;
+ if (!validGlxFBConfig(cl->client, pGlxScreen, req->fbconfig, &config, &err))
+@@ -1285,15 +1340,21 @@ static int DoDestroyDrawable(__GLXclient
+
+ int __glXDisp_DestroyGLXPixmap(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXDestroyGLXPixmapReq *req = (xGLXDestroyGLXPixmapReq *) pc;
+
++ REQUEST_SIZE_MATCH(xGLXDestroyGLXPixmapReq);
++
+ return DoDestroyDrawable(cl, req->glxpixmap, GLX_DRAWABLE_PIXMAP);
+ }
+
+ int __glXDisp_DestroyPixmap(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXDestroyPixmapReq *req = (xGLXDestroyPixmapReq *) pc;
+
++ REQUEST_SIZE_MATCH(xGLXDestroyPixmapReq);
++
+ return DoDestroyDrawable(cl, req->glxpixmap, GLX_DRAWABLE_PIXMAP);
+ }
+
+@@ -1332,10 +1393,13 @@ DoCreatePbuffer(ClientPtr client, int sc
+
+ int __glXDisp_CreatePbuffer(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreatePbufferReq *req = (xGLXCreatePbufferReq *) pc;
+ CARD32 *attrs;
+ int width, height, i;
+
++ REQUEST_FIXED_SIZE(xGLXCreatePbufferReq, req->numAttribs << 3);
++
+ attrs = (CARD32 *) (req + 1);
+ width = 0;
+ height = 0;
+@@ -1361,23 +1425,32 @@ int __glXDisp_CreatePbuffer(__GLXclientS
+
+ int __glXDisp_CreateGLXPbufferSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateGLXPbufferSGIXReq *req = (xGLXCreateGLXPbufferSGIXReq *) pc;
+
++ REQUEST_SIZE_MATCH(xGLXCreateGLXPbufferSGIXReq);
++
+ return DoCreatePbuffer(cl->client, req->screen, req->fbconfig,
+ req->width, req->height, req->pbuffer);
+ }
+
+ int __glXDisp_DestroyPbuffer(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXDestroyPbufferReq *req = (xGLXDestroyPbufferReq *) pc;
+
++ REQUEST_SIZE_MATCH(xGLXDestroyPbufferReq);
++
+ return DoDestroyDrawable(cl, req->pbuffer, GLX_DRAWABLE_PBUFFER);
+ }
+
+ int __glXDisp_DestroyGLXPbufferSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXDestroyGLXPbufferSGIXReq *req = (xGLXDestroyGLXPbufferSGIXReq *) pc;
+
++ REQUEST_SIZE_MATCH(xGLXDestroyGLXPbufferSGIXReq);
++
+ return DoDestroyDrawable(cl, req->pbuffer, GLX_DRAWABLE_PBUFFER);
+ }
+
+@@ -1408,18 +1481,24 @@ DoChangeDrawableAttributes(ClientPtr cli
+
+ int __glXDisp_ChangeDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXChangeDrawableAttributesReq *req =
+ (xGLXChangeDrawableAttributesReq *) pc;
+
++ REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesReq, req->numAttribs << 3);
++
+ return DoChangeDrawableAttributes(cl->client, req->drawable,
+ req->numAttribs, (CARD32 *) (req + 1));
+ }
+
+ int __glXDisp_ChangeDrawableAttributesSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXChangeDrawableAttributesSGIXReq *req =
+ (xGLXChangeDrawableAttributesSGIXReq *)pc;
+
++ REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesSGIXReq, req->numAttribs << 3);
++
+ return DoChangeDrawableAttributes(cl->client, req->drawable,
+ req->numAttribs, (CARD32 *) (req + 1));
+ }
+@@ -1433,6 +1512,8 @@ int __glXDisp_CreateWindow(__GLXclientSt
+ DrawablePtr pDraw;
+ int err;
+
++ REQUEST_FIXED_SIZE(xGLXCreateWindowReq, req->numAttribs << 3);
++
+ LEGAL_NEW_RESOURCE(req->glxwindow, client);
+
+ if (!validGlxScreen(client, req->screen, &pGlxScreen, &err))
+@@ -1456,8 +1537,11 @@ int __glXDisp_CreateWindow(__GLXclientSt
+
+ int __glXDisp_DestroyWindow(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXDestroyWindowReq *req = (xGLXDestroyWindowReq *) pc;
+
++ REQUEST_SIZE_MATCH(xGLXDestroyWindowReq);
++
+ return DoDestroyDrawable(cl, req->glxwindow, GLX_DRAWABLE_WINDOW);
+ }
+
+@@ -1473,12 +1557,16 @@ int __glXDisp_SwapBuffers(__GLXclientSta
+ {
+ ClientPtr client = cl->client;
+ xGLXSwapBuffersReq *req = (xGLXSwapBuffersReq *) pc;
+- GLXContextTag tag = req->contextTag;
+- XID drawId = req->drawable;
++ GLXContextTag tag;
++ XID drawId;
+ __GLXcontext *glxc = NULL;
+ __GLXdrawable *pGlxDraw;
+ int error;
+
++ REQUEST_SIZE_MATCH(xGLXSwapBuffersReq);
++
++ tag = req->contextTag;
++ drawId = req->drawable;
+ if (tag) {
+ glxc = __glXLookupContextByTag(cl, tag);
+ if (!glxc) {
+@@ -1559,15 +1647,21 @@ DoQueryContext(__GLXclientState *cl, GLX
+
+ int __glXDisp_QueryContextInfoEXT(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXQueryContextInfoEXTReq *req = (xGLXQueryContextInfoEXTReq *) pc;
+
++ REQUEST_SIZE_MATCH(xGLXQueryContextInfoEXTReq);
++
+ return DoQueryContext(cl, req->context);
+ }
+
+ int __glXDisp_QueryContext(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXQueryContextReq *req = (xGLXQueryContextReq *) pc;
+
++ REQUEST_SIZE_MATCH(xGLXQueryContextReq);
++
+ return DoQueryContext(cl, req->context);
+ }
+
+@@ -1581,6 +1675,8 @@ int __glXDisp_BindTexImageEXT(__GLXclien
+ int buffer;
+ int error;
+
++ REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 8);
++
+ pc += __GLX_VENDPRIV_HDR_SIZE;
+
+ drawId = *((CARD32 *) (pc));
+@@ -1615,6 +1711,8 @@ int __glXDisp_ReleaseTexImageEXT(__GLXcl
+ int buffer;
+ int error;
+
++ REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 8);
++
+ pc += __GLX_VENDPRIV_HDR_SIZE;
+
+ drawId = *((CARD32 *) (pc));
+@@ -1650,6 +1748,8 @@ int __glXDisp_CopySubBufferMESA(__GLXcli
+ (void) client;
+ (void) req;
+
++ REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 20);
++
+ pc += __GLX_VENDPRIV_HDR_SIZE;
+
+ drawId = *((CARD32 *) (pc));
+@@ -1738,16 +1838,22 @@ DoGetDrawableAttributes(__GLXclientState
+
+ int __glXDisp_GetDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXGetDrawableAttributesReq *req = (xGLXGetDrawableAttributesReq *)pc;
+
++ REQUEST_SIZE_MATCH(xGLXGetDrawableAttributesReq);
++
+ return DoGetDrawableAttributes(cl, req->drawable);
+ }
+
+ int __glXDisp_GetDrawableAttributesSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXGetDrawableAttributesSGIXReq *req =
+ (xGLXGetDrawableAttributesSGIXReq *)pc;
+
++ REQUEST_SIZE_MATCH(xGLXGetDrawableAttributesSGIXReq);
++
+ return DoGetDrawableAttributes(cl, req->drawable);
+ }
+
+@@ -1772,6 +1878,8 @@ int __glXDisp_Render(__GLXclientState *c
+ __GLXcontext *glxc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_AT_LEAST_SIZE(xGLXRenderReq);
++
+ req = (xGLXRenderReq *) pc;
+ if (client->swapped) {
+ __GLX_SWAP_SHORT(&req->length);
+@@ -1792,6 +1900,9 @@ int __glXDisp_Render(__GLXclientState *c
+ __GLXdispatchRenderProcPtr proc;
+ int err;
+
++ if (left < sizeof(__GLXrenderHeader))
++ return BadLength;
++
+ /*
+ ** Verify that the header length and the overall length agree.
+ ** Also, each command must be word aligned.
+@@ -2302,10 +2413,12 @@ int __glXDisp_HyperpipeConfigSGIX(__GLXc
+
+ int __glXDisp_VendorPrivate(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
+ GLint vendorcode = req->vendorCode;
+ __GLXdispatchVendorPrivProcPtr proc;
+
++ REQUEST_AT_LEAST_SIZE(xGLXVendorPrivateReq);
+
+ proc = (__GLXdispatchVendorPrivProcPtr)
+ __glXGetProtocolDecodeFunction(& VendorPriv_dispatch_info,
+@@ -2321,10 +2434,12 @@ int __glXDisp_VendorPrivate(__GLXclientS
+
+ int __glXDisp_VendorPrivateWithReply(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
+ GLint vendorcode = req->vendorCode;
+ __GLXdispatchVendorPrivProcPtr proc;
+
++ REQUEST_AT_LEAST_SIZE(xGLXVendorPrivateReq);
+
+ proc = (__GLXdispatchVendorPrivProcPtr)
+ __glXGetProtocolDecodeFunction(& VendorPriv_dispatch_info,
+@@ -2347,6 +2462,8 @@ int __glXDisp_QueryExtensionsString(__GL
+ char *buf;
+ int err;
+
++ REQUEST_SIZE_MATCH(xGLXQueryExtensionsStringReq);
++
+ if (!validGlxScreen(client, req->screen, &pGlxScreen, &err))
+ return err;
+
+@@ -2386,6 +2503,8 @@ int __glXDisp_QueryServerString(__GLXcli
+ int err;
+ char ver_str[16];
+
++ REQUEST_SIZE_MATCH(xGLXQueryServerStringReq);
++
+ if (!validGlxScreen(client, req->screen, &pGlxScreen, &err))
+ return err;
+
+@@ -2433,13 +2552,19 @@ int __glXDisp_QueryServerString(__GLXcli
+
+ int __glXDisp_ClientInfo(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXClientInfoReq *req = (xGLXClientInfoReq *) pc;
+ const char *buf;
++
++ REQUEST_AT_LEAST_SIZE(xGLXClientInfoReq);
++
++ buf = (const char *)(req+1);
++ if (!memchr(buf, 0, (client->req_len << 2) - sizeof(xGLXClientInfoReq)))
++ return BadLength;
+
+ cl->GLClientmajorVersion = req->major;
+ cl->GLClientminorVersion = req->minor;
+ free(cl->GLClientextensions);
+- buf = (const char *)(req+1);
+ cl->GLClientextensions = strdup(buf);
+
+ return Success;
--- /dev/null
+From: Julien Cristau <jcristau@debian.org>
+Date: Sun Aug 22 00:50:05 2010 +0100
+Subject: [PATCH] glx: check request length before swapping
+Patch-Mainline: Upstream
+Git-commit: 6c69235a9dfc52e4b4e47630ff4bab1a820eb543
+References: bnc #648278, CVE-2010-4818
+Signed-off-by: Egbert Eich <eich@suse.de>
+
+Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
+Reviewed-by: Daniel Stone <daniel@fooishbar.org>
+Signed-off-by: Julien Cristau <jcristau@debian.org>
+
+--- xorg-server-1.9.3/glx/glxcmdsswap.c.orig 2010-03-23 18:35:57.000000000 +0100
++++ xorg-server-1.9.3/glx/glxcmdsswap.c 2012-02-06 15:21:28.000000000 +0100
+@@ -61,9 +61,12 @@
+
+ int __glXDispSwap_CreateContext(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateContextReq *req = (xGLXCreateContextReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXCreateContextReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->context);
+ __GLX_SWAP_INT(&req->visual);
+@@ -75,9 +78,12 @@ int __glXDispSwap_CreateContext(__GLXcli
+
+ int __glXDispSwap_CreateNewContext(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateNewContextReq *req = (xGLXCreateNewContextReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXCreateNewContextReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->context);
+ __GLX_SWAP_INT(&req->fbconfig);
+@@ -90,10 +96,13 @@ int __glXDispSwap_CreateNewContext(__GLX
+
+ int __glXDispSwap_CreateContextWithConfigSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateContextWithConfigSGIXReq *req =
+ (xGLXCreateContextWithConfigSGIXReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXCreateContextWithConfigSGIXReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->context);
+ __GLX_SWAP_INT(&req->fbconfig);
+@@ -106,9 +115,12 @@ int __glXDispSwap_CreateContextWithConfi
+
+ int __glXDispSwap_DestroyContext(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXDestroyContextReq *req = (xGLXDestroyContextReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXDestroyContextReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->context);
+
+@@ -117,9 +129,12 @@ int __glXDispSwap_DestroyContext(__GLXcl
+
+ int __glXDispSwap_MakeCurrent(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXMakeCurrentReq *req = (xGLXMakeCurrentReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXMakeCurrentReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->drawable);
+ __GLX_SWAP_INT(&req->context);
+@@ -130,9 +145,12 @@ int __glXDispSwap_MakeCurrent(__GLXclien
+
+ int __glXDispSwap_MakeContextCurrent(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXMakeContextCurrentReq *req = (xGLXMakeContextCurrentReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXMakeContextCurrentReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->drawable);
+ __GLX_SWAP_INT(&req->readdrawable);
+@@ -144,9 +162,12 @@ int __glXDispSwap_MakeContextCurrent(__G
+
+ int __glXDispSwap_MakeCurrentReadSGI(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXMakeCurrentReadSGIReq *req = (xGLXMakeCurrentReadSGIReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXMakeCurrentReadSGIReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->drawable);
+ __GLX_SWAP_INT(&req->readable);
+@@ -158,9 +179,12 @@ int __glXDispSwap_MakeCurrentReadSGI(__G
+
+ int __glXDispSwap_IsDirect(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXIsDirectReq *req = (xGLXIsDirectReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXIsDirectReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->context);
+
+@@ -169,9 +193,12 @@ int __glXDispSwap_IsDirect(__GLXclientSt
+
+ int __glXDispSwap_QueryVersion(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXQueryVersionReq *req = (xGLXQueryVersionReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXQueryVersionReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->majorVersion);
+ __GLX_SWAP_INT(&req->minorVersion);
+@@ -181,9 +208,12 @@ int __glXDispSwap_QueryVersion(__GLXclie
+
+ int __glXDispSwap_WaitGL(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXWaitGLReq *req = (xGLXWaitGLReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXWaitGLReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->contextTag);
+
+@@ -192,9 +222,12 @@ int __glXDispSwap_WaitGL(__GLXclientStat
+
+ int __glXDispSwap_WaitX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXWaitXReq *req = (xGLXWaitXReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXWaitXReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->contextTag);
+
+@@ -203,9 +236,12 @@ int __glXDispSwap_WaitX(__GLXclientState
+
+ int __glXDispSwap_CopyContext(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCopyContextReq *req = (xGLXCopyContextReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXCopyContextReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->source);
+ __GLX_SWAP_INT(&req->dest);
+@@ -216,36 +252,48 @@ int __glXDispSwap_CopyContext(__GLXclien
+
+ int __glXDispSwap_GetVisualConfigs(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXGetVisualConfigsReq *req = (xGLXGetVisualConfigsReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXGetVisualConfigsReq);
++
+ __GLX_SWAP_INT(&req->screen);
+ return __glXDisp_GetVisualConfigs(cl, pc);
+ }
+
+ int __glXDispSwap_GetFBConfigs(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXGetFBConfigsReq *req = (xGLXGetFBConfigsReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXGetFBConfigsReq);
++
+ __GLX_SWAP_INT(&req->screen);
+ return __glXDisp_GetFBConfigs(cl, pc);
+ }
+
+ int __glXDispSwap_GetFBConfigsSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXGetFBConfigsSGIXReq *req = (xGLXGetFBConfigsSGIXReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXGetFBConfigsSGIXReq);
++
+ __GLX_SWAP_INT(&req->screen);
+ return __glXDisp_GetFBConfigsSGIX(cl, pc);
+ }
+
+ int __glXDispSwap_CreateGLXPixmap(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateGLXPixmapReq *req = (xGLXCreateGLXPixmapReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXCreateGLXPixmapReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->screen);
+ __GLX_SWAP_INT(&req->visual);
+@@ -257,17 +305,22 @@ int __glXDispSwap_CreateGLXPixmap(__GLXc
+
+ int __glXDispSwap_CreatePixmap(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreatePixmapReq *req = (xGLXCreatePixmapReq *) pc;
+ CARD32 *attribs;
+ __GLX_DECLARE_SWAP_VARIABLES;
+ __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
+
++ REQUEST_AT_LEAST_SIZE(xGLXCreatePixmapReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->screen);
+ __GLX_SWAP_INT(&req->fbconfig);
+ __GLX_SWAP_INT(&req->pixmap);
+ __GLX_SWAP_INT(&req->glxpixmap);
+ __GLX_SWAP_INT(&req->numAttribs);
++
++ REQUEST_FIXED_SIZE(xGLXCreatePixmapReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs);
+
+@@ -276,10 +329,13 @@ int __glXDispSwap_CreatePixmap(__GLXclie
+
+ int __glXDispSwap_CreateGLXPixmapWithConfigSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateGLXPixmapWithConfigSGIXReq *req =
+ (xGLXCreateGLXPixmapWithConfigSGIXReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXCreateGLXPixmapWithConfigSGIXReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->screen);
+ __GLX_SWAP_INT(&req->fbconfig);
+@@ -291,9 +347,12 @@ int __glXDispSwap_CreateGLXPixmapWithCon
+
+ int __glXDispSwap_DestroyGLXPixmap(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXDestroyGLXPixmapReq *req = (xGLXDestroyGLXPixmapReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXDestroyGLXPixmapReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->glxpixmap);
+
+@@ -302,9 +361,12 @@ int __glXDispSwap_DestroyGLXPixmap(__GLX
+
+ int __glXDispSwap_DestroyPixmap(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXDestroyGLXPixmapReq *req = (xGLXDestroyGLXPixmapReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXDestroyGLXPixmapReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->glxpixmap);
+
+@@ -313,9 +375,12 @@ int __glXDispSwap_DestroyPixmap(__GLXcli
+
+ int __glXDispSwap_QueryContext(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXQueryContextReq *req = (xGLXQueryContextReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXQueryContextReq);
++
+ __GLX_SWAP_INT(&req->context);
+
+ return __glXDisp_QueryContext(cl, pc);
+@@ -323,15 +388,20 @@ int __glXDispSwap_QueryContext(__GLXclie
+
+ int __glXDispSwap_CreatePbuffer(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreatePbufferReq *req = (xGLXCreatePbufferReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+ __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
+ CARD32 *attribs;
+
++ REQUEST_AT_LEAST_SIZE(xGLXCreatePbufferReq);
++
+ __GLX_SWAP_INT(&req->screen);
+ __GLX_SWAP_INT(&req->fbconfig);
+ __GLX_SWAP_INT(&req->pbuffer);
+ __GLX_SWAP_INT(&req->numAttribs);
++
++ REQUEST_FIXED_SIZE(xGLXCreatePbufferReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs);
+
+@@ -340,9 +410,12 @@ int __glXDispSwap_CreatePbuffer(__GLXcli
+
+ int __glXDispSwap_CreateGLXPbufferSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateGLXPbufferSGIXReq *req = (xGLXCreateGLXPbufferSGIXReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXCreateGLXPbufferSGIXReq);
++
+ __GLX_SWAP_INT(&req->screen);
+ __GLX_SWAP_INT(&req->fbconfig);
+ __GLX_SWAP_INT(&req->pbuffer);
+@@ -354,9 +427,12 @@ int __glXDispSwap_CreateGLXPbufferSGIX(_
+
+ int __glXDispSwap_DestroyPbuffer(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXDestroyPbufferReq *req = (xGLXDestroyPbufferReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXDestroyPbufferReq);
++
+ __GLX_SWAP_INT(&req->pbuffer);
+
+ return __glXDisp_DestroyPbuffer(cl, pc);
+@@ -366,22 +442,31 @@ int __glXDispSwap_DestroyGLXPbufferSGIX(
+ {
+ xGLXDestroyGLXPbufferSGIXReq *req = (xGLXDestroyGLXPbufferSGIXReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
++ ClientPtr client = cl->client;
+
+ __GLX_SWAP_INT(&req->pbuffer);
+
++ REQUEST_SIZE_MATCH(xGLXDestroyPbufferReq);
++
++ __GLX_SWAP_INT(&req->pbuffer);
+ return __glXDisp_DestroyGLXPbufferSGIX(cl, pc);
+ }
+
+ int __glXDispSwap_ChangeDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXChangeDrawableAttributesReq *req =
+ (xGLXChangeDrawableAttributesReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+ __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
+ CARD32 *attribs;
+
++ REQUEST_AT_LEAST_SIZE(xGLXChangeDrawableAttributesReq);
++
+ __GLX_SWAP_INT(&req->drawable);
+ __GLX_SWAP_INT(&req->numAttribs);
++
++ REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs);
+
+@@ -391,14 +476,19 @@ int __glXDispSwap_ChangeDrawableAttribut
+ int __glXDispSwap_ChangeDrawableAttributesSGIX(__GLXclientState *cl,
+ GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXChangeDrawableAttributesSGIXReq *req =
+ (xGLXChangeDrawableAttributesSGIXReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+ __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
+ CARD32 *attribs;
+
++ REQUEST_AT_LEAST_SIZE(xGLXChangeDrawableAttributesSGIXReq);
++
+ __GLX_SWAP_INT(&req->drawable);
+ __GLX_SWAP_INT(&req->numAttribs);
++
++ REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesSGIXReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs);
+
+@@ -407,16 +497,21 @@ int __glXDispSwap_ChangeDrawableAttribut
+
+ int __glXDispSwap_CreateWindow(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXCreateWindowReq *req = (xGLXCreateWindowReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+ __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
+ CARD32 *attribs;
+
++ REQUEST_AT_LEAST_SIZE(xGLXCreateWindowReq);
++
+ __GLX_SWAP_INT(&req->screen);
+ __GLX_SWAP_INT(&req->fbconfig);
+ __GLX_SWAP_INT(&req->window);
+ __GLX_SWAP_INT(&req->glxwindow);
+ __GLX_SWAP_INT(&req->numAttribs);
++
++ REQUEST_FIXED_SIZE(xGLXCreateWindowReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs);
+
+@@ -425,9 +520,12 @@ int __glXDispSwap_CreateWindow(__GLXclie
+
+ int __glXDispSwap_DestroyWindow(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXDestroyWindowReq *req = (xGLXDestroyWindowReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXDestroyWindowReq);
++
+ __GLX_SWAP_INT(&req->glxwindow);
+
+ return __glXDisp_DestroyWindow(cl, pc);
+@@ -435,9 +533,12 @@ int __glXDispSwap_DestroyWindow(__GLXcli
+
+ int __glXDispSwap_SwapBuffers(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXSwapBuffersReq *req = (xGLXSwapBuffersReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXSwapBuffersReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->contextTag);
+ __GLX_SWAP_INT(&req->drawable);
+@@ -447,9 +548,12 @@ int __glXDispSwap_SwapBuffers(__GLXclien
+
+ int __glXDispSwap_UseXFont(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXUseXFontReq *req = (xGLXUseXFontReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXUseXFontReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->contextTag);
+ __GLX_SWAP_INT(&req->font);
+@@ -463,9 +567,12 @@ int __glXDispSwap_UseXFont(__GLXclientSt
+
+ int __glXDispSwap_QueryExtensionsString(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXQueryExtensionsStringReq *req = (xGLXQueryExtensionsStringReq *)pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXQueryExtensionsStringReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->screen);
+
+@@ -474,9 +581,12 @@ int __glXDispSwap_QueryExtensionsString(
+
+ int __glXDispSwap_QueryServerString(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXQueryServerStringReq *req = (xGLXQueryServerStringReq *)pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXQueryServerStringReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->screen);
+ __GLX_SWAP_INT(&req->name);
+@@ -486,9 +596,12 @@ int __glXDispSwap_QueryServerString(__GL
+
+ int __glXDispSwap_ClientInfo(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXClientInfoReq *req = (xGLXClientInfoReq *)pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_AT_LEAST_SIZE(xGLXClientInfoReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->major);
+ __GLX_SWAP_INT(&req->minor);
+@@ -499,9 +612,12 @@ int __glXDispSwap_ClientInfo(__GLXclient
+
+ int __glXDispSwap_QueryContextInfoEXT(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXQueryContextInfoEXTReq *req = (xGLXQueryContextInfoEXTReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXQueryContextInfoEXTReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->context);
+
+@@ -510,12 +626,14 @@ int __glXDispSwap_QueryContextInfoEXT(__
+
+ int __glXDispSwap_BindTexImageEXT(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
+ GLXDrawable *drawId;
+ int *buffer;
+-
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 8);
++
+ pc += __GLX_VENDPRIV_HDR_SIZE;
+
+ drawId = ((GLXDrawable *) (pc));
+@@ -531,12 +649,14 @@ int __glXDispSwap_BindTexImageEXT(__GLXc
+
+ int __glXDispSwap_ReleaseTexImageEXT(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
+ GLXDrawable *drawId;
+ int *buffer;
+-
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 8);
++
+ pc += __GLX_VENDPRIV_HDR_SIZE;
+
+ drawId = ((GLXDrawable *) (pc));
+@@ -552,12 +672,14 @@ int __glXDispSwap_ReleaseTexImageEXT(__G
+
+ int __glXDispSwap_CopySubBufferMESA(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
+ GLXDrawable *drawId;
+ int *buffer;
+-
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 20);
++
+ (void) drawId;
+ (void) buffer;
+
+@@ -577,11 +699,13 @@ int __glXDispSwap_CopySubBufferMESA(__GL
+
+ int __glXDispSwap_GetDrawableAttributesSGIX(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXVendorPrivateWithReplyReq *req = (xGLXVendorPrivateWithReplyReq *)pc;
+ CARD32 *data;
+-
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXGetDrawableAttributesSGIXReq);
++
+ data = (CARD32 *) (req + 1);
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->contextTag);
+@@ -592,10 +716,12 @@ int __glXDispSwap_GetDrawableAttributesS
+
+ int __glXDispSwap_GetDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
+ {
++ ClientPtr client = cl->client;
+ xGLXGetDrawableAttributesReq *req = (xGLXGetDrawableAttributesReq *)pc;
+-
+ __GLX_DECLARE_SWAP_VARIABLES;
+
++ REQUEST_SIZE_MATCH(xGLXGetDrawableAttributesReq);
++
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->drawable);
+
--- /dev/null
+From: Julien Cristau <jcristau@debian.org>
+Date: Sun Aug 22 16:20:45 2010 +0100
+Subject: [PATCH] glx: swap the request arrays entirely, not just half of them
+Patch-Mainline: Upstream
+Git-commit: 62319e8381ebd645ae36b25e5fc3c0e9b098387b
+References: bnc #648278, CVE-2010-4818
+Signed-off-by: Egbert Eich <eich@suse.de>
+
+Various glx requests include a list of pairs of attributes. We were
+only swapping the first half.
+
+Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
+Reviewed-by: Daniel Stone <daniel@fooishbar.org>
+Signed-off-by: Julien Cristau <jcristau@debian.org>
+---
+ glx/glxcmdsswap.c | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+--- xorg-server-1.6.5.orig/glx/glxcmdsswap.c
++++ xorg-server-1.6.5/glx/glxcmdsswap.c
+@@ -324,7 +324,7 @@ int __glXDispSwap_CreatePixmap(__GLXclie
+
+ REQUEST_FIXED_SIZE(xGLXCreatePixmapReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+- __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs);
++ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs << 1);
+
+ return __glXDisp_CreatePixmap(cl, pc);
+ }
+@@ -405,7 +405,7 @@ int __glXDispSwap_CreatePbuffer(__GLXcli
+
+ REQUEST_FIXED_SIZE(xGLXCreatePbufferReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+- __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs);
++ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs << 1);
+
+ return __glXDisp_CreatePbuffer(cl, pc);
+ }
+@@ -470,7 +470,7 @@ int __glXDispSwap_ChangeDrawableAttribut
+
+ REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+- __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs);
++ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs << 1);
+
+ return __glXDisp_ChangeDrawableAttributes(cl, pc);
+ }
+@@ -492,7 +492,7 @@ int __glXDispSwap_ChangeDrawableAttribut
+
+ REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesSGIXReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+- __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs);
++ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs << 1);
+
+ return __glXDisp_ChangeDrawableAttributesSGIX(cl, pc);
+ }
+@@ -515,7 +515,7 @@ int __glXDispSwap_CreateWindow(__GLXclie
+
+ REQUEST_FIXED_SIZE(xGLXCreateWindowReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+- __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs);
++ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs << 1);
+
+ return __glXDisp_CreateWindow(cl, pc);
+ }
--- /dev/null
+From: Julien Cristau <jcristau@debian.org>
+Date: Wed Nov 10 22:39:54 2010 +0100
+Subject: [PATCH] glx: validate numAttribs field before using it
+Patch-Mainline: Upstream
+Git-commit: d9225b9602c85603ae616a7381c784f5cf5e811c
+References: bnc #648278, CVE-2010-4818
+Signed-off-by: Egbert Eich <eich@suse.de>
+
+Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
+Reviewed-by: Daniel Stone <daniel@fooishbar.org>
+Signed-off-by: Julien Cristau <jcristau@debian.org>
+
+--- xorg-server-1.6.5.orig/glx/glxcmdsswap.c
++++ xorg-server-1.6.5/glx/glxcmdsswap.c
+@@ -322,6 +322,10 @@ int __glXDispSwap_CreatePixmap(__GLXclie
+ __GLX_SWAP_INT(&req->glxpixmap);
+ __GLX_SWAP_INT(&req->numAttribs);
+
++ if (req->numAttribs > (UINT32_MAX >> 3)) {
++ client->errorValue = req->numAttribs;
++ return BadValue;
++ }
+ REQUEST_FIXED_SIZE(xGLXCreatePixmapReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs << 1);
+@@ -403,6 +407,10 @@ int __glXDispSwap_CreatePbuffer(__GLXcli
+ __GLX_SWAP_INT(&req->pbuffer);
+ __GLX_SWAP_INT(&req->numAttribs);
+
++ if (req->numAttribs > (UINT32_MAX >> 3)) {
++ client->errorValue = req->numAttribs;
++ return BadValue;
++ }
+ REQUEST_FIXED_SIZE(xGLXCreatePbufferReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs << 1);
+@@ -468,6 +476,10 @@ int __glXDispSwap_ChangeDrawableAttribut
+ __GLX_SWAP_INT(&req->drawable);
+ __GLX_SWAP_INT(&req->numAttribs);
+
++ if (req->numAttribs > (UINT32_MAX >> 3)) {
++ client->errorValue = req->numAttribs;
++ return BadValue;
++ }
+ REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs << 1);
+@@ -490,6 +502,10 @@ int __glXDispSwap_ChangeDrawableAttribut
+ __GLX_SWAP_INT(&req->drawable);
+ __GLX_SWAP_INT(&req->numAttribs);
+
++ if (req->numAttribs > (UINT32_MAX >> 3)) {
++ client->errorValue = req->numAttribs;
++ return BadValue;
++ }
+ REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesSGIXReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs << 1);
+@@ -513,6 +529,10 @@ int __glXDispSwap_CreateWindow(__GLXclie
+ __GLX_SWAP_INT(&req->glxwindow);
+ __GLX_SWAP_INT(&req->numAttribs);
+
++ if (req->numAttribs > (UINT32_MAX >> 3)) {
++ client->errorValue = req->numAttribs;
++ return BadValue;
++ }
+ REQUEST_FIXED_SIZE(xGLXCreateWindowReq, req->numAttribs << 3);
+ attribs = (CARD32*)(req + 1);
+ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs << 1);
+--- xorg-server-1.9.3/glx/glxcmds.c.orig 2012-02-06 15:24:13.000000000 +0100
++++ xorg-server-1.9.3/glx/glxcmds.c 2012-02-06 15:26:23.000000000 +0100
+@@ -1285,6 +1285,11 @@ int __glXDisp_CreatePixmap(__GLXclientSt
+ __GLXscreen *pGlxScreen;
+ int err;
+
++ REQUEST_AT_LEAST_SIZE(xGLXCreatePixmapReq);
++ if (req->numAttribs > (UINT32_MAX >> 3)) {
++ client->errorValue = req->numAttribs;
++ return BadValue;
++ }
+ REQUEST_FIXED_SIZE(xGLXCreatePixmapReq, req->numAttribs << 3);
+
+ if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
+@@ -1398,6 +1403,11 @@ int __glXDisp_CreatePbuffer(__GLXclientS
+ CARD32 *attrs;
+ int width, height, i;
+
++ REQUEST_AT_LEAST_SIZE(xGLXCreatePbufferReq);
++ if (req->numAttribs > (UINT32_MAX >> 3)) {
++ client->errorValue = req->numAttribs;
++ return BadValue;
++ }
+ REQUEST_FIXED_SIZE(xGLXCreatePbufferReq, req->numAttribs << 3);
+
+ attrs = (CARD32 *) (req + 1);
+@@ -1485,6 +1495,11 @@ int __glXDisp_ChangeDrawableAttributes(_
+ xGLXChangeDrawableAttributesReq *req =
+ (xGLXChangeDrawableAttributesReq *) pc;
+
++ REQUEST_AT_LEAST_SIZE(xGLXChangeDrawableAttributesReq);
++ if (req->numAttribs > (UINT32_MAX >> 3)) {
++ client->errorValue = req->numAttribs;
++ return BadValue;
++ }
+ REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesReq, req->numAttribs << 3);
+
+ return DoChangeDrawableAttributes(cl->client, req->drawable,
+@@ -1497,6 +1512,11 @@ int __glXDisp_ChangeDrawableAttributesSG
+ xGLXChangeDrawableAttributesSGIXReq *req =
+ (xGLXChangeDrawableAttributesSGIXReq *)pc;
+
++ REQUEST_AT_LEAST_SIZE(xGLXChangeDrawableAttributesSGIXReq);
++ if (req->numAttribs > (UINT32_MAX >> 3)) {
++ client->errorValue = req->numAttribs;
++ return BadValue;
++ }
+ REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesSGIXReq, req->numAttribs << 3);
+
+ return DoChangeDrawableAttributes(cl->client, req->drawable,
+@@ -1512,6 +1532,11 @@ int __glXDisp_CreateWindow(__GLXclientSt
+ DrawablePtr pDraw;
+ int err;
+
++ REQUEST_AT_LEAST_SIZE(xGLXCreateWindowReq);
++ if (req->numAttribs > (UINT32_MAX >> 3)) {
++ client->errorValue = req->numAttribs;
++ return BadValue;
++ }
+ REQUEST_FIXED_SIZE(xGLXCreateWindowReq, req->numAttribs << 3);
+
+ LEGAL_NEW_RESOURCE(req->glxwindow, client);
--- /dev/null
+From: Julien Cristau <jcristau@debian.org>
+Date: Sun Jan 23 17:05:26 2011 +0100
+Subject: [PATCH] glx: fix request length check for CreateGLXPbufferSGIX
+Patch-Mainline: Upstream
+Git-commit: a883cf1545abd89bb2cadfa659718884b56fd234
+References: bnc #648278, CVE-2010-4818
+Signed-off-by: Egbert Eich <eich@suse.de>
+
+The request is followed by an attribute list.
+
+Signed-off-by: Julien Cristau <jcristau@debian.org>
+Reviewed-by: Adam Jackson <ajax@redhat.com>
+---
+ glx/glxcmds.c | 2 +-
+ glx/glxcmdsswap.c | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+--- xorg-server-1.6.5.orig/glx/glxcmds.c
++++ xorg-server-1.6.5/glx/glxcmds.c
+@@ -1411,7 +1411,7 @@ int __glXDisp_CreateGLXPbufferSGIX(__GLX
+ ClientPtr client = cl->client;
+ xGLXCreateGLXPbufferSGIXReq *req = (xGLXCreateGLXPbufferSGIXReq *) pc;
+
+- REQUEST_SIZE_MATCH(xGLXCreateGLXPbufferSGIXReq);
++ REQUEST_AT_LEAST_SIZE(xGLXCreateGLXPbufferSGIXReq);
+
+ return DoCreatePbuffer(cl->client, req->screen, req->fbconfig,
+ req->width, req->height, req->pbuffer);
+--- xorg-server-1.6.5.orig/glx/glxcmdsswap.c
++++ xorg-server-1.6.5/glx/glxcmdsswap.c
+@@ -424,7 +424,7 @@ int __glXDispSwap_CreateGLXPbufferSGIX(_
+ xGLXCreateGLXPbufferSGIXReq *req = (xGLXCreateGLXPbufferSGIXReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
+- REQUEST_SIZE_MATCH(xGLXCreateGLXPbufferSGIXReq);
++ REQUEST_AT_LEAST_SIZE(xGLXCreateGLXPbufferSGIXReq);
+
+ __GLX_SWAP_INT(&req->screen);
+ __GLX_SWAP_INT(&req->fbconfig);
--- /dev/null
+From: Julien Cristau <jcristau@debian.org>
+Date: Wed Jan 26 13:06:53 2011 +0100
+Subject: [PATCH] glx: fix BindTexImageEXT length check
+Patch-Mainline: Upstream
+Git-commit: 1137c11be0f82049d28024eaf963c6f76e0d4334
+References: bnc #648278, CVE-2010-4818
+Signed-off-by: Egbert Eich <eich@suse.de>
+
+The request is followed by a list of attributes.
+
+X.Org bug#33449
+
+Reported-and-tested-by: meng <mengmeng.meng@intel.com>
+Signed-off-by: Julien Cristau <jcristau@debian.org>
+Reviewed-by: Adam Jackson <ajax@redhat.com>
+---
+ glx/glxcmds.c | 10 +++++++++-
+ glx/glxcmdsswap.c | 6 +++++-
+ 2 files changed, 14 insertions(+), 2 deletions(-)
+
+--- xorg-server-1.6.5.orig/glx/glxcmds.c
++++ xorg-server-1.6.5/glx/glxcmds.c
+@@ -1668,13 +1668,21 @@ int __glXDisp_BindTexImageEXT(__GLXclien
+ GLXDrawable drawId;
+ int buffer;
+ int error;
++ CARD32 num_attribs;
+
+- REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 8);
++ if ((sizeof(xGLXVendorPrivateReq) + 12) >> 2 > client->req_len)
++ return BadLength;
+
+ pc += __GLX_VENDPRIV_HDR_SIZE;
+
+ drawId = *((CARD32 *) (pc));
+ buffer = *((INT32 *) (pc + 4));
++ num_attribs = *((CARD32 *) (pc + 8));
++ if (num_attribs > (UINT32_MAX >> 3)) {
++ client->errorValue = num_attribs;
++ return BadValue;
++ }
++ REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 12 + (num_attribs << 3));
+
+ if (buffer != GLX_FRONT_LEFT_EXT)
+ return __glXError(GLXBadPixmap);
+--- xorg-server-1.6.5.orig/glx/glxcmdsswap.c
++++ xorg-server-1.6.5/glx/glxcmdsswap.c
+@@ -652,19 +652,23 @@ int __glXDispSwap_BindTexImageEXT(__GLXc
+ xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc;
+ GLXDrawable *drawId;
+ int *buffer;
++ CARD32 *num_attribs;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
+- REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 8);
++ if ((sizeof(xGLXVendorPrivateReq) + 12) >> 2 > client->req_len)
++ return BadLength;
+
+ pc += __GLX_VENDPRIV_HDR_SIZE;
+
+ drawId = ((GLXDrawable *) (pc));
+ buffer = ((int *) (pc + 4));
++ num_attribs = ((CARD32 *) (pc + 8));
+
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->contextTag);
+ __GLX_SWAP_INT(drawId);
+ __GLX_SWAP_INT(buffer);
++ __GLX_SWAP_INT(num_attribs);
+
+ return __glXDisp_BindTexImageEXT(cl, (GLbyte *)pc);
+ }
--- /dev/null
+From: Julien Cristau <jcristau@debian.org>
+Date: Sun Jan 23 13:35:54 2011 +0100
+Subject: [PATCH] glx: Work around wrong request lengths sent by mesa
+Patch-Mainline: Upstream
+Git-commit: 402b329c3aa8ddbebaa1f593306a02d4cd6fed26
+References: bnc #648278, CVE-2010-4818
+Signed-off-by: Egbert Eich <eich@suse.de>
+
+mesa used to send too long requests for GLXDestroyPixmap,
+GLXDestroyWindow, GLXChangeDrawableAttributes, GLXGetDrawableAttributes
+and GLXGetFBConfigsSGIX.
+
+Fixes a regression introduced in ec9c97c6bf70b523bc500bd3adf62176f1bb33a4
+X.Org bug#33324 <https://bugs.freedesktop.org/show_bug.cgi?id=33324>
+
+Reported-by: xunx.fang@intel.com
+Signed-off-by: Julien Cristau <jcristau@debian.org>
+Reviewed-by: Adam Jackson <ajax@redhat.com>
+---
+ glx/glxcmds.c | 19 +++++++++++++++----
+ glx/glxcmdsswap.c | 12 +++++++-----
+ 2 files changed, 22 insertions(+), 9 deletions(-)
+
+--- xorg-server-1.6.5.orig/glx/glxcmds.c
++++ xorg-server-1.6.5/glx/glxcmds.c
+@@ -1113,7 +1113,8 @@ int __glXDisp_GetFBConfigsSGIX(__GLXclie
+ {
+ ClientPtr client = cl->client;
+ xGLXGetFBConfigsSGIXReq *req = (xGLXGetFBConfigsSGIXReq *) pc;
+- REQUEST_SIZE_MATCH(xGLXGetFBConfigsSGIXReq);
++ /* work around mesa bug, don't use REQUEST_SIZE_MATCH */
++ REQUEST_AT_LEAST_SIZE(xGLXGetFBConfigsSGIXReq);
+ return DoGetFBConfigs(cl, req->screen);
+ }
+
+@@ -1341,7 +1342,9 @@ int __glXDisp_DestroyPixmap(__GLXclientS
+ ClientPtr client = cl->client;
+ xGLXDestroyPixmapReq *req = (xGLXDestroyPixmapReq *) pc;
+
+- REQUEST_SIZE_MATCH(xGLXDestroyPixmapReq);
++ /* should be REQUEST_SIZE_MATCH, but mesa's glXDestroyPixmap used to set
++ * length to 3 instead of 2 */
++ REQUEST_AT_LEAST_SIZE(xGLXDestroyPixmapReq);
+
+ return DoDestroyDrawable(cl, req->glxpixmap, GLX_DRAWABLE_PIXMAP);
+ }
+@@ -1470,7 +1473,13 @@ int __glXDisp_ChangeDrawableAttributes(_
+ client->errorValue = req->numAttribs;
+ return BadValue;
+ }
++#if 0
++ /* mesa sends an additional 8 bytes */
+ REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesReq, req->numAttribs << 3);
++#else
++ if (((sizeof(xGLXChangeDrawableAttributesReq) + (req->numAttribs << 3)) >> 2) < client->req_len)
++ return BadLength;
++#endif
+
+ return DoChangeDrawableAttributes(cl->client, req->drawable,
+ req->numAttribs, (CARD32 *) (req + 1));
+@@ -1532,7 +1541,8 @@ int __glXDisp_DestroyWindow(__GLXclientS
+ ClientPtr client = cl->client;
+ xGLXDestroyWindowReq *req = (xGLXDestroyWindowReq *) pc;
+
+- REQUEST_SIZE_MATCH(xGLXDestroyWindowReq);
++ /* mesa's glXDestroyWindow used to set length to 3 instead of 2 */
++ REQUEST_AT_LEAST_SIZE(xGLXDestroyWindowReq);
+
+ return DoDestroyDrawable(cl, req->glxwindow, GLX_DRAWABLE_WINDOW);
+ }
+@@ -1849,7 +1859,8 @@ int __glXDisp_GetDrawableAttributes(__GL
+ ClientPtr client = cl->client;
+ xGLXGetDrawableAttributesReq *req = (xGLXGetDrawableAttributesReq *)pc;
+
+- REQUEST_SIZE_MATCH(xGLXGetDrawableAttributesReq);
++ /* this should be REQUEST_SIZE_MATCH, but mesa sends an additional 4 bytes */
++ REQUEST_AT_LEAST_SIZE(xGLXGetDrawableAttributesReq);
+
+ return DoGetDrawableAttributes(cl, req->drawable);
+ }
+--- xorg-server-1.6.5.orig/glx/glxcmdsswap.c
++++ xorg-server-1.6.5/glx/glxcmdsswap.c
+@@ -282,7 +282,7 @@ int __glXDispSwap_GetFBConfigsSGIX(__GLX
+ xGLXGetFBConfigsSGIXReq *req = (xGLXGetFBConfigsSGIXReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
+- REQUEST_SIZE_MATCH(xGLXGetFBConfigsSGIXReq);
++ REQUEST_AT_LEAST_SIZE(xGLXGetFBConfigsSGIXReq);
+
+ __GLX_SWAP_INT(&req->screen);
+ return __glXDisp_GetFBConfigsSGIX(cl, pc);
+@@ -371,7 +371,7 @@ int __glXDispSwap_DestroyPixmap(__GLXcli
+ xGLXDestroyGLXPixmapReq *req = (xGLXDestroyGLXPixmapReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
+- REQUEST_SIZE_MATCH(xGLXDestroyGLXPixmapReq);
++ REQUEST_AT_LEAST_SIZE(xGLXDestroyGLXPixmapReq);
+
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->glxpixmap);
+@@ -480,7 +480,9 @@ int __glXDispSwap_ChangeDrawableAttribut
+ client->errorValue = req->numAttribs;
+ return BadValue;
+ }
+- REQUEST_FIXED_SIZE(xGLXChangeDrawableAttributesReq, req->numAttribs << 3);
++ if (((sizeof(xGLXChangeDrawableAttributesReq) + (req->numAttribs << 3)) >> 2) < client->req_len)
++ return BadLength;
++
+ attribs = (CARD32*)(req + 1);
+ __GLX_SWAP_INT_ARRAY(attribs, req->numAttribs << 1);
+
+@@ -546,7 +548,7 @@ int __glXDispSwap_DestroyWindow(__GLXcli
+ xGLXDestroyWindowReq *req = (xGLXDestroyWindowReq *) pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
+- REQUEST_SIZE_MATCH(xGLXDestroyWindowReq);
++ REQUEST_AT_LEAST_SIZE(xGLXDestroyWindowReq);
+
+ __GLX_SWAP_INT(&req->glxwindow);
+
+@@ -746,7 +748,7 @@ int __glXDispSwap_GetDrawableAttributes(
+ xGLXGetDrawableAttributesReq *req = (xGLXGetDrawableAttributesReq *)pc;
+ __GLX_DECLARE_SWAP_VARIABLES;
+
+- REQUEST_SIZE_MATCH(xGLXGetDrawableAttributesReq);
++ REQUEST_AT_LEAST_SIZE(xGLXGetDrawableAttributesReq);
+
+ __GLX_SWAP_SHORT(&req->length);
+ __GLX_SWAP_INT(&req->drawable);
--- /dev/null
+--- xorg-server-1.9.3/os/io.c 2010-11-23 20:07:18.000000000 +0100
++++ xorg-server-1.9.3.new/os/io.c 2013-07-03 16:07:37.283509815 +0200
+@@ -1108,6 +1108,7 @@
+ oci->bufptr = oci->buffer;
+ oci->bufcnt = 0;
+ oci->lenLastReq = 0;
++ oci->ignoreBytes = 0;
+ }
+ }
+ if ((oco = oc->output))
--- /dev/null
+From 6ca03b9161d33b1d2b55a3a1a913cf88deb2343f Mon Sep 17 00:00:00 2001
+From: Dave Airlie <airlied@gmail.com>
+Date: Wed, 10 Apr 2013 16:09:01 +1000
+Subject: [PATCH] xf86: fix flush input to work with Linux evdev devices.
+
+So when we VT switch back and attempt to flush the input devices,
+we don't succeed because evdev won't return part of an event,
+since we were only asking for 4 bytes, we'd only get -EINVAL back.
+
+This could later cause events to be flushed that we shouldn't have
+gotten.
+
+This is a fix for CVE-2013-1940.
+
+Signed-off-by: Dave Airlie <airlied@redhat.com>
+Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
+Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
+---
+ hw/xfree86/os-support/shared/posix_tty.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/hw/xfree86/os-support/shared/posix_tty.c b/hw/xfree86/os-support/shared/posix_tty.c
+index ab3757a..4d08c1e 100644
+--- a/hw/xfree86/os-support/shared/posix_tty.c
++++ b/hw/xfree86/os-support/shared/posix_tty.c
+@@ -460,7 +460,8 @@ xf86FlushInput(int fd)
+ {
+ fd_set fds;
+ struct timeval timeout;
+- char c[4];
++ /* this needs to be big enough to flush an evdev event. */
++ char c[256];
+
+ DebugF("FlushingSerial\n");
+ if (tcflush(fd, TCIFLUSH) == 0)
+--
+1.8.1.4
--- /dev/null
+From bb4e768eaf8025d3ccf369cbad9a9b8be721e7ac Mon Sep 17 00:00:00 2001
+From: Matthias Hopf <mhopf@suse.de>
+Date: Wed, 25 Aug 2010 14:12:48 +0200
+Subject: [PATCH] Use external tool for creating backtraces on crashes if available.
+
+This calls /usr/bin/xorg-backtrace to create reasonable commented backtraces
+with gdb. On errors it falls back to the generic method.
+
+Signed-off-by: Matthias Hopf <mhopf@suse.de>
+---
+ os/backtrace.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 1 files changed, 82 insertions(+), 0 deletions(-)
+
+diff --git a/os/backtrace.c b/os/backtrace.c
+index 7ca6dab..1e3201a 100644
+--- a/os/backtrace.c
++++ b/os/backtrace.c
+@@ -28,6 +28,81 @@
+ #include "os.h"
+ #include "misc.h"
+
++#include <sys/types.h>
++#include <sys/wait.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <unistd.h>
++#include <errno.h>
++
++#define XORG_BACKTRACE "/usr/bin/xorg-backtrace"
++
++/* Call gdb to create reasonable(!) backtrace. Returns 0 if successfull. */
++static int xorg_backtrace_gdb(void)
++{
++ static const char *xorg_backtrace = XORG_BACKTRACE;
++ char pidstr[12];
++ char fdname[] = "/tmp/xorg.XXXXXX";
++ char buf[256];
++ pid_t pid;
++ int fd, status = -1, ret;
++ FILE *f;
++
++ if (access (xorg_backtrace, R_OK | X_OK) != 0) {
++ ErrorF ("%s not found, using internal backtrace system\n", xorg_backtrace);
++ return 1;
++ }
++ if ( (fd = mkstemp (fdname)) == -1) {
++ ErrorF ("xorg_backtrace_gdb internal error 1\n");
++ return 1;
++ }
++ unlink (fdname);
++ snprintf (pidstr, 12, "%d", getpid());
++
++ switch ( (pid = fork()) ) {
++ case 0:
++ close (0);
++ close (1);
++ close (2);
++ dup2 (fd, 1);
++ dup2 (fd, 2);
++ close (fd);
++ execl (xorg_backtrace, xorg_backtrace, pidstr, NULL);
++ exit (-1);
++ case -1:
++ close (fd);
++ return 1;
++ }
++
++ while (waitpid (pid, &status, 0) == -1 && errno == EINTR)
++ ;
++ if (WIFEXITED (status) && WEXITSTATUS (status) == 0)
++ ret = 0;
++ else {
++ ErrorF ("%s failed with returncode %d\n", xorg_backtrace, WEXITSTATUS (status));
++ ret = 1;
++ }
++
++ lseek (fd, 0, SEEK_SET);
++ if (! (f = fdopen (fd, "r"))) {
++ ErrorF ("xorg_backtrace_gdb internal error 2\n");
++ close (fd);
++ return 1;
++ }
++ status = 0;
++ while (fgets (buf, 256, f)) {
++ status++;
++ ErrorF("%s", buf);
++ }
++ fclose (f);
++ if (status < 10 && ret == 0) {
++ ErrorF ("%s only produced %d lines of output\n", xorg_backtrace, status);
++ return 1;
++ }
++
++ return ret;
++}
++
+ #ifdef HAVE_BACKTRACE
+ #ifndef _GNU_SOURCE
+ #define _GNU_SOURCE
+@@ -41,6 +116,10 @@ void xorg_backtrace(void)
+ const char *mod;
+ int size, i;
+ Dl_info info;
++
++ if (xorg_backtrace_gdb () == 0)
++ return;
++
+ ErrorF("\nBacktrace:\n");
+ size = backtrace(array, 64);
+ for (i = 0; i < size; i++) {
+@@ -182,6 +261,9 @@ static int xorg_backtrace_pstack(void) {
+
+ void xorg_backtrace(void) {
+
++ if (xorg_backtrace_gdb () == 0)
++ return;
++
+ ErrorF("\nBacktrace:\n");
+
+ # ifdef HAVE_PSTACK
+--
+1.6.0.2
+
--- /dev/null
+Index: hw/xfree86/common/xf86AutoConfig.c
+================================================================================
+--- hw/xfree86/common/xf86AutoConfig.c
++++ hw/xfree86/common/xf86AutoConfig.c
+@@ -506,7 +506,7 @@
+ /* Fallback to platform default hardware */
+ if (i < (nmatches - 1)) {
+ #if defined(__i386__) || defined(__amd64__) || defined(__hurd__)
+- matches[i++] = xnfstrdup("vesa");
++ matches[i++] = xnfstrdup("fbdev");
+ #elif defined(__sparc__) && !defined(sun)
+ matches[i++] = xnfstrdup("sunffb");
+ #endif
+@@ -517,7 +517,7 @@
+ #if !defined(__linux__) && defined(__sparc__)
+ matches[i++] = xnfstrdup("wsfb");
+ #else
+- matches[i++] = xnfstrdup("fbdev");
++ matches[i++] = xnfstrdup("vesa");
+ #endif
+ }
+ }
--- /dev/null
+From 107688407c7ebc71323dc1203ed5b92276026e1e Mon Sep 17 00:00:00 2001
+From: Luc Verhaegen <libv@skynet.be>
+Date: Wed, 2 Apr 2008 20:09:26 +0200
+Subject: [PATCH] Default bitmap fonts should typically be set as unscaled.
+
+It is generally not desired to have bitmap fonts scale. Even so
+DEFAULT_FONT_PATH had the misc, 100dpi and 75dpi paths without the
+:unscaled specifier.
+
+Now the default font path has this per default, xorgconfig and
+--configure will only use these as :unscaled too.
+
+Since SUSE has been specifying :unscaled for its bitmap fonts for
+about a decade or so, and since adding the default font path to the
+.conf fontpath was only introduced a year ago, this lack of scaled
+bitmap fonts will not have any new side-effects.
+
+Reported by Mike Fabian, debugged and fixed with the help of Mike
+Fabian and Stefan Dirsch.
+================================================================================
+--- xorg-server-1.7.99/configure.ac
++++ xorg-server-1.7.99/configure.ac
+@@ -509,7 +509,7 @@
+ dnl Uses --default-font-path if set, otherwise checks for /etc/X11/fontpath.d,
+ dnl otherwise uses standard subdirectories of FONTROOTDIR. When cross
+ dnl compiling, assume default font path uses standard FONTROOTDIR directories.
+-DEFAULT_FONT_PATH="${FONTMISCDIR}/,${FONTTTFDIR}/,${FONTOTFDIR}/,${FONTTYPE1DIR}/,${FONT100DPIDIR}/,${FONT75DPIDIR}/"
++DEFAULT_FONT_PATH="${FONTMISCDIR}:unscaled,${FONTTTFDIR}/,${FONTOTFDIR}/,${FONTTYPE1DIR}/,${FONT100DPIDIR}/,${FONT75DPIDIR}/"
+ if test "$cross_compiling" != yes; then
+ AC_CHECK_FILE([${sysconfdir}/X11/fontpath.d],
+ [DEFAULT_FONT_PATH='catalogue:${sysconfdir}/X11/fontpath.d'],
--- /dev/null
+Index: hw/xfree86/common/xf86Events.c
+================================================================================
+--- hw/xfree86/common/xf86Events.c
++++ hw/xfree86/common/xf86Events.c
+@@ -115,6 +115,7 @@
+ InputHandlerProc ihproc;
+ pointer data;
+ Bool enabled;
++ Bool is_input;
+ struct x_IHRec * next;
+ } IHRec, *IHPtr;
+
+@@ -449,8 +450,12 @@
+ * Keep the order: Disable Device > LeaveVT
+ * EnterVT > EnableDevice
+ */
+- for (ih = InputHandlers; ih; ih = ih->next)
+- xf86DisableInputHandler(ih);
++ for (ih = InputHandlers; ih; ih = ih->next) {
++ if (ih->is_input)
++ xf86DisableInputHandler(ih);
++ else
++ xf86DisableGeneralHandler(ih);
++ }
+ for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) {
+ if (pInfo->dev) {
+ xf86ReleaseKeys(pInfo->dev);
+@@ -492,8 +497,12 @@
+ EnableDevice(pInfo->dev, TRUE);
+ pInfo = pInfo->next;
+ }
+- for (ih = InputHandlers; ih; ih = ih->next)
+- xf86EnableInputHandler(ih);
++ for (ih = InputHandlers; ih; ih = ih->next) {
++ if (ih->is_input)
++ xf86EnableInputHandler(ih);
++ else
++ xf86EnableGeneralHandler(ih);
++ }
+
+ xf86UnblockSIGIO(prevSIGIO);
+
+@@ -549,8 +558,12 @@
+ pInfo = pInfo->next;
+ }
+
+- for (ih = InputHandlers; ih; ih = ih->next)
+- xf86EnableInputHandler(ih);
++ for (ih = InputHandlers; ih; ih = ih->next) {
++ if (ih->is_input)
++ xf86EnableInputHandler(ih);
++ else
++ xf86EnableGeneralHandler(ih);
++ }
+
+ xf86UnblockSIGIO(prevSIGIO);
+ }
+@@ -587,8 +600,10 @@
+ {
+ IHPtr ih = addInputHandler(fd, proc, data);
+
+- if (ih)
++ if (ih) {
+ AddEnabledDevice(fd);
++ ih->is_input = TRUE;
++ }
+ return ih;
+ }
+
+--- os/WaitFor.c
++++ os/WaitFor.c
+@@ -142,6 +142,7 @@
+ * For more info on ClientsWithInput, see ReadRequestFromClient().
+ * pClientsReady is an array to store ready client->index values into.
+ *****************/
++volatile fd_set tmp_set;
+
+ int
+ WaitForSomething(int *pClientsReady)
+@@ -279,10 +280,9 @@
+ if (expired)
+ return 0;
+ }
+- }
++ }
+ else
+- {
+- fd_set tmp_set;
++ {
+
+ if (*checkForInput[0] == *checkForInput[1]) {
+ if (timers)
+@@ -317,6 +317,12 @@
+ QueueWorkProc(EstablishNewConnections, NULL,
+ (pointer)&LastSelectMask);
+
++#ifdef DPMSExtension
++ XFD_ANDSET(&tmp_set, &devicesReadable, &EnabledDevices);
++ if (XFD_ANYSET (&tmp_set) && (DPMSPowerLevel != DPMSModeOn))
++ DPMSSet(serverClient, DPMSModeOn);
++#endif
++
+ if (XFD_ANYSET (&devicesReadable) || XFD_ANYSET (&clientsReadable))
+ break;
+ /* check here for DDXes that queue events during Block/Wakeup */
--- /dev/null
+Index: linuxPci.c
+================================================================================
+--- linuxPci.c
++++ linuxPci.c
+@@ -195,7 +195,7 @@
+ struct pci_id_match bridge_match = {
+ PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
+ (PCI_CLASS_BRIDGE << 16) | (PCI_SUBCLASS_BRIDGE_PCI << 8),
+- 0
++ (PCI_CLASS_BRIDGE << 16) | (PCI_SUBCLASS_BRIDGE_PCI << 8)
+ };
+ struct pci_device *bridge;
+ struct pci_device_iterator *iter;
+@@ -433,7 +433,6 @@
+ xf86MapLegacyIO(struct pci_device *dev)
+ {
+ const int domain = dev->domain;
+- struct pci_device *bridge = get_parent_bridge(dev);
+ int fd;
+
+ if (domain >= MAX_DOMAINS)
+@@ -441,9 +440,11 @@
+
+ if (DomainMmappedIO[domain] == NULL) {
+ /* Permanently map all of I/O space */
+- fd = linuxOpenLegacy(bridge, "legacy_io");
++ fd = linuxOpenLegacy(dev, "legacy_io");
+ if (fd < 0) {
+- DomainMmappedIO[domain] = linuxMapPci(-1, VIDMEM_MMIO, bridge,
++ struct pci_device *bridge = get_parent_bridge(dev);
++ if (bridge != NULL)
++ DomainMmappedIO[domain] = linuxMapPci(-1, VIDMEM_MMIO, bridge,
+ 0, linuxGetIOSize(bridge),
+ PCIIOC_MMAP_IS_IO);
+ }
--- /dev/null
+Index: xorg-server-1.6.3.901/hw/xfree86/loader/dlloader.c
+================================================================================
+--- xorg-server-1.7.99/hw/xfree86/loader/dlloader.c
++++ xorg-server-1.7.99/hw/xfree86/loader/dlloader.c
+@@ -120,7 +120,7 @@
+ }
+
+ if (!global_scope)
+- global_scope = dlopen(NULL, DLOPEN_LAZY | DLOPEN_GLOBAL);
++ global_scope = dlopen(NULL, DLOPEN_LAZY | DLOPEN_GLOBAL | RTLD_DEEPBIND);
+
+ if (global_scope)
+ return DLFindSymbolLocal(global_scope, name);
+@@ -136,9 +136,9 @@
+ int dlopen_flags;
+
+ if (flags & LD_FLAG_GLOBAL)
+- dlopen_flags = DLOPEN_LAZY | DLOPEN_GLOBAL;
++ dlopen_flags = DLOPEN_LAZY | DLOPEN_GLOBAL | RTLD_DEEPBIND;
+ else
+- dlopen_flags = DLOPEN_LAZY;
++ dlopen_flags = DLOPEN_LAZY | RTLD_DEEPBIND;
+ dlfile = dlopen(modrec->name, dlopen_flags);
+ if (dlfile == NULL) {
+ ErrorF("dlopen: %s\n", dlerror());
--- /dev/null
+From 0f70ba9d3412b17ac4e08e33e1be3c226c06ea54 Mon Sep 17 00:00:00 2001
+From: Yan Li <yan.i.li@intel.com>
+Date: Tue, 12 May 2009 17:49:07 +0800
+Subject: [PATCH] XKB: cache xkbcomp output for fast start-up v5 for 1.6.1
+Organization: Intel
+
+xkbcomp outputs will be cached in files with hashed keymap as
+names. This saves boot time for around 1s on commodity netbooks.
+
+Signed-off-by: Yan Li <yan.i.li@intel.com>
+================================================================================
+--- xorg-server-1.7.99/configure.ac
++++ xorg-server-1.7.99/configure.ac
+@@ -527,9 +527,9 @@
+ AC_ARG_WITH(xkb-path, AS_HELP_STRING([--with-xkb-path=PATH], [Path to XKB base dir (default: ${datadir}/X11/xkb)]),
+ [ XKBPATH="$withval" ],
+ [ XKBPATH="${datadir}/X11/xkb" ])
+-AC_ARG_WITH(xkb-output, AS_HELP_STRING([--with-xkb-output=PATH], [Path to XKB output dir (default: ${datadir}/X11/xkb/compiled)]),
++AC_ARG_WITH(xkb-output, AS_HELP_STRING([--with-xkb-output=PATH], [Path to XKB output dir (default: ${localstatedir}/cache/xkb)]),
+ [ XKBOUTPUT="$withval" ],
+- [ XKBOUTPUT="compiled" ])
++ [ XKBOUTPUT="${localstatedir}/cache/xkb" ])
+ AC_ARG_WITH(default-xkb-rules, AS_HELP_STRING([--with-default-xkb-rules=RULES],
+ [Keyboard ruleset (default: base/evdev)]),
+ [ XKB_DFLT_RULES="$withval" ],
+@@ -1160,7 +1160,7 @@
+ dnl Make sure XKM_OUTPUT_DIR is an absolute path
+ XKBOUTPUT_FIRSTCHAR=`echo $XKBOUTPUT | cut -b 1`
+ if [[ x$XKBOUTPUT_FIRSTCHAR != x/ -a x$XKBOUTPUT_FIRSTCHAR != 'x$' ]] ; then
+- XKBOUTPUT="$XKB_BASE_DIRECTORY/$XKBOUTPUT"
++ AC_MSG_ERROR([xkb-output must be an absolute path.])
+ fi
+
+ dnl XKM_OUTPUT_DIR (used in code) must end in / or file names get hosed
+--- xorg-server-1.7.99/xkb/README.compiled
++++ xorg-server-1.7.99/xkb/README.compiled
+@@ -4,10 +4,10 @@
+ or some other tool might destroy or replace the files in this directory,
+ so it is not a safe place to store compiled keymaps for long periods of
+ time. The default keymap for any server is usually stored in:
+- X<num>-default.xkm
+-where <num> is the display number of the server in question, which makes
+-it possible for several servers *on the same host* to share the same
+-directory.
++ server-<SHA1>.xkm
++
++where <SHA1> is the SHA1 hash of keymap source, so that compiled
++keymap of different keymap sources are stored in different files.
+
+ Unless the X server is modified, sharing this directory between servers on
+ different hosts could cause problems.
+--- xorg-server-1.9.0/xkb/ddxLoad.c.orig 2010-07-14 22:23:17.000000000 +0200
++++ xorg-server-1.9.0/xkb/ddxLoad.c 2010-08-23 15:23:47.000000000 +0200
+@@ -30,6 +30,12 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ #include <xkb-config.h>
+
++#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */
++# include <sha1.h>
++#else /* Use OpenSSL's libcrypto */
++# include <stddef.h> /* buggy openssl/sha.h wants size_t */
++# include <openssl/sha.h>
++#endif
+ #include <stdio.h>
+ #include <ctype.h>
+ #include <X11/X.h>
+@@ -43,24 +49,13 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ #define XKBSRV_NEED_FILE_FUNCS
+ #include <xkbsrv.h>
+ #include <X11/extensions/XI.h>
++#include <errno.h>
+ #include "xkb.h"
+
+ #if defined(CSRG_BASED) || defined(linux) || defined(__GNU__)
+ #include <paths.h>
+ #endif
+
+- /*
+- * If XKM_OUTPUT_DIR specifies a path without a leading slash, it is
+- * relative to the top-level XKB configuration directory.
+- * Making the server write to a subdirectory of that directory
+- * requires some work in the general case (install procedure
+- * has to create links to /var or somesuch on many machines),
+- * so we just compile into /usr/tmp for now.
+- */
+-#ifndef XKM_OUTPUT_DIR
+-#define XKM_OUTPUT_DIR "compiled/"
+-#endif
+-
+ #define PRE_ERROR_MSG "\"The XKEYBOARD keymap compiler (xkbcomp) reports:\""
+ #define ERROR_PREFIX "\"> \""
+ #define POST_ERROR_MSG1 "\"Errors from xkbcomp are not fatal to the X server\""
+@@ -175,6 +170,45 @@ OutputDirectory(
+ }
+
+ static Bool
++Sha1Asc(char sha1Asc[SHA_DIGEST_LENGTH*2+1], const char * input)
++{
++ int i;
++ unsigned char sha1[SHA_DIGEST_LENGTH];
++
++#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */
++ SHA1_CTX ctx;
++
++ SHA1Init (&ctx);
++ SHA1Update (&ctx, input, strlen(input));
++ SHA1Final (sha1, &ctx);
++#else /* Use OpenSSL's libcrypto */
++ SHA_CTX ctx;
++ int success;
++
++ success = SHA1_Init (&ctx);
++ if (! success)
++ return BadAlloc;
++
++ success = SHA1_Update (&ctx, input, strlen(input));
++ if (! success)
++ return BadAlloc;
++
++ success = SHA1_Final (sha1, &ctx);
++ if (! success)
++ return BadAlloc;
++#endif
++
++ /* convert sha1 to sha1_asc */
++ for(i=0; i<SHA_DIGEST_LENGTH; ++i) {
++ sprintf(sha1Asc+i*2, "%02X", sha1[i]);
++ }
++
++ return Success;
++}
++
++/* call xkbcomp and compile XKB keymap, return xkm file name in
++ nameRtrn */
++static Bool
+ XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
+ XkbComponentNamesPtr names,
+ unsigned want,
+@@ -183,7 +217,11 @@ XkbDDXCompileKeymapByNames( XkbDescPtr
+ int nameRtrnLen)
+ {
+ FILE * out;
+- char *buf = NULL, keymap[PATH_MAX], xkm_output_dir[PATH_MAX];
++ char * buf = NULL, xkmfile[PATH_MAX], xkm_output_dir[PATH_MAX];
++ char * tmpXkmFile = NULL;
++ char * canonicalXkmFileName = NULL;
++ char sha1Asc[SHA_DIGEST_LENGTH*2+1], xkbKeyMapBuf[100*1024];
++ int ret, result;
+
+ const char *emptystring = "";
+ char *xkbbasedirflag = NULL;
+@@ -194,15 +232,70 @@ XkbDDXCompileKeymapByNames( XkbDescPtr
+ /* WIN32 has no popen. The input must be stored in a file which is
+ used as input for xkbcomp. xkbcomp does not read from stdin. */
+ char tmpname[PATH_MAX];
+- const char *xkmfile = tmpname;
++ const char *xkbfile = tmpname;
+ #else
+- const char *xkmfile = "-";
++ const char *xkbfile = "-";
++#endif
++
++ /* Write keymap source (xkbfile) to memory buffer `xkbKeyMapBuf',
++ of which SHA1 is generated and used as result xkm file name */
++ memset(xkbKeyMapBuf, 0, sizeof(xkbKeyMapBuf));
++ out = fmemopen(xkbKeyMapBuf, sizeof(xkbKeyMapBuf), "w");
++ if (NULL == out) {
++ ErrorF("[xkb] Open xkbKeyMapBuf for writing failed\n");
++ return FALSE;
++ }
++ ret = XkbWriteXKBKeymapForNames(out, names, xkb, want, need);
++ if (fclose(out) !=0)
++ {
++ ErrorF("[xkb] XkbWriteXKBKeymapForNames error, perhaps xkbKeyMapBuf is too small\n");
++ return FALSE;
++ }
++#ifdef DEBUG
++ if (xkbDebugFlags) {
++ ErrorF("[xkb] XkbDDXCompileKeymapByNames compiling keymap:\n");
++ fputs(xkbKeyMapBuf, stderr);
++ }
+ #endif
++ if (!ret) {
++ ErrorF("[xkb] Generating XKB Keymap failed, giving up compiling keymap\n");
++ return FALSE;
++ }
+
+- snprintf(keymap, sizeof(keymap), "server-%s", display);
++ DebugF("[xkb] computing SHA1 of keymap\n");
++ if (Success == Sha1Asc(sha1Asc, xkbKeyMapBuf)) {
++ snprintf(xkmfile, sizeof(xkmfile), "server-%s", sha1Asc);
++ }
++ else {
++ ErrorF("[xkb] Computing SHA1 of keymap failed, "
++ "using display name instead as xkm file name\n");
++ snprintf(xkmfile, sizeof(xkmfile), "server-%s", display);
++ }
+
+ OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir));
+
++ /* set nameRtrn, fail if it's too small */
++ if ((strlen(xkmfile)+1 > nameRtrnLen) && nameRtrn) {
++ ErrorF("[xkb] nameRtrn too small to hold xkmfile name\n");
++ return FALSE;
++ }
++ strncpy(nameRtrn, xkmfile, nameRtrnLen);
++
++ /* if the xkm file already exists, reuse it */
++ canonicalXkmFileName = Xprintf("%s%s.xkm", xkm_output_dir, xkmfile);
++ if (access(canonicalXkmFileName, R_OK) == 0) {
++ /* yes, we can reuse the old xkm file */
++ LogMessage(X_INFO, "XKB: reuse xkmfile %s\n", canonicalXkmFileName);
++ result = TRUE;
++ goto _ret;
++ }
++ LogMessage(X_INFO, "XKB: generating xkmfile %s\n", canonicalXkmFileName);
++
++ /* continue to call xkbcomp to compile the keymap. to avoid race
++ condition, we compile it to a tmpfile then rename it to
++ xkmfile */
++
++
+ #ifdef WIN32
+ strcpy(tmpname, Win32TempDir());
+ strcat(tmpname, "\\xkb_XXXXXX");
+@@ -225,14 +318,20 @@ XkbDDXCompileKeymapByNames( XkbDescPtr
+ }
+ }
+
++ if ( (tmpXkmFile = tempnam(xkm_output_dir, NULL)) == NULL ) {
++ ErrorF("[xkb] Can't generate temp xkm file name");
++ result = FALSE;
++ goto _ret;
++ }
++
+ buf = Xprintf("\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" "
+- "-em1 %s -emp %s -eml %s \"%s%s.xkm\"",
++ "-em1 %s -emp %s -eml %s \"%s\"",
+ xkbbindir, xkbbindirsep,
+ ( (xkbDebugFlags < 2) ? 1 :
+ ((xkbDebugFlags > 10) ? 10 : (int)xkbDebugFlags) ),
+- xkbbasedirflag ? xkbbasedirflag : "", xkmfile,
++ xkbbasedirflag ? xkbbasedirflag : "", xkbfile,
+ PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1,
+- xkm_output_dir, keymap);
++ tmpXkmFile);
+
+ free(xkbbasedirflag);
+
+@@ -240,7 +339,12 @@ XkbDDXCompileKeymapByNames( XkbDescPtr
+ LogMessage(X_ERROR, "XKB: Could not invoke xkbcomp: not enough memory\n");
+ return FALSE;
+ }
+-
++
++ /* there's a potential race condition between calling tempnam()
++ and invoking xkbcomp to write the result file (potential temp
++ file name conflicts), but since xkbcomp is a standalone
++ program, we have to live with this */
++
+ #ifndef WIN32
+ out= Popen(buf,"w");
+ #else
+@@ -248,31 +352,42 @@ XkbDDXCompileKeymapByNames( XkbDescPtr
+ #endif
+
+ if (out!=NULL) {
+-#ifdef DEBUG
+- if (xkbDebugFlags) {
+- ErrorF("[xkb] XkbDDXCompileKeymapByNames compiling keymap:\n");
+- XkbWriteXKBKeymapForNames(stderr,names,xkb,want,need);
+- }
+-#endif
+- XkbWriteXKBKeymapForNames(out,names,xkb,want,need);
++ /* write XKBKeyMapBuf to xkbcomp */
++ if (EOF==fputs(xkbKeyMapBuf, out))
++ {
++ ErrorF("[xkb] Sending keymap to xkbcomp failed\n");
++ result = FALSE;
++ goto _ret;
++ }
+ #ifndef WIN32
+ if (Pclose(out)==0)
+ #else
+ if (fclose(out)==0 && System(buf) >= 0)
+ #endif
+ {
++ /* xkbcomp success */
+ if (xkbDebugFlags)
+ DebugF("[xkb] xkb executes: %s\n",buf);
+- if (nameRtrn) {
+- strncpy(nameRtrn,keymap,nameRtrnLen);
+- nameRtrn[nameRtrnLen-1]= '\0';
++ /* if canonicalXkmFileName already exists now, we simply
++ overwrite it, this is OK */
++ ret = rename(tmpXkmFile, canonicalXkmFileName);
++ if (0 != ret) {
++ ErrorF("[xkb] Can't rename %s to %s, error: %s\n",
++ tmpXkmFile, canonicalXkmFileName,
++ strerror(errno));
++
++ /* in case of error, don't unlink tmpXkmFile, leave it
++ for debugging */
++
++ result = FALSE;
++ goto _ret;
+ }
+- if (buf != NULL)
+- free(buf);
+- return TRUE;
++
++ result = TRUE;
++ goto _ret;
+ }
+ else
+- LogMessage(X_ERROR, "Error compiling keymap (%s)\n", keymap);
++ LogMessage(X_ERROR, "Error compiling keymap (%s)\n", xkbfile);
+ #ifdef WIN32
+ /* remove the temporary file */
+ unlink(tmpname);
+@@ -289,7 +404,17 @@ XkbDDXCompileKeymapByNames( XkbDescPtr
+ nameRtrn[0]= '\0';
+ if (buf != NULL)
+ free(buf);
+- return FALSE;
++ result = FALSE;
++
++_ret:
++ if (tmpXkmFile)
++ free(tmpXkmFile);
++ if (canonicalXkmFileName)
++ xfree(canonicalXkmFileName);
++ if (buf != NULL)
++ xfree (buf);
++
++ return result;
+ }
+
+ static FILE *
+@@ -373,7 +498,6 @@ unsigned missing;
+ DebugF("Loaded XKB keymap %s, defined=0x%x\n",fileName,(*xkbRtrn)->defined);
+ }
+ fclose(file);
+- (void) unlink (fileName);
+ return (need|want)&(~missing);
+ }
+
--- /dev/null
+commit 5c6a2f93ebc16a78093782b442306de23ae94e78
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date: Mon Sep 27 19:39:23 2010 +0100
+
+ xfree86: Kill pixmapPrivate with a vengeance (v2)
+
+ ScrnInfo->pixmapPrivate only existed in order to catch invalid access to
+ the framebuffer by making the backing data NULL across the VT switch.
+ This was causing more confusion in the higher layers during mode setting
+ without any real benefit, so remove it.
+
+ v2: Kill ShadowModifyPixmapHeader() as well.
+
+ Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+ Cc: Julien Cristau <jcristau@debian.org>
+ Cc: Andrew Guertin <lists@dolphinling.net>
+ Reviewed-by: Keith Packard <keithp@keithp.com>
+ Signed-off-by: Keith Packard <keithp@keithp.com>
+
+diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
+index 90e0c67..97e5aec 100644
+--- a/hw/xfree86/common/xf86Helper.c
++++ b/hw/xfree86/common/xf86Helper.c
+@@ -1180,10 +1180,6 @@ xf86EnableDisableFBAccess(int scrnIndex, Bool enable)
+ if (enable)
+ {
+ /*
+- * Restore the screen pixmap devPrivate field
+- */
+- pspix->devPrivate = pScrnInfo->pixmapPrivate;
+- /*
+ * Restore all of the clip lists on the screen
+ */
+ if (!xf86Resetting)
+@@ -1196,13 +1192,6 @@ xf86EnableDisableFBAccess(int scrnIndex, Bool enable)
+ * Empty all of the clip lists on the screen
+ */
+ xf86SetRootClip (pScreen, FALSE);
+- /*
+- * save the screen pixmap devPrivate field and
+- * replace it with NULL so accidental references
+- * to the frame buffer are caught
+- */
+- pScrnInfo->pixmapPrivate = pspix->devPrivate;
+- pspix->devPrivate.ptr = NULL;
+ }
+ }
+
+diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
+index c9b261d..b979884 100644
+--- a/hw/xfree86/common/xf86str.h
++++ b/hw/xfree86/common/xf86str.h
+@@ -765,7 +765,7 @@ typedef struct _ScrnInfoRec {
+
+ /* Allow screens to be enabled/disabled individually */
+ Bool vtSema;
+- DevUnion pixmapPrivate; /* saved devPrivate from pixmap */
++ DevUnion pixmapPrivate; /* XXX obsoleted; just for ABI compatibility */
+
+ /* hw cursor moves at SIGIO time */
+ Bool silkenMouse;
+diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
+index 8a593a7..ba0862a 100644
+--- a/hw/xfree86/modes/xf86RandR12.c
++++ b/hw/xfree86/modes/xf86RandR12.c
+@@ -511,7 +511,6 @@ xf86RandR12SetMode (ScreenPtr pScreen,
+ WindowPtr pRoot = pScreen->root;
+ DisplayModePtr currentMode = NULL;
+ Bool ret = TRUE;
+- PixmapPtr pspix = NULL;
+
+ if (pRoot)
+ (*scrp->EnableDisableFBAccess) (pScreen->myNum, FALSE);
+@@ -560,14 +559,6 @@ xf86RandR12SetMode (ScreenPtr pScreen,
+ pScreen->mmHeight = oldmmHeight;
+ scrp->currentMode = currentMode;
+ }
+- /*
+- * Get the new Screen pixmap ptr as SwitchMode might have called
+- * ModifyPixmapHeader and xf86EnableDisableFBAccess will put it back...
+- * Unfortunately.
+- */
+- pspix = (*pScreen->GetScreenPixmap) (pScreen);
+- if (pspix->devPrivate.ptr)
+- scrp->pixmapPrivate = pspix->devPrivate;
+
+ /*
+ * Make sure the layout is correct
+diff --git a/hw/xfree86/shadowfb/shadow.c b/hw/xfree86/shadowfb/shadow.c
+index 0af53d1..5cc476a 100644
+--- a/hw/xfree86/shadowfb/shadow.c
++++ b/hw/xfree86/shadowfb/shadow.c
+@@ -36,15 +36,6 @@ static void ShadowCopyWindow(
+ RegionPtr prgn
+ );
+ static Bool ShadowCreateGC(GCPtr pGC);
+-static Bool ShadowModifyPixmapHeader(
+- PixmapPtr pPixmap,
+- int width,
+- int height,
+- int depth,
+- int bitsPerPixel,
+- int devKind,
+- pointer pPixData
+-);
+
+ static Bool ShadowEnterVT(int index, int flags);
+ static void ShadowLeaveVT(int index, int flags);
+@@ -189,7 +180,6 @@ ShadowFBInit2 (
+ pScreen->CloseScreen = ShadowCloseScreen;
+ pScreen->CopyWindow = ShadowCopyWindow;
+ pScreen->CreateGC = ShadowCreateGC;
+- pScreen->ModifyPixmapHeader = ShadowModifyPixmapHeader;
+
+ pScrn->EnterVT = ShadowEnterVT;
+ pScrn->LeaveVT = ShadowLeaveVT;
+@@ -310,49 +300,6 @@ ShadowCopyWindow(
+ }
+ }
+
+-static Bool
+-ShadowModifyPixmapHeader(
+- PixmapPtr pPixmap,
+- int width,
+- int height,
+- int depth,
+- int bitsPerPixel,
+- int devKind,
+- pointer pPixData
+-)
+-{
+- ScreenPtr pScreen;
+- ScrnInfoPtr pScrn;
+- ShadowScreenPtr pPriv;
+- Bool retval;
+- PixmapPtr pScreenPix;
+-
+- if (!pPixmap)
+- return FALSE;
+-
+- pScreen = pPixmap->drawable.pScreen;
+- pScrn = xf86Screens[pScreen->myNum];
+-
+- pScreenPix = (*pScreen->GetScreenPixmap)(pScreen);
+-
+- if (pPixmap == pScreenPix && !pScrn->vtSema)
+- pScreenPix->devPrivate = pScrn->pixmapPrivate;
+-
+- pPriv = GET_SCREEN_PRIVATE(pScreen);
+-
+- pScreen->ModifyPixmapHeader = pPriv->ModifyPixmapHeader;
+- retval = (*pScreen->ModifyPixmapHeader)(pPixmap,
+- width, height, depth, bitsPerPixel, devKind, pPixData);
+- pScreen->ModifyPixmapHeader = ShadowModifyPixmapHeader;
+-
+- if (pPixmap == pScreenPix && !pScrn->vtSema)
+- {
+- pScrn->pixmapPrivate = pScreenPix->devPrivate;
+- pScreenPix->devPrivate.ptr = 0;
+- }
+- return retval;
+-}
+-
+ static void
+ ShadowComposite(
+ CARD8 op,
--- /dev/null
+Index: dix/events.c
+================================================================================
+--- dix/events.c
++++ dix/events.c
+@@ -661,37 +661,80 @@
+ {
+ BoxRec box;
+ int x = *px, y = *py;
+- int incx = 1, incy = 1;
+ SpritePtr pSprite;
++ int nbox;
++ BoxPtr pbox;
++ int d, min = (~0U >> 1), dx2, dy2, x_r, y_r;
+
+ pSprite = pDev->spriteInfo->sprite;
+ if (RegionContainsPoint(shape, x, y, &box))
+ return;
+- box = *RegionExtents(shape);
+- /* this is rather crude */
+- do {
+- x += incx;
+- if (x >= box.x2)
+- {
+- incx = -1;
+- x = *px - 1;
++
++ for (nbox = REGION_NUM_RECTS (shape),
++ pbox = REGION_RECTS(shape);
++ nbox--;
++ pbox++)
++ {
++ if (pbox->x1 < x && pbox->x2 > x) {
++ d = pbox->y1 - y;
++ if (d >= 0) {
++ d *= d;
++ if (d < min) {
++ *px = x;
++ *py = pbox->y1 + 1;
++ min = d;
++ }
++ } else {
++ d = pbox->y2 - y; d *= d;
++ if (d < min) {
++ *px = x;
++ *py = pbox->y2 - 1;
++ min = d;
++ }
++ }
+ }
+- else if (x < box.x1)
+- {
+- incx = 1;
+- x = *px;
+- y += incy;
+- if (y >= box.y2)
+- {
+- incy = -1;
+- y = *py - 1;
++ else if (pbox->y1 < y && pbox->y2 > y) {
++ d = pbox->x1 - x;
++ if (d >= 0) {
++ d *= d;
++ if (d < min) {
++ *px = pbox->x1 + 1;
++ *py = y;
++ min = d;
++ }
++ } else {
++ d = pbox->x2 - x; d *= d;
++ if (d < min) {
++ *px = pbox->x2 - 1;
++ *py = y;
++ min = d;
++ }
++ }
++
++ } else {
++ dx2 = pbox->x1 - x;
++ if (dx2 >= 0) {
++ dx2 *= dx2;
++ x_r = pbox->x1 + 1;
++ } else {
++ dx2 = pbox->x2 - x; dx2 *= dx2;
++ x_r = pbox->x2 - 1;
++ }
++ dy2 = pbox->y1 - y;
++ if (dy2 >= 0) {
++ dy2 *= dy2;
++ y_r = pbox->y1 + 1;
++ } else {
++ dy2 = pbox->y2 - y; dy2 *= dy2;
++ y_r = pbox->y2 - 1;
++ }
++ if ((d = dx2 + dy2) < min) {
++ *px = x_r;
++ *py = y_r;
++ min = d;
+ }
+- else if (y < box.y1)
+- return; /* should never get here! */
+ }
+- } while (!RegionContainsPoint(shape, x, y, &box));
+- *px = x;
+- *py = y;
++ }
+ }
+
+ static void
--- /dev/null
+Index: fb/fbblt.c
+================================================================================
+--- fb/fbblt.c
++++ fb/fbblt.c
+@@ -76,6 +76,11 @@
+ }
+ #endif
+
++/*
++ * Disable optimization (introduced by ajax) due to a general vesa
++ * driver crash later in memcpy
++*/
++#if 0
+ if (alu == GXcopy && pm == FB_ALLONES && !reverse &&
+ !(srcX & 7) && !(dstX & 7) && !(width & 7)) {
+ int i;
+@@ -97,6 +102,7 @@
+
+ return;
+ }
++#endif
+
+ FbInitializeMergeRop(alu, pm);
+ destInvarient = FbDestInvarientMergeRop();
--- /dev/null
+Index: xorg-server-1.6.3.901/hw/xfree86/common/xf86DPMS.c
+================================================================================
+--- xorg-server-1.7.99/hw/xfree86/common/xf86DPMS.c
++++ xorg-server-1.7.99/hw/xfree86/common/xf86DPMS.c
+@@ -156,7 +156,8 @@
+ rc = dixSaveScreens(client, SCREEN_SAVER_FORCER, ScreenSaverActive);
+ if (rc != Success)
+ return rc;
+- }
++ } else
++ dixSaveScreens(client, SCREEN_SAVER_FORCER, ScreenSaverReset);
+
+ /* For each screen, set the DPMS level */
+ for (i = 0; i < xf86NumScreens; i++) {
--- /dev/null
+--- hw/xfree86/common/xf86pciBus.c
++++ hw/xfree86/common/xf86pciBus.c
+@@ -176,7 +176,11 @@
+ case 0x1142: driverList[0] = "apm"; break;
+ case 0xedd8: driverList[0] = "ark"; break;
+ case 0x1a03: driverList[0] = "ast"; break;
+- case 0x1002: driverList[0] = "ati"; break;
++ case 0x1002:
++ driverList[0] = "fglrx";
++ driverList[1] = "radeonhd";
++ driverList[2] = "ati";
++ break;
+ case 0x102c: driverList[0] = "chips"; break;
+ case 0x1013: driverList[0] = "cirrus"; break;
+ case 0x3d3d: driverList[0] = "glint"; break;
+@@ -192,8 +196,20 @@
+ break;
+ case 0x102b: driverList[0] = "mga"; break;
+ case 0x10c8: driverList[0] = "neomagic"; break;
+- case 0x10de: case 0x12d2: driverList[0] = "nv"; break;
+- case 0x1106: driverList[0] = "openchrome"; break;
++ case 0x12d2: driverList[0] = "nv"; break;
++ case 0x10de:
++ driverList[0] = "nvidia";
++ driverList[1] = "nouveau";
++ /* GeForce 6150SE support broken (bnc #465190/544674) */
++ if (dev->device_id != 0x03D0) {
++ driverList[2] = "nv";
++ }
++ break;
++ case 0x1106:
++ driverList[0] = "via";
++ driverList[1] = "openchrome";
++ driverList[2] = "unichrome";
++ break;
+ case 0x1b36: driverList[0] = "qxl"; break;
+ case 0x1163: driverList[0] = "rendition"; break;
+ case 0x5333:
--- /dev/null
+Index: xorg-server-1.6.3.901/hw/xfree86/modes/xf86Crtc.c
+================================================================================
+--- xorg-server-1.7.99/hw/xfree86/modes/xf86Crtc.c
++++ xorg-server-1.7.99/hw/xfree86/modes/xf86Crtc.c
+@@ -2916,8 +2916,14 @@
+ p->output->MonInfo->features.vsize);
+ if (det_mon->type == DT &&
+ det_mon->section.d_timings.h_size != 0 &&
+- det_mon->section.d_timings.v_size != 0) {
+-
++ det_mon->section.d_timings.v_size != 0 &&
++ det_mon->section.d_timings.v_size != 0 &&
++ /* some sanity checking for aspect ration */
++ ((det_mon->section.d_timings.h_size /
++ det_mon->section.d_timings.v_size) < 2) &&
++ ((det_mon->section.d_timings.v_size /
++ det_mon->section.d_timings.h_size) < 2)
++ ) {
+ p->output->mm_width = det_mon->section.d_timings.h_size;
+ p->output->mm_height = det_mon->section.d_timings.v_size;
+ p->ret = TRUE;
--- /dev/null
+Index: hw/xfree86/fbdevhw/fbdevhw.c
+================================================================================
+--- hw/xfree86/fbdevhw/fbdevhw.c
++++ hw/xfree86/fbdevhw/fbdevhw.c
+@@ -957,9 +957,10 @@
+ return;
+ }
+
++ /* Novell Bug #146462 */
+ if (-1 == ioctl(fPtr->fd, FBIOBLANK, (void *)fbmode))
+- xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+- "FBIOBLANK: %s\n", strerror(errno));
++ xf86DrvMsg(pScrn->scrnIndex, X_INFO,
++ "FBIOBLANK: %s (Screen blanking not supported by vesafb of Linux Kernel)\n", strerror(errno));
+ }
+
+ Bool
+@@ -975,9 +976,10 @@
+
+ unblank = xf86IsUnblank(mode);
+
++ /* Novell Bug #146462 */
+ if (-1 == ioctl(fPtr->fd, FBIOBLANK, (void *)(1-unblank))) {
+- xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+- "FBIOBLANK: %s\n", strerror(errno));
++ xf86DrvMsg(pScrn->scrnIndex, X_INFO,
++ "FBIOBLANK: %s (Screen blanking not supported by vesafb of Linux Kernel)\n", strerror(errno));
+ return FALSE;
+ }
+
--- /dev/null
+Index: hw/xfree86/common/xf86Helper.c
+================================================================================
+--- hw/xfree86/common/xf86Helper.c
++++ hw/xfree86/common/xf86Helper.c
+@@ -974,12 +974,22 @@
+ } else if (pScrn->widthmm > 0 || pScrn->heightmm > 0) {
+ from = X_CONFIG;
+ if (pScrn->widthmm > 0) {
+- pScrn->xDpi =
+- (int)((double)pScrn->virtualX * MMPERINCH / pScrn->widthmm);
++ if (pScrn->modes && pScrn->modes->HDisplay > 0) {
++ pScrn->xDpi =
++ (int)((double) pScrn->modes->HDisplay * MMPERINCH / pScrn->widthmm);
++ } else {
++ pScrn->xDpi =
++ (int)((double)pScrn->virtualX * MMPERINCH / pScrn->widthmm);
++ }
+ }
+ if (pScrn->heightmm > 0) {
+- pScrn->yDpi =
+- (int)((double)pScrn->virtualY * MMPERINCH / pScrn->heightmm);
++ if (pScrn->modes && pScrn->modes->VDisplay > 0) {
++ pScrn->yDpi =
++ (int)((double)pScrn->modes->VDisplay * MMPERINCH / pScrn->heightmm);
++ } else {
++ pScrn->yDpi =
++ (int)((double)pScrn->virtualY * MMPERINCH / pScrn->heightmm);
++ }
+ }
+ if (pScrn->xDpi > 0 && pScrn->yDpi <= 0)
+ pScrn->yDpi = pScrn->xDpi;
+@@ -1014,12 +1024,22 @@
+ pScrn->widthmm = ddcWidthmm;
+ pScrn->heightmm = ddcHeightmm;
+ if (pScrn->widthmm > 0) {
+- pScrn->xDpi =
+- (int)((double)pScrn->virtualX * MMPERINCH / pScrn->widthmm);
++ if (pScrn->modes && pScrn->modes->HDisplay > 0) {
++ pScrn->xDpi =
++ (int)((double) pScrn->modes->HDisplay * MMPERINCH / pScrn->widthmm);
++ } else {
++ pScrn->xDpi =
++ (int)((double)pScrn->virtualX * MMPERINCH / pScrn->widthmm);
++ }
+ }
+ if (pScrn->heightmm > 0) {
+- pScrn->yDpi =
+- (int)((double)pScrn->virtualY * MMPERINCH / pScrn->heightmm);
++ if (pScrn->modes && pScrn->modes->VDisplay > 0) {
++ pScrn->yDpi =
++ (int)((double)pScrn->modes->VDisplay * MMPERINCH / pScrn->heightmm);
++ } else {
++ pScrn->yDpi =
++ (int)((double)pScrn->virtualY * MMPERINCH / pScrn->heightmm);
++ }
+ }
+ if (pScrn->xDpi > 0 && pScrn->yDpi <= 0)
+ pScrn->yDpi = pScrn->xDpi;
--- /dev/null
+--- hw/xfree86/common/xf86AutoConfig.c.orig 2010-03-23 19:36:35.242114919 +0100
++++ hw/xfree86/common/xf86AutoConfig.c 2010-03-23 19:46:34.037124633 +0100
+@@ -75,6 +75,13 @@
+ "\tDevice\t" BUILTIN_DEVICE_NAME "\n" \
+ "EndSection\n\n"
+
++#define BUILTIN_SCREEN_SECTION_FOR_FGLRX \
++ "Section \"Screen\"\n" \
++ "\tIdentifier\t" BUILTIN_SCREEN_NAME "\n" \
++ "\tDevice\t" BUILTIN_DEVICE_NAME "\n" \
++ "\tDefaultDepth\t24\n" \
++ "EndSection\n\n"
++
+ #define BUILTIN_LAYOUT_SECTION_PRE \
+ "Section \"ServerLayout\"\n" \
+ "\tIdentifier\t\"Builtin Default Layout\"\n"
+@@ -259,7 +266,10 @@ xf86AutoConfig(void)
+ for (p = deviceList; *p; p++) {
+ snprintf(buf, sizeof(buf), BUILTIN_DEVICE_SECTION, *p, 0, *p);
+ AppendToConfig(buf);
+- snprintf(buf, sizeof(buf), BUILTIN_SCREEN_SECTION, *p, 0, *p, 0);
++ if( strcmp(*p, "fglrx") == 0 )
++ snprintf(buf, sizeof(buf), BUILTIN_SCREEN_SECTION_FOR_FGLRX, *p, 0, *p, 0);
++ else
++ snprintf(buf, sizeof(buf), BUILTIN_SCREEN_SECTION, *p, 0, *p, 0);
+ AppendToConfig(buf);
+ }
+
--- /dev/null
+diff -up fltk-1.3.x-r8659/FL/Fl.H.orig fltk-1.3.x-r8659/FL/Fl.H
+--- fltk-1.3.x-r8659/FL/Fl.H.orig 2011-05-17 16:25:56.671744548 +0200
++++ fltk-1.3.x-r8659/FL/Fl.H 2011-05-17 16:26:05.709101536 +0200
+@@ -108,6 +108,9 @@ typedef int (*Fl_Args_Handler)(int argc,
+ \see Fl::event_dispatch(Fl_Event_Dispatch) */
+ typedef int (*Fl_Event_Dispatch)(int event, Fl_Window *w);
+
++/** Signature of add_clipboard_notify functions passed as parameters */
++typedef void (*Fl_Clipboard_Notify_Handler)(int source, void *data);
++
+ /** @} */ /* group callback_functions */
+
+
+@@ -744,6 +747,19 @@ public:
+ */
+ static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent
+ /**
++ FLTK will call the registered callback whenever there is a change to the
++ selection buffer or the clipboard. The source argument indicates which
++ of the two has changed. Only changes by other applications are reported.
++ \note Some systems require polling to monitor the clipboard and may
++ therefore have some delay in detecting changes.
++ */
++ static void add_clipboard_notify(Fl_Clipboard_Notify_Handler h, void *data);
++ /**
++ Stop calling the specified callback when there are changes to the selection
++ buffer or the clipboard.
++ */
++ static void remove_clipboard_notify(Fl_Clipboard_Notify_Handler h);
++ /**
+ Initiate a Drag And Drop operation. The selection buffer should be
+ filled with relevant data before calling this method. FLTK will
+ then initiate the system wide drag and drop handling. Dropped data
+diff -up fltk-1.3.x-r8659/src/Fl.cxx.orig fltk-1.3.x-r8659/src/Fl.cxx
+--- fltk-1.3.x-r8659/src/Fl.cxx.orig 2011-05-18 15:20:26.667291459 +0200
++++ fltk-1.3.x-r8659/src/Fl.cxx 2011-05-18 16:31:15.522026086 +0200
+@@ -430,6 +430,69 @@ static char in_idle;
+ #endif
+
+ ////////////////////////////////////////////////////////////////
++// Clipboard notifications
++
++struct Clipboard_Notify {
++ Fl_Clipboard_Notify_Handler handler;
++ void *data;
++ struct Clipboard_Notify *next;
++};
++
++static struct Clipboard_Notify *clip_notify_list = NULL;
++
++extern void fl_clipboard_notify_change(); // in Fl_<platform>.cxx
++
++void Fl::add_clipboard_notify(Fl_Clipboard_Notify_Handler h, void *data) {
++ struct Clipboard_Notify *node;
++
++ remove_clipboard_notify(h);
++
++ node = new Clipboard_Notify;
++
++ node->handler = h;
++ node->data = data;
++ node->next = clip_notify_list;
++
++ clip_notify_list = node;
++
++ fl_clipboard_notify_change();
++}
++
++void Fl::remove_clipboard_notify(Fl_Clipboard_Notify_Handler h) {
++ struct Clipboard_Notify *node, **prev;
++
++ node = clip_notify_list;
++ prev = &clip_notify_list;
++ while (node != NULL) {
++ if (node->handler == h) {
++ *prev = node->next;
++ delete node;
++
++ fl_clipboard_notify_change();
++
++ return;
++ }
++
++ prev = &node->next;
++ node = node->next;
++ }
++}
++
++bool fl_clipboard_notify_empty(void) {
++ return clip_notify_list == NULL;
++}
++
++void fl_trigger_clipboard_notify(int source) {
++ struct Clipboard_Notify *node;
++
++ node = clip_notify_list;
++ while (node != NULL) {
++ node->handler(source, node->data);
++ node = node->next;
++ }
++}
++
++////////////////////////////////////////////////////////////////
+ // wait/run/check/ready:
+
+ void (*Fl::idle)(); // see Fl::add_idle.cxx for the add/remove functions
--- /dev/null
+diff -up fltk-1.3.0r9619/FL/Fl.H.screen_num fltk-1.3.0r9619/FL/Fl.H
+--- fltk-1.3.0r9619/FL/Fl.H.screen_num 2012-07-03 13:49:28.663085580 +0200
++++ fltk-1.3.0r9619/FL/Fl.H 2012-07-03 13:49:28.731084402 +0200
+@@ -806,6 +806,8 @@ public:
+ static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
+ static void screen_xywh(int &X, int &Y, int &W, int &H, int n);
+ static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh);
++ static int screen_num(int x, int y);
++ static int screen_num(int x, int y, int w, int h);
+ static void screen_dpi(float &h, float &v, int n=0);
+ static void screen_work_area(int &X, int &Y, int &W, int &H, int mx, int my);
+ static void screen_work_area(int &X, int &Y, int &W, int &H, int n);
+diff -up fltk-1.3.0r9619/src/screen_xywh.cxx.screen_num fltk-1.3.0r9619/src/screen_xywh.cxx
+--- fltk-1.3.0r9619/src/screen_xywh.cxx.screen_num 2012-03-23 17:47:53.000000000 +0100
++++ fltk-1.3.0r9619/src/screen_xywh.cxx 2012-07-03 13:58:01.947195396 +0200
+@@ -215,21 +215,6 @@ int Fl::screen_count() {
+ return num_screens ? num_screens : 1;
+ }
+
+-static int find_screen_with_point(int mx, int my) {
+- int screen = 0;
+- if (num_screens < 0) screen_init();
+-
+- for (int i = 0; i < num_screens; i ++) {
+- int sx, sy, sw, sh;
+- Fl::screen_xywh(sx, sy, sw, sh, i);
+- if ((mx >= sx) && (mx < (sx+sw)) && (my >= sy) && (my < (sy+sh))) {
+- screen = i;
+- break;
+- }
+- }
+- return screen;
+-}
+-
+ /**
+ Gets the bounding box of a screen
+ that contains the specified screen position \p mx, \p my
+@@ -237,7 +222,7 @@ static int find_screen_with_point(int mx
+ \param[in] mx, my the absolute screen position
+ */
+ void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my) {
+- screen_xywh(X, Y, W, H, find_screen_with_point(mx, my));
++ screen_xywh(X, Y, W, H, screen_num(mx, my));
+ }
+
+
+@@ -248,7 +233,7 @@ void Fl::screen_xywh(int &X, int &Y, int
+ \param[in] mx, my the absolute screen position
+ */
+ void Fl::screen_work_area(int &X, int &Y, int &W, int &H, int mx, int my) {
+- screen_work_area(X, Y, W, H, find_screen_with_point(mx, my));
++ screen_work_area(X, Y, W, H, screen_num(mx, my));
+ }
+
+ /**
+@@ -321,6 +306,38 @@ void Fl::screen_xywh(int &X, int &Y, int
+ #endif // WIN32
+ }
+
++/**
++ Gets the screen bounding rect for the screen
++ which intersects the most with the rectangle
++ defined by \p mx, \p my, \p mw, \p mh.
++ \param[out] X,Y,W,H the corresponding screen bounding box
++ \param[in] mx, my, mw, mh the rectangle to search for intersection with
++ \see void screen_xywh(int &X, int &Y, int &W, int &H, int n)
++ */
++void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh) {
++ screen_xywh(X, Y, W, H, screen_num(mx, my, mw, mh));
++}
++
++/**
++ Gets the screen number of a screen
++ that contains the specified screen position \p x, \p y
++ \param[in] x, y the absolute screen position
++*/
++int Fl::screen_num(int x, int y) {
++ int screen = 0;
++ if (num_screens < 0) screen_init();
++
++ for (int i = 0; i < num_screens; i ++) {
++ int sx, sy, sw, sh;
++ Fl::screen_xywh(sx, sy, sw, sh, i);
++ if ((x >= sx) && (x < (sx+sw)) && (y >= sy) && (y < (sy+sh))) {
++ screen = i;
++ break;
++ }
++ }
++ return screen;
++}
++
+ static inline float fl_intersection(int x1, int y1, int w1, int h1,
+ int x2, int y2, int w2, int h2) {
+ if(x1+w1 < x2 || x2+w2 < x1 || y1+h1 < y2 || y2+h2 < y1)
+@@ -333,30 +350,27 @@ static inline float fl_intersection(int
+ }
+
+ /**
+- Gets the screen bounding rect for the screen
++ Gets the screen number for the screen
+ which intersects the most with the rectangle
+- defined by \p mx, \p my, \p mw, \p mh.
+- \param[out] X,Y,W,H the corresponding screen bounding box
+- \param[in] mx, my, mw, mh the rectangle to search for intersection with
+- \see void screen_xywh(int &X, int &Y, int &W, int &H, int n)
++ defined by \p x, \p y, \p w, \p h.
++ \param[in] x, y, w, h the rectangle to search for intersection with
+ */
+-void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh) {
++int Fl::screen_num(int x, int y, int w, int h) {
+ int best_screen = 0;
+ float best_intersection = 0.;
+ for(int i = 0; i < Fl::screen_count(); i++) {
+ int sx, sy, sw, sh;
+ Fl::screen_xywh(sx, sy, sw, sh, i);
+- float sintersection = fl_intersection(mx, my, mw, mh, sx, sy, sw, sh);
++ float sintersection = fl_intersection(x, y, w, h, sx, sy, sw, sh);
+ if(sintersection > best_intersection) {
+ best_screen = i;
+ best_intersection = sintersection;
+ }
+ }
+- screen_xywh(X, Y, W, H, best_screen);
++ return best_screen;
+ }
+
+
+-
+ /**
+ Gets the screen resolution in dots-per-inch for the given screen.
+ \param[out] h, v horizontal and vertical resolution
--- /dev/null
+diff -bur fltk-1.3.0r9619.org/src/Fl_cocoa.mm fltk-1.3.0r9619/src/Fl_cocoa.mm
+--- fltk-1.3.0r9619.org/src/Fl_cocoa.mm 2012-06-19 12:54:43.694231638 +0200
++++ fltk-1.3.0r9619/src/Fl_cocoa.mm 2012-06-19 12:57:05.899048602 +0200
+@@ -697,12 +697,9 @@
+ return NO; // prevent the caption to be redrawn as active on click
+ // when another modal window is currently the key win
+
+- return !(w->tooltip_window() || w->menu_window());
++ return !w->tooltip_window();
+ }
+
+-// TODO see if we really need a canBecomeMainWindow ...
+-#if 0
+-
+ - (BOOL)canBecomeMainWindow
+ {
+ if (Fl::modal_ && (Fl::modal_ != w))
+@@ -711,7 +708,6 @@
+
+ return !(w->tooltip_window() || w->menu_window());
+ }
+-#endif
+
+ @end
+
+diff -bur fltk-1.3.0r9619.org/src/Fl_win32.cxx fltk-1.3.0r9619/src/Fl_win32.cxx
+--- fltk-1.3.0r9619.org/src/Fl_win32.cxx 2012-06-19 12:54:43.696231735 +0200
++++ fltk-1.3.0r9619/src/Fl_win32.cxx 2012-06-19 12:54:43.803236862 +0200
+@@ -1065,6 +1065,10 @@
+ break;
+
+ case WM_SETFOCUS:
++ if ((Fl::modal_) && (Fl::modal_ != window)) {
++ SetFocus(fl_xid(Fl::modal_));
++ return 0;
++ }
+ Fl::handle(FL_FOCUS, window);
+ break;
+
+@@ -1826,6 +1830,11 @@
+ Fl::e_number = old_event;
+ w->redraw(); // force draw to happen
+ }
++
++ // Needs to be done before ShowWindow() to get the correct behaviour
++ // when we get WM_SETFOCUS.
++ if (w->modal()) {Fl::modal_ = w; fl_fix_focus();}
++
+ // If we've captured the mouse, we dont want to activate any
+ // other windows from the code, or we lose the capture.
+ ShowWindow(x->xid, !showit ? SW_SHOWMINNOACTIVE :
+@@ -1843,7 +1852,6 @@
+ }
+ }
+
+- if (w->modal()) {Fl::modal_ = w; fl_fix_focus();}
+ return x;
+ }
+
+diff -bur fltk-1.3.0r9619.org/src/Fl_x.cxx fltk-1.3.0r9619/src/Fl_x.cxx
+--- fltk-1.3.0r9619.org/src/Fl_x.cxx 2012-06-19 12:54:43.697231783 +0200
++++ fltk-1.3.0r9619/src/Fl_x.cxx 2012-06-19 12:54:43.804236911 +0200
+@@ -2101,6 +2101,12 @@
+ while (wp->parent()) wp = wp->window();
+ XSetTransientForHint(fl_display, xp->xid, fl_xid(wp));
+ if (!wp->visible()) showit = 0; // guess that wm will not show it
++ if (win->modal()) {
++ Atom net_wm_state = XInternAtom (fl_display, "_NET_WM_STATE", 0);
++ Atom net_wm_state_skip_taskbar = XInternAtom (fl_display, "_NET_WM_STATE_MODAL", 0);
++ XChangeProperty (fl_display, xp->xid, net_wm_state, XA_ATOM, 32,
++ PropModeAppend, (unsigned char*) &net_wm_state_skip_taskbar, 1);
++ }
+ }
+
+ // Make sure that borderless windows do not show in the task bar
--- /dev/null
+diff -bur fltk-1.3.0r9619.org/src/Fl_cocoa.mm fltk-1.3.0r9619/src/Fl_cocoa.mm
+--- fltk-1.3.0r9619.org/src/Fl_cocoa.mm 2012-06-18 19:24:30.971688769 +0200
++++ fltk-1.3.0r9619/src/Fl_cocoa.mm 2012-06-18 19:25:25.700310375 +0200
+@@ -1319,9 +1319,13 @@
+ }
+ @end
+
++static void clipboard_check(void);
++
+ @implementation FLApplication
+ + (void)sendEvent:(NSEvent *)theEvent
+ {
++ // update clipboard status
++ clipboard_check();
+ NSEventType type = [theEvent type];
+ if (type == NSLeftMouseDown) {
+ fl_lock_function();
+@@ -2790,6 +2794,26 @@
+ PasteboardCreate(kPasteboardClipboard, &myPasteboard);
+ }
+
++extern void fl_trigger_clipboard_notify(int source);
++
++void fl_clipboard_notify_change() {
++ // No need to do anything here...
++}
++
++static void clipboard_check(void)
++{
++ PasteboardSyncFlags flags;
++
++ allocatePasteboard();
++ flags = PasteboardSynchronize(myPasteboard);
++
++ if (!(flags & kPasteboardModified))
++ return;
++ if (flags & kPasteboardClientIsOwner)
++ return;
++
++ fl_trigger_clipboard_notify(1);
++}
+
+ /*
+ * create a selection
--- /dev/null
+diff -ur fltk-1.3.0r9110.org/src/Fl.cxx fltk-1.3.0r9110/src/Fl.cxx
+--- fltk-1.3.0r9110.org/src/Fl.cxx 2012-06-17 19:47:09.988183253 +0200
++++ fltk-1.3.0r9110/src/Fl.cxx 2012-06-17 19:47:10.127189919 +0200
+@@ -1421,6 +1421,7 @@
+ // hide() destroys the X window, it does not do unmap!
+
+ #if defined(WIN32)
++extern void fl_clipboard_notify_untarget(HWND wnd);
+ extern void fl_update_clipboard(void);
+ #elif USE_XFT
+ extern void fl_destroy_xft_draw(Window);
+@@ -1471,6 +1472,8 @@
+ // to destroy the window that owns the selection.
+ if (GetClipboardOwner()==ip->xid)
+ fl_update_clipboard();
++ // Make sure we unlink this window from the clipboard chain
++ fl_clipboard_notify_untarget(ip->xid);
+ // Send a message to myself so that I'll get out of the event loop...
+ PostMessage(ip->xid, WM_APP, 0, 0);
+ if (ip->private_dc) fl_release_dc(ip->xid, ip->private_dc);
+diff -ur fltk-1.3.0r9110.org/src/Fl_win32.cxx fltk-1.3.0r9110/src/Fl_win32.cxx
+--- fltk-1.3.0r9110.org/src/Fl_win32.cxx 2012-06-17 19:47:09.987183205 +0200
++++ fltk-1.3.0r9110/src/Fl_win32.cxx 2012-06-17 19:47:19.069618739 +0200
+@@ -646,6 +646,38 @@
+ }
+ }
+
++static HWND clipboard_wnd = 0;
++static HWND next_clipboard_wnd = 0;
++
++static bool initial_clipboard = true;
++
++void fl_clipboard_notify_change() {
++ // No need to do anything here...
++}
++
++void fl_clipboard_notify_target(HWND wnd) {
++ if (clipboard_wnd)
++ return;
++
++ // We get one fake WM_DRAWCLIPBOARD immediately, which we therefore
++ // need to ignore.
++ initial_clipboard = true;
++
++ clipboard_wnd = wnd;
++ next_clipboard_wnd = SetClipboardViewer(wnd);
++}
++
++void fl_clipboard_notify_untarget(HWND wnd) {
++ if (wnd != clipboard_wnd)
++ return;
++
++ ChangeClipboardChain(wnd, next_clipboard_wnd);
++ clipboard_wnd = next_clipboard_wnd = 0;
++
++ if (Fl::first_window())
++ fl_clipboard_notify_target(fl_xid(Fl::first_window()));
++}
++
+ ////////////////////////////////////////////////////////////////
+ char fl_is_ime = 0;
+ void fl_get_codepage()
+@@ -1327,6 +1359,27 @@
+ Fl::handle(FL_SCREEN_CONFIGURATION_CHANGED, NULL);
+ return 0;
+
++ case WM_CHANGECBCHAIN:
++ if ((hWnd == clipboard_wnd) &&
++ (next_clipboard_wnd == (HWND)wParam)) {
++ next_clipboard_wnd = (HWND)lParam;
++ return 0;
++ }
++ break;
++
++ case WM_DRAWCLIPBOARD:
++ // When the clipboard moves between two FLTK windows,
++ // fl_i_own_selection will temporarily be false as we are
++ // processing this message. Hence the need to use fl_find().
++ if (!initial_clipboard && !fl_find(GetClipboardOwner()))
++ fl_trigger_clipboard_notify(1);
++ initial_clipboard = false;
++
++ if (next_clipboard_wnd)
++ SendMessage(next_clipboard_wnd, WM_DRAWCLIPBOARD, wParam, lParam);
++
++ return 0;
++
+ default:
+ if (Fl::handle(0,0)) return 0;
+ break;
+@@ -1685,6 +1738,8 @@
+ x->next = Fl_X::first;
+ Fl_X::first = x;
+
++ fl_clipboard_notify_target(x->xid);
++
+ x->wait_for_expose = 1;
+ if (fl_show_iconic) {showit = 0; fl_show_iconic = 0;}
+ if (showit) {
--- /dev/null
+diff -ur fltk-1.3.2.org/FL/Fl_Window.H fltk-1.3.2/FL/Fl_Window.H
+--- fltk-1.3.2.org/FL/Fl_Window.H 2013-01-16 10:49:40.904228200 +0100
++++ fltk-1.3.2/FL/Fl_Window.H 2013-01-16 10:49:55.554353925 +0100
+@@ -22,6 +22,10 @@
+ #ifndef Fl_Window_H
+ #define Fl_Window_H
+
++#ifdef WIN32
++#include <windows.h>
++#endif
++
+ #include "Fl_Group.H"
+
+ #define FL_WINDOW 0xF0 ///< window type id all subclasses have type() >= this
+@@ -73,9 +77,19 @@
+ friend class Fl_X;
+ Fl_X *i; // points at the system-specific stuff
+
++ struct icon_data {
++ const void *legacy_icon;
++ Fl_RGB_Image **icons;
++ int count;
++#ifdef WIN32
++ HICON big_icon;
++ HICON small_icon;
++#endif
++ };
++
+ const char* iconlabel_;
+ char* xclass_;
+- const void* icon_;
++ struct icon_data *icon_;
+ // size_range stuff:
+ int minw, minh, maxw, maxh;
+ int dw, dh, aspect;
+@@ -121,6 +135,8 @@
+ */
+ int force_position() const { return ((flags() & FORCE_POSITION)?1:0); }
+
++ void free_icons();
++
+ public:
+
+ /**
+@@ -350,6 +366,18 @@
+ static const char *default_xclass();
+ const char* xclass() const;
+ void xclass(const char* c);
++
++ static void default_icon(const Fl_RGB_Image*);
++ static void default_icons(const Fl_RGB_Image*[], int);
++ void icon(const Fl_RGB_Image*);
++ void icons(const Fl_RGB_Image*[], int);
++
++#ifdef WIN32
++ static void default_icons(HICON big_icon, HICON small_icon);
++ void icons(HICON big_icon, HICON small_icon);
++#endif
++
++ /* for legacy compatibility */
+ const void* icon() const;
+ void icon(const void * ic);
+
+diff -ur fltk-1.3.2.org/FL/mac.H fltk-1.3.2/FL/mac.H
+--- fltk-1.3.2.org/FL/mac.H 2013-01-16 10:49:40.904228200 +0100
++++ fltk-1.3.2/FL/mac.H 2013-01-16 10:49:55.554353925 +0100
+@@ -120,6 +120,9 @@
+ void collapse(void);
+ WindowRef window_ref(void);
+ void set_key_window(void);
++ // OS X doesn't have per window icons
++ static void set_default_icons(const Fl_RGB_Image*[], int) {};
++ void set_icons() {};
+ int set_cursor(Fl_Cursor);
+ int set_cursor(const Fl_RGB_Image*, int, int);
+ static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
+diff -ur fltk-1.3.2.org/FL/win32.H fltk-1.3.2/FL/win32.H
+--- fltk-1.3.2.org/FL/win32.H 2013-01-16 10:49:40.904228200 +0100
++++ fltk-1.3.2/FL/win32.H 2013-01-16 10:49:55.555355617 +0100
+@@ -84,6 +84,9 @@
+ void flush() {w->flush();}
+ void set_minmax(LPMINMAXINFO minmax);
+ void mapraise();
++ static void set_default_icons(const Fl_RGB_Image*[], int);
++ static void set_default_icons(HICON, HICON);
++ void set_icons();
+ int set_cursor(Fl_Cursor);
+ int set_cursor(const Fl_RGB_Image*, int, int);
+ static Fl_X* make(Fl_Window*);
+diff -ur fltk-1.3.2.org/FL/x.H fltk-1.3.2/FL/x.H
+--- fltk-1.3.2.org/FL/x.H 2013-01-16 10:49:40.904228200 +0100
++++ fltk-1.3.2/FL/x.H 2013-01-16 10:49:55.555355617 +0100
+@@ -154,6 +154,8 @@
+ static Fl_X* i(const Fl_Window* wi) {return wi->i;}
+ void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
+ void sendxjunk();
++ static void set_default_icons(const Fl_RGB_Image*[], int);
++ void set_icons();
+ int set_cursor(Fl_Cursor);
+ int set_cursor(const Fl_RGB_Image*, int, int);
+ static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
+diff -ur fltk-1.3.2.org/src/Fl.cxx fltk-1.3.2/src/Fl.cxx
+--- fltk-1.3.2.org/src/Fl.cxx 2013-01-16 10:49:40.895228113 +0100
++++ fltk-1.3.2/src/Fl.cxx 2013-01-16 10:49:55.556137979 +0100
+@@ -1530,6 +1530,8 @@
+ if (xclass_) {
+ free(xclass_);
+ }
++ free_icons();
++ delete icon_;
+ }
+
+ // FL_SHOW and FL_HIDE are called whenever the visibility of this widget
+diff -ur fltk-1.3.2.org/src/Fl_win32.cxx fltk-1.3.2/src/Fl_win32.cxx
+--- fltk-1.3.2.org/src/Fl_win32.cxx 2013-01-16 10:49:40.911227539 +0100
++++ fltk-1.3.2/src/Fl_win32.cxx 2013-01-16 10:49:55.556137979 +0100
+@@ -1804,6 +1804,8 @@
+ );
+ if (lab) free(lab);
+
++ x->set_icons();
++
+ if (w->fullscreen_active()) {
+ /* We need to make sure that the fullscreen is created on the
+ default monitor, ie the desktop where the shortcut is located
+@@ -2034,71 +2036,19 @@
+
+ ////////////////////////////////////////////////////////////////
+
+-#ifndef IDC_HAND
+-# define IDC_HAND MAKEINTRESOURCE(32649)
+-#endif // !IDC_HAND
+-
+-int Fl_X::set_cursor(Fl_Cursor c) {
+- LPSTR n;
+- HCURSOR new_cursor;
+-
+- if (c == FL_CURSOR_NONE)
+- new_cursor = NULL;
+- else {
+- switch (c) {
+- case FL_CURSOR_ARROW: n = IDC_ARROW; break;
+- case FL_CURSOR_CROSS: n = IDC_CROSS; break;
+- case FL_CURSOR_WAIT: n = IDC_WAIT; break;
+- case FL_CURSOR_INSERT: n = IDC_IBEAM; break;
+- case FL_CURSOR_HAND: n = IDC_HAND; break;
+- case FL_CURSOR_HELP: n = IDC_HELP; break;
+- case FL_CURSOR_MOVE: n = IDC_SIZEALL; break;
+- case FL_CURSOR_N:
+- case FL_CURSOR_S:
+- // FIXME: Should probably have fallbacks for these instead
+- case FL_CURSOR_NS: n = IDC_SIZENS; break;
+- case FL_CURSOR_NE:
+- case FL_CURSOR_SW:
+- // FIXME: Dito.
+- case FL_CURSOR_NESW: n = IDC_SIZENESW; break;
+- case FL_CURSOR_E:
+- case FL_CURSOR_W:
+- // FIXME: Dito.
+- case FL_CURSOR_WE: n = IDC_SIZEWE; break;
+- case FL_CURSOR_SE:
+- case FL_CURSOR_NW:
+- // FIXME: Dito.
+- case FL_CURSOR_NWSE: n = IDC_SIZENWSE; break;
+- default:
+- return 0;
+- }
+-
+- new_cursor = LoadCursor(NULL, n);
+- if (new_cursor == NULL)
+- return 0;
+- }
+-
+- if ((cursor != NULL) && custom_cursor)
+- DestroyIcon(cursor);
+-
+- cursor = new_cursor;
+- custom_cursor = 0;
+-
+- SetCursor(cursor);
+-
+- return 1;
+-}
+-
+-int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
++static HICON image_to_icon(const Fl_RGB_Image *image, bool is_icon=true,
++ int hotx = 0, int hoty = 0) {
+ BITMAPV5HEADER bi;
+ HBITMAP bitmap, mask;
+ DWORD *bits;
+- HCURSOR new_cursor;
++ HICON icon;
+
++ if (!is_icon) {
+ if ((hotx < 0) || (hotx >= image->w()))
+- return 0;
++ return NULL;
+ if ((hoty < 0) || (hoty >= image->h()))
+- return 0;
++ return NULL;
++ }
+
+ memset(&bi, 0, sizeof(BITMAPV5HEADER));
+
+@@ -2120,7 +2070,7 @@
+ ReleaseDC(NULL, hdc);
+
+ if (bits == NULL)
+- return 0;
++ return NULL;
+
+ const uchar *i = (const uchar*)*image->data();
+ for (int y = 0;y < image->h();y++) {
+@@ -2149,22 +2099,206 @@
+ mask = CreateBitmap(image->w(),image->h(),1,1,NULL);
+ if (mask == NULL) {
+ DeleteObject(bitmap);
+- return 0;
++ return NULL;
+ }
+
+ ICONINFO ii;
+
+- ii.fIcon = FALSE;
++ ii.fIcon = is_icon;
+ ii.xHotspot = hotx;
+ ii.yHotspot = hoty;
+ ii.hbmMask = mask;
+ ii.hbmColor = bitmap;
+
+- new_cursor = CreateIconIndirect(&ii);
++ icon = CreateIconIndirect(&ii);
+
+ DeleteObject(bitmap);
+ DeleteObject(mask);
+
++ if (icon == NULL)
++ return NULL;
++
++ return icon;
++}
++
++////////////////////////////////////////////////////////////////
++
++static HICON default_big_icon = NULL;
++static HICON default_small_icon = NULL;
++
++const Fl_RGB_Image *find_best_icon(int ideal_width,
++ const Fl_RGB_Image *icons[], int count) {
++ const Fl_RGB_Image *best;
++
++ best = NULL;
++
++ for (int i = 0;i < count;i++) {
++ if (best == NULL)
++ best = icons[i];
++ else {
++ if (best->w() < ideal_width) {
++ if (icons[i]->w() > best->w())
++ best = icons[i];
++ } else {
++ if ((icons[i]->w() >= ideal_width) &&
++ (icons[i]->w() < best->w()))
++ best = icons[i];
++ }
++ }
++ }
++
++ return best;
++}
++
++void Fl_X::set_default_icons(const Fl_RGB_Image *icons[], int count) {
++ const Fl_RGB_Image *best_big, *best_small;
++
++ if (default_big_icon != NULL)
++ DestroyIcon(default_big_icon);
++ if (default_small_icon != NULL)
++ DestroyIcon(default_small_icon);
++
++ best_big = find_best_icon(GetSystemMetrics(SM_CXICON), icons, count);
++ best_small = find_best_icon(GetSystemMetrics(SM_CXSMICON), icons, count);
++
++ if (best_big != NULL)
++ default_big_icon = image_to_icon(best_big);
++ else
++ default_big_icon = NULL;
++
++ if (best_small != NULL)
++ default_small_icon = image_to_icon(best_small);
++ else
++ default_small_icon = NULL;
++}
++
++void Fl_X::set_default_icons(HICON big_icon, HICON small_icon) {
++ if (default_big_icon != NULL)
++ DestroyIcon(default_big_icon);
++ if (default_small_icon != NULL)
++ DestroyIcon(default_small_icon);
++
++ if (big_icon != NULL)
++ default_big_icon = CopyIcon(big_icon);
++ if (small_icon != NULL)
++ default_small_icon = CopyIcon(small_icon);
++}
++
++void Fl_X::set_icons() {
++ HICON big_icon, small_icon;
++
++ big_icon = NULL;
++ small_icon = NULL;
++
++ if (w->icon_->count) {
++ const Fl_RGB_Image *best_big, *best_small;
++
++ best_big = find_best_icon(GetSystemMetrics(SM_CXICON),
++ (const Fl_RGB_Image **)w->icon_->icons,
++ w->icon_->count);
++ best_small = find_best_icon(GetSystemMetrics(SM_CXSMICON),
++ (const Fl_RGB_Image **)w->icon_->icons,
++ w->icon_->count);
++
++ if (best_big != NULL)
++ big_icon = image_to_icon(best_big);
++ if (best_small != NULL)
++ small_icon = image_to_icon(best_small);
++ } else {
++ big_icon = default_big_icon;
++ small_icon = default_small_icon;
++ }
++
++ if (big_icon != NULL)
++ SendMessage(xid, WM_SETICON, ICON_BIG, (LPARAM)big_icon);
++ if (small_icon != NULL)
++ SendMessage(xid, WM_SETICON, ICON_SMALL, (LPARAM)small_icon);
++
++ if (w->icon_->count) {
++ if (big_icon != NULL)
++ DestroyIcon(big_icon);
++ if (small_icon != NULL)
++ DestroyIcon(small_icon);
++ }
++}
++
++void Fl_Window::default_icons(HICON big_icon, HICON small_icon) {
++ Fl_X::set_default_icons(big_icon, small_icon);
++}
++
++void Fl_Window::icons(HICON big_icon, HICON small_icon) {
++ free_icons();
++
++ if (big_icon != NULL)
++ icon_->big_icon = CopyIcon(big_icon);
++ if (small_icon != NULL)
++ icon_->small_icon = CopyIcon(small_icon);
++
++ if (i)
++ i->set_icons();
++}
++
++////////////////////////////////////////////////////////////////
++
++#ifndef IDC_HAND
++# define IDC_HAND MAKEINTRESOURCE(32649)
++#endif // !IDC_HAND
++
++int Fl_X::set_cursor(Fl_Cursor c) {
++ LPSTR n;
++ HCURSOR new_cursor;
++
++ if (c == FL_CURSOR_NONE)
++ new_cursor = NULL;
++ else {
++ switch (c) {
++ case FL_CURSOR_ARROW: n = IDC_ARROW; break;
++ case FL_CURSOR_CROSS: n = IDC_CROSS; break;
++ case FL_CURSOR_WAIT: n = IDC_WAIT; break;
++ case FL_CURSOR_INSERT: n = IDC_IBEAM; break;
++ case FL_CURSOR_HAND: n = IDC_HAND; break;
++ case FL_CURSOR_HELP: n = IDC_HELP; break;
++ case FL_CURSOR_MOVE: n = IDC_SIZEALL; break;
++ case FL_CURSOR_N:
++ case FL_CURSOR_S:
++ // FIXME: Should probably have fallbacks for these instead
++ case FL_CURSOR_NS: n = IDC_SIZENS; break;
++ case FL_CURSOR_NE:
++ case FL_CURSOR_SW:
++ // FIXME: Dito.
++ case FL_CURSOR_NESW: n = IDC_SIZENESW; break;
++ case FL_CURSOR_E:
++ case FL_CURSOR_W:
++ // FIXME: Dito.
++ case FL_CURSOR_WE: n = IDC_SIZEWE; break;
++ case FL_CURSOR_SE:
++ case FL_CURSOR_NW:
++ // FIXME: Dito.
++ case FL_CURSOR_NWSE: n = IDC_SIZENWSE; break;
++ default:
++ return 0;
++ }
++
++ new_cursor = LoadCursor(NULL, n);
++ if (new_cursor == NULL)
++ return 0;
++ }
++
++ if ((cursor != NULL) && custom_cursor)
++ DestroyIcon(cursor);
++
++ cursor = new_cursor;
++ custom_cursor = 0;
++
++ SetCursor(cursor);
++
++ return 1;
++}
++
++int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
++ HCURSOR new_cursor;
++
++ new_cursor = image_to_icon(image, false, hotx, hoty);
+ if (new_cursor == NULL)
+ return 0;
+
+diff -ur fltk-1.3.2.org/src/Fl_Window.cxx fltk-1.3.2/src/Fl_Window.cxx
+--- fltk-1.3.2.org/src/Fl_Window.cxx 2013-01-16 10:49:40.908130903 +0100
++++ fltk-1.3.2/src/Fl_Window.cxx 2013-01-16 10:49:55.557353865 +0100
+@@ -23,6 +23,7 @@
+ #include <config.h>
+ #include <FL/Fl.H>
+ #include <FL/x.H>
++#include <FL/Fl_RGB_Image.H>
+ #include <FL/Fl_Window.H>
+ #include <stdlib.h>
+ #include "flstring.h"
+@@ -45,7 +46,8 @@
+ }
+ i = 0;
+ xclass_ = 0;
+- icon_ = 0;
++ icon_ = new icon_data;
++ memset(icon_, 0, sizeof(*icon_));
+ iconlabel_ = 0;
+ resizable(0);
+ size_range_set = 0;
+@@ -264,16 +266,68 @@
+ }
+ }
+
++void Fl_Window::default_icon(const Fl_RGB_Image *icon) {
++ default_icons(&icon, 1);
++}
++
++void Fl_Window::default_icons(const Fl_RGB_Image **icons, int count) {
++ Fl_X::set_default_icons(icons, count);
++}
++
++void Fl_Window::icon(const Fl_RGB_Image *icon) {
++ icons(&icon, 1);
++}
++
++void Fl_Window::icons(const Fl_RGB_Image **icons, int count) {
++ free_icons();
++
++ if (count > 0) {
++ icon_->icons = new Fl_RGB_Image*[count];
++ icon_->count = count;
++ // FIXME: Fl_RGB_Image lacks const modifiers on methods
++ for (int i = 0;i < count;i++)
++ icon_->icons[i] = (Fl_RGB_Image*)((Fl_RGB_Image*)icons[i])->copy();
++ }
++
++ if (i)
++ i->set_icons();
++}
++
+ /** Gets the current icon window target dependent data. */
+ const void *Fl_Window::icon() const {
+- return icon_;
++ return icon_->legacy_icon;
+ }
+
+ /** Sets the current icon window target dependent data. */
+ void Fl_Window::icon(const void * ic) {
+- icon_ = ic;
++ free_icons();
++ icon_->legacy_icon = ic;
+ }
+
++void Fl_Window::free_icons() {
++ int i;
++
++ icon_->legacy_icon = 0L;
++
++ if (icon_->icons) {
++ for (i = 0;i < icon_->count;i++)
++ delete icon_->icons[i];
++ delete [] icon_->icons;
++ icon_->icons = 0L;
++ }
++
++ icon_->count = 0;
++
++#ifdef WIN32
++ if (icon_->big_icon)
++ DestroyIcon(icon_->big_icon);
++ if (icon_->small_icon)
++ DestroyIcon(icon_->small_icon);
++
++ icon_->big_icon = NULL;
++ icon_->small_icon = NULL;
++#endif
++}
+
+ //
+ // End of "$Id: Fl_Window.cxx 9706 2012-11-06 20:46:14Z matt $".
+diff -ur fltk-1.3.2.org/src/Fl_x.cxx fltk-1.3.2/src/Fl_x.cxx
+--- fltk-1.3.2.org/src/Fl_x.cxx 2013-01-16 10:49:40.912227213 +0100
++++ fltk-1.3.2/src/Fl_x.cxx 2013-01-16 10:49:55.558137113 +0100
+@@ -345,6 +345,7 @@
+ Atom fl_NET_WM_STATE;
+ Atom fl_NET_WM_STATE_FULLSCREEN;
+ Atom fl_NET_WORKAREA;
++Atom fl_NET_WM_ICON;
+
+ /*
+ X defines 32-bit-entities to have a format value of max. 32,
+@@ -709,6 +710,7 @@
+ fl_NET_WM_STATE = XInternAtom(d, "_NET_WM_STATE", 0);
+ fl_NET_WM_STATE_FULLSCREEN = XInternAtom(d, "_NET_WM_STATE_FULLSCREEN", 0);
+ fl_NET_WORKAREA = XInternAtom(d, "_NET_WORKAREA", 0);
++ fl_NET_WM_ICON = XInternAtom(d, "_NET_WM_ICON", 0);
+
+ if (sizeof(Atom) < 4)
+ atom_bits = sizeof(Atom) * 8;
+@@ -2138,12 +2140,14 @@
+ fl_show_iconic = 0;
+ showit = 0;
+ }
+- if (win->icon()) {
+- hints->icon_pixmap = (Pixmap)win->icon();
++ if (win->icon_->legacy_icon) {
++ hints->icon_pixmap = (Pixmap)win->icon_->legacy_icon;
+ hints->flags |= IconPixmapHint;
+ }
+ XSetWMHints(fl_display, xp->xid, hints);
+ XFree(hints);
++
++ xp->set_icons();
+ }
+
+ // set the window type for menu and tooltip windows to avoid animations (compiz)
+@@ -2263,6 +2267,93 @@
+
+ ////////////////////////////////////////////////////////////////
+
++static unsigned long *default_net_wm_icons = 0L;
++static size_t default_net_wm_icons_size = 0;
++
++void icons_to_property(const Fl_RGB_Image *icons[], int count,
++ unsigned long **property, size_t *len) {
++ size_t sz;
++ unsigned long *data;
++
++ sz = 0;
++ for (int i = 0;i < count;i++)
++ sz += 2 + icons[i]->w() * icons[i]->h();
++
++ // FIXME: Might want to sort the icons
++
++ *property = data = new unsigned long[sz];
++ *len = sz;
++
++ for (int i = 0;i < count;i++) {
++ const Fl_RGB_Image *image;
++
++ image = icons[i];
++
++ data[0] = image->w();
++ data[1] = image->h();
++ data += 2;
++
++ const uchar *in = (const uchar*)*image->data();
++ for (int y = 0;y < image->h();y++) {
++ for (int x = 0;x < image->w();x++) {
++ switch (image->d()) {
++ case 1:
++ *data = ( 0xff<<24) | (in[0]<<16) | (in[0]<<8) | in[0];
++ break;
++ case 2:
++ *data = (in[1]<<24) | (in[0]<<16) | (in[0]<<8) | in[0];
++ break;
++ case 3:
++ *data = ( 0xff<<24) | (in[0]<<16) | (in[1]<<8) | in[2];
++ break;
++ case 4:
++ *data = (in[3]<<24) | (in[0]<<16) | (in[1]<<8) | in[2];
++ break;
++ }
++ in += image->d();
++ data++;
++ }
++ in += image->ld();
++ }
++ }
++}
++
++void Fl_X::set_default_icons(const Fl_RGB_Image *icons[], int count) {
++ if (default_net_wm_icons) {
++ delete [] default_net_wm_icons;
++ default_net_wm_icons = 0L;
++ default_net_wm_icons_size = 0;
++ }
++
++ if (count > 0)
++ icons_to_property(icons, count,
++ &default_net_wm_icons, &default_net_wm_icons_size);
++}
++
++void Fl_X::set_icons() {
++ unsigned long *net_wm_icons;
++ size_t net_wm_icons_size;
++
++ if (w->icon_->count) {
++ icons_to_property((const Fl_RGB_Image **)w->icon_->icons, w->icon_->count,
++ &net_wm_icons, &net_wm_icons_size);
++ } else {
++ net_wm_icons = default_net_wm_icons;
++ net_wm_icons_size = default_net_wm_icons_size;
++ }
++
++ XChangeProperty (fl_display, xid, fl_NET_WM_ICON, XA_CARDINAL, 32,
++ PropModeReplace, (unsigned char*) net_wm_icons, net_wm_icons_size);
++
++ if (w->icon_->count) {
++ delete [] net_wm_icons;
++ net_wm_icons = 0L;
++ net_wm_icons_size = 0;
++ }
++}
++
++////////////////////////////////////////////////////////////////
++
+ int Fl_X::set_cursor(Fl_Cursor c) {
+ unsigned int shape;
+ Cursor xc;
--- /dev/null
+diff -ur fltk-1.3.0r9110.org/src/Fl_win32.cxx fltk-1.3.0r9110/src/Fl_win32.cxx
+--- fltk-1.3.0r9110.org/src/Fl_win32.cxx 2012-06-17 19:42:02.169422400 +0200
++++ fltk-1.3.0r9110/src/Fl_win32.cxx 2012-06-17 19:43:38.286031455 +0200
+@@ -543,6 +543,37 @@
+ const char* GetValue() const { return(out); }
+ };
+
++void fl_update_clipboard(void) {
++ Fl_Window *w1 = Fl::first_window();
++ if (!w1)
++ return;
++
++ HWND hwnd = fl_xid(w1);
++
++ if (!OpenClipboard(hwnd))
++ return;
++
++ EmptyClipboard();
++
++ int utf16_len = fl_utf8toUtf16(fl_selection_buffer[1],
++ fl_selection_length[1], 0, 0);
++
++ HGLOBAL hMem = GlobalAlloc(GHND, utf16_len * 2 + 2); // moveable and zero'ed mem alloc.
++ LPVOID memLock = GlobalLock(hMem);
++
++ fl_utf8toUtf16(fl_selection_buffer[1], fl_selection_length[1],
++ (unsigned short*) memLock, utf16_len + 1);
++
++ GlobalUnlock(hMem);
++ SetClipboardData(CF_UNICODETEXT, hMem);
++
++ CloseClipboard();
++
++ // In case Windows managed to lob of a WM_DESTROYCLIPBOARD during
++ // the above.
++ fl_i_own_selection[1] = 1;
++}
++
+ // call this when you create a selection:
+ void Fl::copy(const char *stuff, int len, int clipboard) {
+ if (!stuff || len<0) return;
+@@ -560,25 +591,9 @@
+ memcpy(fl_selection_buffer[clipboard], stuff, len);
+ fl_selection_buffer[clipboard][len] = 0; // needed for direct paste
+ fl_selection_length[clipboard] = len;
+- if (clipboard) {
+- // set up for "delayed rendering":
+- if (OpenClipboard(NULL)) {
+- // if the system clipboard works, use it
+- int utf16_len = fl_utf8toUtf16(fl_selection_buffer[clipboard], fl_selection_length[clipboard], 0, 0);
+- EmptyClipboard();
+- HGLOBAL hMem = GlobalAlloc(GHND, utf16_len * 2 + 2); // moveable and zero'ed mem alloc.
+- LPVOID memLock = GlobalLock(hMem);
+- fl_utf8toUtf16(fl_selection_buffer[clipboard], fl_selection_length[clipboard], (unsigned short*) memLock, utf16_len + 1);
+- GlobalUnlock(hMem);
+- SetClipboardData(CF_UNICODETEXT, hMem);
+- CloseClipboard();
+- GlobalFree(hMem);
+- fl_i_own_selection[clipboard] = 0;
+- } else {
+- // only if it fails, instruct paste() to use the internal buffers
+- fl_i_own_selection[clipboard] = 1;
+- }
+- }
++ fl_i_own_selection[clipboard] = 1;
++ if (clipboard)
++ fl_update_clipboard();
+ }
+
+ // Call this when a "paste" operation happens:
+@@ -1307,33 +1322,6 @@
+ fl_i_own_selection[1] = 0;
+ return 1;
+
+- case WM_RENDERALLFORMATS:
+- fl_i_own_selection[1] = 0;
+- // Windoze seems unhappy unless I do these two steps. Documentation
+- // seems to vary on whether opening the clipboard is necessary or
+- // is in fact wrong:
+- CloseClipboard();
+- OpenClipboard(NULL);
+- // fall through...
+- case WM_RENDERFORMAT: {
+- HANDLE h;
+-
+-// int l = fl_utf_nb_char((unsigned char*)fl_selection_buffer[1], fl_selection_length[1]);
+- int l = fl_utf8toUtf16(fl_selection_buffer[1], fl_selection_length[1], NULL, 0); // Pass NULL buffer to query length required
+- h = GlobalAlloc(GHND, (l+1) * sizeof(unsigned short));
+- if (h) {
+- unsigned short *g = (unsigned short*) GlobalLock(h);
+-// fl_utf2unicode((unsigned char *)fl_selection_buffer[1], fl_selection_length[1], (xchar*)g);
+- l = fl_utf8toUtf16(fl_selection_buffer[1], fl_selection_length[1], g, (l+1));
+- g[l] = 0;
+- GlobalUnlock(h);
+- SetClipboardData(CF_UNICODETEXT, h);
+- }
+-
+- // Windoze also seems unhappy if I don't do this. Documentation very
+- // unclear on what is correct:
+- if (fl_msg.message == WM_RENDERALLFORMATS) CloseClipboard();
+- return 1;}
+ case WM_DISPLAYCHANGE: // occurs when screen configuration (number, position) changes
+ Fl::call_screen_init();
+ Fl::handle(FL_SCREEN_CONFIGURATION_CHANGED, NULL);
+diff -ur fltk-1.3.0r9110.org/src/Fl.cxx fltk-1.3.0r9110/src/Fl.cxx
+--- fltk-1.3.0r9110.org/src/Fl.cxx 2012-06-17 19:42:02.173422595 +0200
++++ fltk-1.3.0r9110/src/Fl.cxx 2012-06-17 19:42:02.317429497 +0200
+@@ -1420,7 +1420,9 @@
+ ////////////////////////////////////////////////////////////////
+ // hide() destroys the X window, it does not do unmap!
+
+-#if !defined(WIN32) && USE_XFT
++#if defined(WIN32)
++extern void fl_update_clipboard(void);
++#elif USE_XFT
+ extern void fl_destroy_xft_draw(Window);
+ #endif
+
+@@ -1467,14 +1469,8 @@
+ #if defined(WIN32)
+ // this little trick keeps the current clipboard alive, even if we are about
+ // to destroy the window that owns the selection.
+- if (GetClipboardOwner()==ip->xid) {
+- Fl_Window *w1 = Fl::first_window();
+- if (w1 && OpenClipboard(fl_xid(w1))) {
+- EmptyClipboard();
+- SetClipboardData(CF_TEXT, NULL);
+- CloseClipboard();
+- }
+- }
++ if (GetClipboardOwner()==ip->xid)
++ fl_update_clipboard();
+ // Send a message to myself so that I'll get out of the event loop...
+ PostMessage(ip->xid, WM_APP, 0, 0);
+ if (ip->private_dc) fl_release_dc(ip->xid, ip->private_dc);
--- /dev/null
+diff -urp fltk-1.3.2.org/FL/Fl_Window.H fltk-1.3.2/FL/Fl_Window.H
+--- fltk-1.3.2.org/FL/Fl_Window.H 2013-01-16 10:52:33.017228122 +0100
++++ fltk-1.3.2/FL/Fl_Window.H 2013-01-16 10:52:47.876478968 +0100
+@@ -54,7 +54,7 @@ class Fl_RGB_Image;
+ class FL_EXPORT Fl_Window : public Fl_Group {
+
+ static char *default_xclass_;
+- // Note: we must use separate statements for each of the following 4 variables,
++ // Note: we must use separate statements for each of the following 8 variables,
+ // with the static attribute, otherwise MS VC++ 2008/2010 complains :-(
+ // AlbrechtS 04/2012
+ #if FLTK_ABI_VERSION < 10301
+@@ -73,6 +73,22 @@ class FL_EXPORT Fl_Window : public Fl_Gr
+ static // when these members are static, ABI compatibility with 1.3.0 is respected
+ #endif
+ int no_fullscreen_h;
++#if FLTK_ABI_VERSION < 10302
++ static // when these members are static, ABI compatibility with 1.3.0 is respected
++#endif
++ int fullscreen_screen_top;
++#if FLTK_ABI_VERSION < 10302
++ static // when these members are static, ABI compatibility with 1.3.0 is respected
++#endif
++ int fullscreen_screen_bottom;
++#if FLTK_ABI_VERSION < 10302
++ static // when these members are static, ABI compatibility with 1.3.0 is respected
++#endif
++ int fullscreen_screen_left;
++#if FLTK_ABI_VERSION < 10302
++ static // when these members are static, ABI compatibility with 1.3.0 is respected
++#endif
++ int fullscreen_screen_right;
+
+ friend class Fl_X;
+ Fl_X *i; // points at the system-specific stuff
+@@ -430,13 +446,15 @@ public:
+ */
+ void show(int argc, char **argv);
+ /**
+- Makes the window completely fill the screen, without any window
+- manager border visible. You must use fullscreen_off() to undo
+- this.
++ Makes the window completely fill one or more screens, without any
++ window manager border visible. You must use fullscreen_off() to
++ undo this.
+
+ \note On some platforms, this can result in the keyboard being
+ grabbed. The window may also be recreated, meaning hide() and
+ show() will be called.
++
++ \see void Fl_Window::fullscreen_screens()
+ */
+ void fullscreen();
+ /**
+@@ -453,6 +471,17 @@ public:
+ */
+ unsigned int fullscreen_active() const { return flags() & FULLSCREEN; }
+ /**
++ Sets which screens should be used when this window is in fullscreen
++ mode. The window will be resized to the top of the screen with index
++ \p top, the bottom of the screen with index \p bottom, etc.
++
++ If this method is never called, or if any argument is < 0, then the
++ window will be resized to fill the screen it is currently on.
++
++ \see void Fl_Window::fullscreen()
++ */
++ void fullscreen_screens(int top, int bottom, int left, int right);
++ /**
+ Iconifies the window. If you call this when shown() is false
+ it will show() it as an icon. If the window is already
+ iconified this does nothing.
+diff -urp fltk-1.3.2.org/FL/win32.H fltk-1.3.2/FL/win32.H
+--- fltk-1.3.2.org/FL/win32.H 2013-01-16 10:52:33.017228122 +0100
++++ fltk-1.3.2/FL/win32.H 2013-01-16 10:52:47.876478968 +0100
+@@ -80,6 +80,7 @@ public:
+ static Fl_X* i(const Fl_Window* w) {return w->i;}
+ static int fake_X_wm(const Fl_Window* w,int &X, int &Y,
+ int &bt,int &bx,int &by);
++ void make_fullscreen(int X, int Y, int W, int H);
+ void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
+ void flush() {w->flush();}
+ void set_minmax(LPMINMAXINFO minmax);
+diff -urp fltk-1.3.2.org/src/Fl_cocoa.mm fltk-1.3.2/src/Fl_cocoa.mm
+--- fltk-1.3.2.org/src/Fl_cocoa.mm 2013-01-16 10:52:33.014229574 +0100
++++ fltk-1.3.2/src/Fl_cocoa.mm 2013-01-16 10:52:47.877480606 +0100
+@@ -2438,9 +2438,32 @@ void Fl_X::make(Fl_Window* w)
+
+ NSRect crect;
+ if (w->fullscreen_active()) {
+- int sx, sy, sw, sh;
+- Fl::screen_xywh(sx, sy, sw, sh, w->x(), w->y(), w->w(), w->h());
+- w->resize(sx, sy, sw, sh);
++ int top, bottom, left, right;
++ int sx, sy, sw, sh, X, Y, W, H;
++
++ top = w->fullscreen_screen_top;
++ bottom = w->fullscreen_screen_bottom;
++ left = w->fullscreen_screen_left;
++ right = w->fullscreen_screen_right;
++
++ if ((top < 0) || (bottom < 0) || (left < 0) || (right < 0)) {
++ top = Fl::screen_num(w->x(), w->y(), w->w(), w->h());
++ bottom = top;
++ left = top;
++ right = top;
++ }
++
++ Fl::screen_xywh(sx, sy, sw, sh, top);
++ Y = sy;
++ Fl::screen_xywh(sx, sy, sw, sh, bottom);
++ H = sy + sh - Y;
++ Fl::screen_xywh(sx, sy, sw, sh, left);
++ X = sx;
++ Fl::screen_xywh(sx, sy, sw, sh, right);
++ W = sx + sw - X;
++
++ w->resize(X, Y, W, H);
++
+ winstyle = NSBorderlessWindowMask;
+ winlevel = NSStatusWindowLevel;
+ }
+diff -urp fltk-1.3.2.org/src/Fl_win32.cxx fltk-1.3.2/src/Fl_win32.cxx
+--- fltk-1.3.2.org/src/Fl_win32.cxx 2013-01-16 10:52:33.019230734 +0100
++++ fltk-1.3.2/src/Fl_win32.cxx 2013-01-16 10:52:47.878480504 +0100
+@@ -1493,7 +1493,6 @@ int Fl_X::fake_X_wm(const Fl_Window* w,i
+ Y+=yoff;
+
+ if (w->fullscreen_active()) {
+- X = Y = 0;
+ bx = by = bt = 0;
+ }
+
+@@ -1547,19 +1546,42 @@ void Fl_Window::resize(int X,int Y,int W
+ }
+ }
+
+-static void make_fullscreen(Fl_Window *w, Window xid, int X, int Y, int W, int H) {
++void Fl_X::make_fullscreen(int X, int Y, int W, int H) {
++ int top, bottom, left, right;
+ int sx, sy, sw, sh;
+- Fl::screen_xywh(sx, sy, sw, sh, X, Y, W, H);
++
++ top = w->fullscreen_screen_top;
++ bottom = w->fullscreen_screen_bottom;
++ left = w->fullscreen_screen_left;
++ right = w->fullscreen_screen_right;
++
++ if ((top < 0) || (bottom < 0) || (left < 0) || (right < 0)) {
++ top = Fl::screen_num(X, Y, W, H);
++ bottom = top;
++ left = top;
++ right = top;
++ }
++
++ Fl::screen_xywh(sx, sy, sw, sh, top);
++ Y = sy;
++ Fl::screen_xywh(sx, sy, sw, sh, bottom);
++ H = sy + sh - Y;
++ Fl::screen_xywh(sx, sy, sw, sh, left);
++ X = sx;
++ Fl::screen_xywh(sx, sy, sw, sh, right);
++ W = sx + sw - X;
++
+ DWORD flags = GetWindowLong(xid, GWL_STYLE);
+ flags = flags & ~(WS_THICKFRAME|WS_CAPTION);
+ SetWindowLong(xid, GWL_STYLE, flags);
++
+ // SWP_NOSENDCHANGING is so that we can override size limits
+- SetWindowPos(xid, HWND_TOP, sx, sy, sw, sh, SWP_NOSENDCHANGING | SWP_FRAMECHANGED);
++ SetWindowPos(xid, HWND_TOP, X, Y, W, H, SWP_NOSENDCHANGING | SWP_FRAMECHANGED);
+ }
+
+ void Fl_Window::fullscreen_x() {
+ _set_fullscreen();
+- make_fullscreen(this, fl_xid(this), x(), y(), w(), h());
++ i->make_fullscreen(x(), y(), w(), h());
+ Fl::handle(FL_FULLSCREEN, this);
+ }
+
+@@ -1814,8 +1836,8 @@ Fl_X* Fl_X::make(Fl_Window* w) {
+ monitor the window was placed on. */
+ RECT rect;
+ GetWindowRect(x->xid, &rect);
+- make_fullscreen(w, x->xid, rect.left, rect.top,
+- rect.right - rect.left, rect.bottom - rect.top);
++ x->make_fullscreen(rect.left, rect.top,
++ rect.right - rect.left, rect.bottom - rect.top);
+ }
+
+ x->next = Fl_X::first;
+diff -urp fltk-1.3.2.org/src/Fl_Window_fullscreen.cxx fltk-1.3.2/src/Fl_Window_fullscreen.cxx
+--- fltk-1.3.2.org/src/Fl_Window_fullscreen.cxx 2012-11-06 21:46:14.000000000 +0100
++++ fltk-1.3.2/src/Fl_Window_fullscreen.cxx 2013-01-16 10:52:47.879480608 +0100
+@@ -36,6 +36,10 @@ int Fl_Window::no_fullscreen_x = 0;
+ int Fl_Window::no_fullscreen_y = 0;
+ int Fl_Window::no_fullscreen_w = 0;
+ int Fl_Window::no_fullscreen_h = 0;
++int Fl_Window::fullscreen_screen_top = -1;
++int Fl_Window::fullscreen_screen_bottom = -1;
++int Fl_Window::fullscreen_screen_left = -1;
++int Fl_Window::fullscreen_screen_right = -1;
+ #endif
+
+ void Fl_Window::border(int b) {
+@@ -95,6 +99,23 @@ void Fl_Window::fullscreen_off() {
+ fullscreen_off(no_fullscreen_x, no_fullscreen_y, no_fullscreen_w, no_fullscreen_h);
+ }
+
++void Fl_Window::fullscreen_screens(int top, int bottom, int left, int right) {
++ if ((top < 0) || (bottom < 0) || (left < 0) || (right < 0)) {
++ fullscreen_screen_top = -1;
++ fullscreen_screen_bottom = -1;
++ fullscreen_screen_left = -1;
++ fullscreen_screen_right = -1;
++ } else {
++ fullscreen_screen_top = top;
++ fullscreen_screen_bottom = bottom;
++ fullscreen_screen_left = left;
++ fullscreen_screen_right = right;
++ }
++
++ if (shown() && (flags() & Fl_Widget::FULLSCREEN))
++ fullscreen_x();
++}
++
+
+ //
+ // End of "$Id: Fl_Window_fullscreen.cxx 9706 2012-11-06 20:46:14Z matt $".
+diff -urp fltk-1.3.2.org/src/Fl_x.cxx fltk-1.3.2/src/Fl_x.cxx
+--- fltk-1.3.2.org/src/Fl_x.cxx 2013-01-16 10:52:33.020228202 +0100
++++ fltk-1.3.2/src/Fl_x.cxx 2013-01-16 10:52:47.880480556 +0100
+@@ -344,6 +344,7 @@ Atom fl_NET_WM_ICON_NAME; // utf8 aware
+ Atom fl_NET_SUPPORTING_WM_CHECK;
+ Atom fl_NET_WM_STATE;
+ Atom fl_NET_WM_STATE_FULLSCREEN;
++Atom fl_NET_WM_FULLSCREEN_MONITORS;
+ Atom fl_NET_WORKAREA;
+ Atom fl_NET_WM_ICON;
+
+@@ -709,6 +710,7 @@ void fl_open_display(Display* d) {
+ fl_NET_SUPPORTING_WM_CHECK = XInternAtom(d, "_NET_SUPPORTING_WM_CHECK", 0);
+ fl_NET_WM_STATE = XInternAtom(d, "_NET_WM_STATE", 0);
+ fl_NET_WM_STATE_FULLSCREEN = XInternAtom(d, "_NET_WM_STATE_FULLSCREEN", 0);
++ fl_NET_WM_FULLSCREEN_MONITORS = XInternAtom(d, "_NET_WM_FULLSCREEN_MONITORS", 0);
+ fl_NET_WORKAREA = XInternAtom(d, "_NET_WORKAREA", 0);
+ fl_NET_WM_ICON = XInternAtom(d, "_NET_WM_ICON", 0);
+
+@@ -1872,22 +1874,30 @@ void Fl_Window::resize(int X,int Y,int W
+ #define _NET_WM_STATE_ADD 1 /* add/set property */
+ #define _NET_WM_STATE_TOGGLE 2 /* toggle property */
+
+-static void send_wm_state_event(Window wnd, int add, Atom prop) {
++static void send_wm_event(Window wnd, Atom message,
++ unsigned long d0, unsigned long d1=0,
++ unsigned long d2=0, unsigned long d3=0,
++ unsigned long d4=0) {
+ XEvent e;
+ e.xany.type = ClientMessage;
+ e.xany.window = wnd;
+- e.xclient.message_type = fl_NET_WM_STATE;
++ e.xclient.message_type = message;
+ e.xclient.format = 32;
+- e.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
+- e.xclient.data.l[1] = prop;
+- e.xclient.data.l[2] = 0;
+- e.xclient.data.l[3] = 0;
+- e.xclient.data.l[4] = 0;
++ e.xclient.data.l[0] = d0;
++ e.xclient.data.l[1] = d1;
++ e.xclient.data.l[2] = d2;
++ e.xclient.data.l[3] = d3;
++ e.xclient.data.l[4] = d4;
+ XSendEvent(fl_display, RootWindow(fl_display, fl_screen),
+ 0, SubstructureNotifyMask | SubstructureRedirectMask,
+ &e);
+ }
+
++static void send_wm_state_event(Window wnd, int add, Atom prop) {
++ send_wm_event(wnd, fl_NET_WM_STATE,
++ add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE, prop);
++}
++
+ int Fl_X::ewmh_supported() {
+ static int result = -1;
+
+@@ -1911,6 +1921,22 @@ int Fl_X::ewmh_supported() {
+ /* Change an existing window to fullscreen */
+ void Fl_Window::fullscreen_x() {
+ if (Fl_X::ewmh_supported()) {
++ int top, bottom, left, right;
++
++ top = fullscreen_screen_top;
++ bottom = fullscreen_screen_bottom;
++ left = fullscreen_screen_left;
++ right = fullscreen_screen_right;
++
++ if ((top < 0) || (bottom < 0) || (left < 0) || (right < 0)) {
++ top = Fl::screen_num(x(), y(), w(), h());
++ bottom = top;
++ left = top;
++ right = top;
++ }
++
++ send_wm_event(fl_xid(this), fl_NET_WM_FULLSCREEN_MONITORS,
++ top, bottom, left, right);
+ send_wm_state_event(fl_xid(this), 1, fl_NET_WM_STATE_FULLSCREEN);
+ } else {
+ _set_fullscreen();
+@@ -1997,7 +2023,7 @@ void Fl_X::make_xid(Fl_Window* win, XVis
+ // force the window to be on-screen. Usually the X window manager
+ // does this, but a few don't, so we do it here for consistency:
+ int scr_x, scr_y, scr_w, scr_h;
+- Fl::screen_xywh(scr_x, scr_y, scr_w, scr_h, X, Y);
++ Fl::screen_xywh(scr_x, scr_y, scr_w, scr_h, X, Y, W, H);
+
+ if (win->border()) {
+ // ensure border is on screen:
+@@ -2026,6 +2052,23 @@ void Fl_X::make_xid(Fl_Window* win, XVis
+ return;
+ }
+
++ // Compute which screen(s) we should be on if we want to go fullscreen
++ int fullscreen_top, fullscreen_bottom, fullscreen_left, fullscreen_right;
++
++ fullscreen_top = win->fullscreen_screen_top;
++ fullscreen_bottom = win->fullscreen_screen_bottom;
++ fullscreen_left = win->fullscreen_screen_left;
++ fullscreen_right = win->fullscreen_screen_right;
++
++ if ((fullscreen_top < 0) || (fullscreen_bottom < 0) ||
++ (fullscreen_left < 0) || (fullscreen_right < 0)) {
++ fullscreen_top = Fl::screen_num(X, Y, W, H);
++ fullscreen_bottom = fullscreen_top;
++ fullscreen_left = fullscreen_top;
++ fullscreen_right = fullscreen_top;
++ }
++
++
+ ulong root = win->parent() ?
+ fl_xid(win->window()) : RootWindow(fl_display, fl_screen);
+
+@@ -2049,9 +2092,17 @@ void Fl_X::make_xid(Fl_Window* win, XVis
+ // border, and cannot grab without an existing window. Besides,
+ // there is no clear_override().
+ if (win->flags() & Fl_Widget::FULLSCREEN && !Fl_X::ewmh_supported()) {
++ int sx, sy, sw, sh;
+ attr.override_redirect = 1;
+ mask |= CWOverrideRedirect;
+- Fl::screen_xywh(X, Y, W, H, X, Y, W, H);
++ Fl::screen_xywh(sx, sy, sw, sh, fullscreen_left);
++ X = sx;
++ Fl::screen_xywh(sx, sy, sw, sh, fullscreen_right);
++ W = sx + sw - X;
++ Fl::screen_xywh(sx, sy, sw, sh, fullscreen_top);
++ Y = sy;
++ Fl::screen_xywh(sx, sy, sw, sh, fullscreen_bottom);
++ H = sy + sh - Y;
+ }
+
+ if (fl_background_pixel >= 0) {
+@@ -2122,6 +2173,13 @@ void Fl_X::make_xid(Fl_Window* win, XVis
+
+ // If asked for, create fullscreen
+ if (win->flags() & Fl_Widget::FULLSCREEN && Fl_X::ewmh_supported()) {
++ unsigned long data[4];
++ data[0] = fullscreen_top;
++ data[1] = fullscreen_bottom;
++ data[2] = fullscreen_left;
++ data[3] = fullscreen_right;
++ XChangeProperty (fl_display, xp->xid, fl_NET_WM_FULLSCREEN_MONITORS, XA_ATOM, 32,
++ PropModeReplace, (unsigned char*) data, 4);
+ XChangeProperty (fl_display, xp->xid, fl_NET_WM_STATE, XA_ATOM, 32,
+ PropModeAppend, (unsigned char*) &fl_NET_WM_STATE_FULLSCREEN, 1);
+ }
+diff -urp fltk-1.3.2.org/test/fullscreen.cxx fltk-1.3.2/test/fullscreen.cxx
+--- fltk-1.3.2.org/test/fullscreen.cxx 2012-06-14 17:09:46.000000000 +0200
++++ fltk-1.3.2/test/fullscreen.cxx 2013-01-16 10:52:47.881104801 +0100
+@@ -127,7 +127,7 @@ class fullscreen_window : public Fl_Sing
+ fullscreen_window(int W, int H, const char *t=0);
+ int handle (int e);
+ Fl_Toggle_Light_Button *b3;
+-
++ Fl_Toggle_Light_Button *b4;
+ };
+
+ fullscreen_window::fullscreen_window(int W, int H, const char *t) : Fl_Single_Window(W, H, t) {
+@@ -170,23 +170,54 @@ void border_cb(Fl_Widget *o, void *p) {
+ #endif
+ }
+
+-int px,py,pw,ph;
+ Fl_Button *border_button;
+ void fullscreen_cb(Fl_Widget *o, void *p) {
+ Fl_Window *w = (Fl_Window *)p;
+ int d = ((Fl_Button *)o)->value();
+ if (d) {
+- px = w->x();
+- py = w->y();
+- pw = w->w();
+- ph = w->h();
++ if (((fullscreen_window*)w)->b4->value()) {
++ int top, bottom, left, right;
++ int top_y, bottom_y, left_x, right_x;
++
++ int sx, sy, sw, sh;
++
++ top = bottom = left = right = 0;
++
++ Fl::screen_xywh(sx, sy, sw, sh, 0);
++ top_y = sy;
++ bottom_y = sy + sh;
++ left_x = sx;
++ right_x = sx + sw;
++
++ for (int i = 1;i < Fl::screen_count();i++) {
++ Fl::screen_xywh(sx, sy, sw, sh, i);
++ if (sy < top_y) {
++ top = i;
++ top_y = sy;
++ }
++ if ((sy + sh) > bottom_y) {
++ bottom = i;
++ bottom_y = sy + sh;
++ }
++ if (sx < left_x) {
++ left = i;
++ left_x = sx;
++ }
++ if ((sx + sw) > right_x) {
++ right = i;
++ right_x = sx + sw;
++ }
++ }
++
++ w->fullscreen_screens(top, bottom, left, right);
++ } else {
++ w->fullscreen_screens(-1, -1, -1, -1);
++ }
+ w->fullscreen();
+- w->override();
+ #ifndef WIN32 // update our border state in case border was turned off
+ border_button->value(w->border());
+ #endif
+ } else {
+- //w->fullscreen_off(px,py,pw,ph);
+ w->fullscreen_off();
+ }
+ }
+@@ -219,7 +250,7 @@ void exit_cb(Fl_Widget *, void *) {
+ exit(0);
+ }
+
+-#define NUMB 7
++#define NUMB 8
+
+ int twowindow = 0;
+ int initfull = 0;
+@@ -284,6 +315,9 @@ int main(int argc, char **argv) {
+ window.b3->callback(fullscreen_cb,w);
+ y+=30;
+
++ window.b4 = new Fl_Toggle_Light_Button(50,y,window.w()-60,30,"All Screens");
++ y+=30;
++
+ Fl_Button eb(50,y,window.w()-60,30,"Exit");
+ eb.callback(exit_cb);
+ y+=30;
--- /dev/null
+diff -ur fltk-1.3.0r9293.org/src/Fl_win32.cxx fltk-1.3.0r9293/src/Fl_win32.cxx
+--- fltk-1.3.0r9293.org/src/Fl_win32.cxx 2012-06-18 09:07:56.522314557 +0200
++++ fltk-1.3.0r9293/src/Fl_win32.cxx 2012-06-18 09:08:07.392836285 +0200
+@@ -87,6 +87,8 @@
+ static Fl_Display_Device fl_gdi_display(&fl_gdi_driver);
+ Fl_Display_Device *Fl_Display_Device::_display = &fl_gdi_display; // the platform display
+
++bool use_simple_keyboard = false;
++
+ // dynamic wsock dll handling api:
+ #if defined(__CYGWIN__) && !defined(SOCKET)
+ # define SOCKET int
+@@ -120,6 +122,8 @@
+ * size and link dependencies.
+ */
+ static HMODULE s_imm_module = 0;
++typedef BOOL (WINAPI* flTypeImmAssociateContextEx)(HWND, HIMC, DWORD);
++static flTypeImmAssociateContextEx flImmAssociateContextEx = 0;
+ typedef HIMC (WINAPI* flTypeImmGetContext)(HWND);
+ static flTypeImmGetContext flImmGetContext = 0;
+ typedef BOOL (WINAPI* flTypeImmSetCompositionWindow)(HIMC, LPCOMPOSITIONFORM);
+@@ -135,6 +139,7 @@
+ if (!s_imm_module)
+ Fl::fatal("FLTK Lib Error: IMM32.DLL file not found!\n\n"
+ "Please check your input method manager library accessibility.");
++ flImmAssociateContextEx = (flTypeImmAssociateContextEx)GetProcAddress(s_imm_module, "ImmAssociateContextEx");
+ flImmGetContext = (flTypeImmGetContext)GetProcAddress(s_imm_module, "ImmGetContext");
+ flImmSetCompositionWindow = (flTypeImmSetCompositionWindow)GetProcAddress(s_imm_module, "ImmSetCompositionWindow");
+ flImmReleaseContext = (flTypeImmReleaseContext)GetProcAddress(s_imm_module, "ImmReleaseContext");
+@@ -413,7 +418,12 @@
+ }
+ }
+
+- TranslateMessage(&fl_msg);
++ // Don't bother with key to character translation as we do
++ // it manually for simpley keyboard widgets. In fact, calling
++ // TranslateMessage() just makes it more difficult as it sets
++ // a bunch of internal state.
++ if (!use_simple_keyboard)
++ TranslateMessage(&fl_msg);
+ DispatchMessageW(&fl_msg);
+ have_message = PeekMessageW(&fl_msg, NULL, 0, 0, PM_REMOVE);
+ }
+@@ -638,6 +648,49 @@
+ }
+ }
+
++void fl_update_focus(void)
++{
++ Fl_Widget *focus;
++ Fl_Window *win;
++
++ get_imm_module();
++
++ focus = Fl::grab();
++ if (!focus)
++ focus = Fl::focus();
++ if (!focus)
++ return;
++
++ // Grabs are special in that events are sent to the first
++ // available window
++ if (focus == Fl::grab())
++ win = Fl::first_window();
++ else {
++ win = focus->as_window();
++ if (!win)
++ win = focus->window();
++ }
++
++ if (!win) {
++ Fl::warning("Cannot find window for widget receiving focus");
++ return;
++ }
++
++ // No Win32 window created yet
++ if (!Fl_X::i(win) || !fl_xid(win))
++ return;
++
++ if (focus->simple_keyboard()) {
++ use_simple_keyboard = true;
++ if (flImmGetContext(fl_xid(win)) != 0)
++ flImmAssociateContextEx(fl_xid(win), 0, 0);
++ } else {
++ use_simple_keyboard = false;
++ if (flImmGetContext(fl_xid(win)) == 0)
++ flImmAssociateContextEx(fl_xid(win), 0, IACE_DEFAULT);
++ }
++}
++
+ HWND fl_capture;
+
+ static int mouse_event(Fl_Window *window, int what, int button,
+@@ -785,6 +838,27 @@
+ return extended ? extendedlut[vk] : vklut[vk];
+ }
+
++static xchar msdead2fltk(xchar in)
++{
++ switch (in) {
++ case 0x0060: // GRAVE ACCENT
++ return 0x0300; // COMBINING GRAVE ACCENT
++ case 0x00b4: // ACUTE ACCENT
++ return 0x0301; // COMBINING ACUTE ACCENT
++ case 0x005e: // CIRCUMFLEX ACCENT
++ return 0x0302; // COMBINING CIRCUMFLEX ACCENT
++ case 0x007e: // TILDE
++ return 0x0303; // COMBINING TILDE
++ case 0x00a8: // DIAERESIS
++ return 0x0308; // COMBINING DIAERESIS
++ // FIXME: Windows dead key behaviour isn't documented and I don't have
++ // any more keyboards to test with...
++ }
++
++ // hope that Windows gave us something proper to begin with
++ return in;
++}
++
+ #if USE_COLORMAP
+ extern HPALETTE fl_select_palette(void); // in fl_color_win32.cxx
+ #endif
+@@ -846,6 +920,8 @@
+ //fl_msg.pt = ???
+ //fl_msg.lPrivate = ???
+
++ MSG fl_orig_msg = fl_msg;
++
+ Fl_Window *window = fl_find(hWnd);
+
+ if (window) switch (uMsg) {
+@@ -1025,23 +1101,82 @@
+ if (GetKeyState(VK_SCROLL)) state |= FL_SCROLL_LOCK;
+ Fl::e_state = state;
+ static char buffer[1024];
+- if (uMsg == WM_CHAR || uMsg == WM_SYSCHAR) {
+
++ if (use_simple_keyboard) {
++ BYTE keystate[256];
++ WCHAR wbuf[8];
++ int ret;
++
++ // I'm not sure if we ever get WM_CHAR (& friends) without an initial
++ // WM_KEYDOWN (& friends), but if we do then we should not send such
++ // side band events to simple keyboard widgets.
++ if ((fl_orig_msg.message != WM_KEYDOWN) &&
++ (fl_orig_msg.message != WM_SYSKEYDOWN) &&
++ (fl_orig_msg.message != WM_KEYUP) &&
++ (fl_orig_msg.message != WM_SYSKEYUP))
++ break;
++
++ GetKeyboardState(keystate);
++
++ // Pressing Ctrl wreaks havoc with the symbol lookup, so turn that off.
++ // But AltGr shows up as Ctrl+Alt in Windows, so keep Ctrl if Alt is
++ // active.
++ if (!(keystate[VK_MENU] & 0x80))
++ keystate[VK_CONTROL] = keystate[VK_LCONTROL] = keystate[VK_RCONTROL] = 0;
++
++ // We cannot inspect or modify Windows' internal state of the keyboard
++ // so we have to try to infer information from ToUnicode() and wedge
++ // things into a known state.
++ for (int i = 0;i < 2;i++) {
++ ret = ToUnicode(fl_orig_msg.wParam, 0, keystate, wbuf,
++ sizeof(wbuf)/sizeof(wbuf[0]), 0);
++
++ // No symbol for this key (or unexpected length)
++ if ((ret == 0) || (ret < -1)) {
++ buffer[0] = 0;
++ Fl::e_length = 0;
++ break;
++ }
++
++ // A dead key. Convert this to a Unicode combining character so
++ // that the application can tell the difference between dead and
++ // normal keys.
++ if (ret == -1) {
++ xchar u = (xchar) msdead2fltk(wbuf[0]);
++ Fl::e_length = fl_utf8fromwc(buffer, 1024, &u, 1);
++ buffer[Fl::e_length] = 0;
++ break;
++ }
++
++ // If we have two characters (or more) from ToUnicode(), that's
++ // an invalid sequence. One character chould mean a proper symbol,
++ // or it could mean a composed one. In both cases we need to call
++ // ToUnicode() again to get something sane.
++ if (i == 0)
++ continue;
++
++ // We should now have something sane. Give whatever we have to the
++ // application.
++ Fl::e_length = fl_utf8fromwc(buffer, 1024, wbuf, ret);
++ buffer[Fl::e_length] = 0;
++ }
++ } else if (uMsg == WM_CHAR || uMsg == WM_SYSCHAR) {
+ xchar u = (xchar) wParam;
+ // Fl::e_length = fl_unicode2utf(&u, 1, buffer);
+ Fl::e_length = fl_utf8fromwc(buffer, 1024, &u, 1);
+ buffer[Fl::e_length] = 0;
++ } else {
++ buffer[0] = 0;
++ Fl::e_length = 0;
++ }
+
+-
+- } else if (Fl::e_keysym >= FL_KP && Fl::e_keysym <= FL_KP_Last) {
+- if (state & FL_NUM_LOCK) {
+- // Convert to regular keypress...
+- buffer[0] = Fl::e_keysym-FL_KP;
+- Fl::e_length = 1;
+- } else {
+- // Convert to special keypress...
+- buffer[0] = 0;
+- Fl::e_length = 0;
++ // The keypad area is a bit odd in that we need to change the keysym
++ // to properly indicate what the user meant, unlike other keys where
++ // we normally change the text and keep keysym stable.
++ if (Fl::e_keysym >= FL_KP && Fl::e_keysym <= FL_KP_Last) {
++ // The initial mapping tables give us a keysym that corresponds to
++ // numlock being on, so we only do something when it is off.
++ if (!(state & FL_NUM_LOCK)) {
+ switch (Fl::e_keysym) {
+ case FL_KP + '0' :
+ Fl::e_keysym = FL_Insert;
+@@ -1073,30 +1208,10 @@
+ case FL_KP + '.' :
+ Fl::e_keysym = FL_Delete;
+ break;
+- case FL_KP + '/' :
+- case FL_KP + '*' :
+- case FL_KP + '-' :
+- case FL_KP + '+' :
+- buffer[0] = Fl::e_keysym-FL_KP;
+- Fl::e_length = 1;
+- break;
+ }
+ }
+- } else if ((lParam & (1<<31))==0) {
+-#ifdef FLTK_PREVIEW_DEAD_KEYS
+- if ((lParam & (1<<24))==0) { // clear if dead key (always?)
+- xchar u = (xchar) wParam;
+- Fl::e_length = fl_utf8fromwc(buffer, 1024, &u, 1);
+- buffer[Fl::e_length] = 0;
+- } else { // set if "extended key" (never printable?)
+- buffer[0] = 0;
+- Fl::e_length = 0;
+- }
+-#else
+- buffer[0] = 0;
+- Fl::e_length = 0;
+-#endif
+ }
++
+ Fl::e_text = buffer;
+ if (lParam & (1<<31)) { // key up events.
+ if (Fl::handle(FL_KEYUP, window)) return 0;
--- /dev/null
+diff -ur fltk-1.3.0r9619.org/FL/Fl_Widget.H fltk-1.3.0r9619/FL/Fl_Widget.H
+--- fltk-1.3.0r9619.org/FL/Fl_Widget.H 2012-04-23 22:12:06.000000000 +0200
++++ fltk-1.3.0r9619/FL/Fl_Widget.H 2012-06-18 13:46:07.302320825 +0200
+@@ -171,6 +171,7 @@
+ GROUP_RELATIVE = 1<<16, ///< position this widget relative to the parent group, not to the window
+ COPIED_TOOLTIP = 1<<17, ///< the widget tooltip is internally copied, its destruction is handled by the widget
+ FULLSCREEN = 1<<18, ///< a fullscreen window (Fl_Window)
++ SIMPLE_KEYBOARD = 1<<19, ///< the widget wants simple, consistent keypresses and not advanced input (like character composition and CJK input)
+ // (space for more flags)
+ USERFLAG3 = 1<<29, ///< reserved for 3rd party extensions
+ USERFLAG2 = 1<<30, ///< reserved for 3rd party extensions
+@@ -776,6 +777,35 @@
+ */
+ void clear_changed() {flags_ &= ~CHANGED;}
+
++ /**
++ Returns if the widget sees a simplified keyboard model or not.
++
++ Normally widgets get a full-featured keyboard model that is geared
++ towards text input. This includes support for compose sequences and
++ advanced input methods, commonly used for asian writing system. This
++ system however has downsides in that extra graphic can be presented
++ to the user and that a physical key press doesn't correspond directly
++ to a FLTK event.
++
++ Widgets that need a direct correspondence between actual key events
++ and those seen by the widget can swith to the simplified keyboard
++ model.
++
++ \retval 0 if the widget uses the normal keyboard model
++ \see set_changed(), clear_changed()
++ */
++ unsigned int simple_keyboard() const {return flags_&SIMPLE_KEYBOARD;}
++
++ /** Marks a widget to use the simple keyboard model.
++ \see changed(), clear_changed()
++ */
++ void set_simple_keyboard() {flags_ |= SIMPLE_KEYBOARD;}
++
++ /** Marks a widget to use the normal keyboard model.
++ \see changed(), set_changed()
++ */
++ void set_normal_keyboard() {flags_ &= ~SIMPLE_KEYBOARD;}
++
+ /** Gives the widget the keyboard focus.
+ Tries to make this widget be the Fl::focus() widget, by first sending
+ it an FL_FOCUS event, and if it returns non-zero, setting
+diff -ur fltk-1.3.0r9619.org/src/Fl.cxx fltk-1.3.0r9619/src/Fl.cxx
+--- fltk-1.3.0r9619.org/src/Fl.cxx 2012-03-23 17:47:53.000000000 +0100
++++ fltk-1.3.0r9619/src/Fl.cxx 2012-06-18 13:46:07.303320877 +0200
+@@ -70,6 +70,8 @@
+ extern double fl_mac_flush_and_wait(double time_to_wait, char in_idle);
+ #endif // WIN32
+
++extern void fl_update_focus(void);
++
+ //
+ // Globals...
+ //
+@@ -876,6 +878,8 @@
+ fl_oldfocus = p;
+ }
+ e_number = old_event;
++ // let the platform code do what it needs
++ fl_update_focus();
+ }
+ }
+
+diff -ur fltk-1.3.0r9619.org/src/Fl_grab.cxx fltk-1.3.0r9619/src/Fl_grab.cxx
+--- fltk-1.3.0r9619.org/src/Fl_grab.cxx 2012-03-23 17:47:53.000000000 +0100
++++ fltk-1.3.0r9619/src/Fl_grab.cxx 2012-06-18 13:46:07.303320877 +0200
+@@ -29,6 +29,7 @@
+ // override_redirect, it does similar things on WIN32.
+
+ extern void fl_fix_focus(); // in Fl.cxx
++void fl_update_focus(void);
+
+ #ifdef WIN32
+ // We have to keep track of whether we have captured the mouse, since
+@@ -80,6 +81,7 @@
+ #endif
+ }
+ grab_ = win;
++ fl_update_focus();
+ } else {
+ if (grab_) {
+ #ifdef WIN32
+@@ -98,6 +100,7 @@
+ XFlush(fl_display);
+ #endif
+ grab_ = 0;
++ fl_update_focus();
+ fl_fix_focus();
+ }
+ }
+diff -ur fltk-1.3.0r9619.org/src/Fl_x.cxx fltk-1.3.0r9619/src/Fl_x.cxx
+--- fltk-1.3.0r9619.org/src/Fl_x.cxx 2012-06-18 13:46:07.205316173 +0200
++++ fltk-1.3.0r9619/src/Fl_x.cxx 2012-06-18 13:46:18.216844629 +0200
+@@ -298,6 +298,7 @@
+ Colormap fl_colormap;
+ XIM fl_xim_im = 0;
+ XIC fl_xim_ic = 0;
++Window fl_xim_win = 0;
+ char fl_is_over_the_spot = 0;
+ static XRectangle status_area;
+
+@@ -583,6 +584,65 @@
+ if(xim_styles) XFree(xim_styles);
+ }
+
++void fl_xim_deactivate(void);
++
++void fl_xim_activate(Window xid)
++{
++ if (!fl_xim_im)
++ return;
++
++ // If the focused window has changed, then use the brute force method
++ // of completely recreating the input context.
++ if (fl_xim_win != xid) {
++ fl_xim_deactivate();
++
++ fl_new_ic();
++ fl_xim_win = xid;
++
++ XSetICValues(fl_xim_ic,
++ XNFocusWindow, fl_xim_win,
++ XNClientWindow, fl_xim_win,
++ NULL);
++ }
++
++ fl_set_spot(spotf, spots, spot.x, spot.y, spot.width, spot.height);
++}
++
++void fl_xim_deactivate(void)
++{
++ if (!fl_xim_ic)
++ return;
++
++ XDestroyIC(fl_xim_ic);
++ fl_xim_ic = NULL;
++
++ fl_xim_win = 0;
++}
++
++extern Fl_Window *fl_xfocus;
++
++void fl_update_focus(void)
++{
++ Fl_Widget *focus;
++
++ focus = Fl::grab();
++ if (!focus)
++ focus = Fl::focus();
++ if (!focus)
++ return;
++
++ if (focus->simple_keyboard()) {
++ fl_xim_deactivate();
++ } else {
++ // fl_xfocus should always be set if something has focus, but let's
++ // play it safe
++ if (!fl_xfocus || !fl_xid(fl_xfocus))
++ return;
++
++ fl_xim_activate(fl_xid(fl_xfocus));
++ }
++}
++
+ void fl_open_display() {
+ if (fl_display) return;
+
+@@ -917,10 +977,9 @@
+ XEvent xevent = thisevent;
+ fl_xevent = &thisevent;
+ Window xid = xevent.xany.window;
+- static Window xim_win = 0;
+
+ if (fl_xim_ic && xevent.type == DestroyNotify &&
+- xid != xim_win && !fl_find(xid))
++ xid != fl_xim_win && !fl_find(xid))
+ {
+ XIM xim_im;
+ xim_im = XOpenIM(fl_display, NULL, NULL, NULL);
+@@ -935,48 +994,10 @@
+ return 0;
+ }
+
+- if (fl_xim_ic && (xevent.type == FocusIn))
+- {
+-#define POOR_XIM
+-#ifdef POOR_XIM
+- if (xim_win != xid)
+- {
+- xim_win = xid;
+- XDestroyIC(fl_xim_ic);
+- fl_xim_ic = NULL;
+- fl_new_ic();
+- XSetICValues(fl_xim_ic,
+- XNFocusWindow, xevent.xclient.window,
+- XNClientWindow, xid,
+- NULL);
+- }
+- fl_set_spot(spotf, spots, spot.x, spot.y, spot.width, spot.height);
+-#else
+- if (Fl::first_window() && Fl::first_window()->modal()) {
+- Window x = fl_xid(Fl::first_window());
+- if (x != xim_win) {
+- xim_win = x;
+- XSetICValues(fl_xim_ic,
+- XNFocusWindow, xim_win,
+- XNClientWindow, xim_win,
+- NULL);
+- fl_set_spot(spotf, spots, spot.x, spot.y, spot.width, spot.height);
+- }
+- } else if (xim_win != xid && xid) {
+- xim_win = xid;
+- XSetICValues(fl_xim_ic,
+- XNFocusWindow, xevent.xclient.window,
+- XNClientWindow, xid,
+- //XNFocusWindow, xim_win,
+- //XNClientWindow, xim_win,
+- NULL);
+- fl_set_spot(spotf, spots, spot.x, spot.y, spot.width, spot.height);
+- }
+-#endif
++ if (fl_xim_ic) {
++ if (XFilterEvent((XEvent *)&xevent, 0))
++ return 1;
+ }
+-
+- if ( XFilterEvent((XEvent *)&xevent, 0) )
+- return(1);
+
+ #if USE_XRANDR
+ if( XRRUpdateConfiguration_f && xevent.type == randrEventBase + RRScreenChangeNotify) {
+@@ -1326,15 +1347,15 @@
+ //static XComposeStatus compose;
+ len = XLookupString((XKeyEvent*)&(xevent.xkey),
+ buffer, buffer_len, &keysym, 0/*&compose*/);
+- if (keysym && keysym < 0x400) { // a character in latin-1,2,3,4 sets
+- // force it to type a character (not sure if this ever is needed):
+- // if (!len) {buffer[0] = char(keysym); len = 1;}
+- len = fl_utf8encode(XKeysymToUcs(keysym), buffer);
+- if (len < 1) len = 1;
+- // ignore all effects of shift on the keysyms, which makes it a lot
+- // easier to program shortcuts and is Windoze-compatible:
+- keysym = XKeycodeToKeysym(fl_display, keycode, 0);
+- }
++ // XLookupString() is only defined to return Latin-1 (although it
++ // often gives you more). To be safe, use our own lookups based on
++ // keysym.
++ len = fl_utf8encode(XKeysymToUcs(keysym), buffer);
++ if (len < 1)
++ len = 1;
++ // ignore all effects of shift on the keysyms, which makes it a lot
++ // easier to program shortcuts and is Windoze-compatable:
++ keysym = XKeycodeToKeysym(fl_display, keycode, 0);
+ }
+ // MRS: Can't use Fl::event_state(FL_CTRL) since the state is not
+ // set until set_event_xy() is called later...
+diff -ur fltk-1.3.0r9619.org/src/xutf8/imKStoUCS.c fltk-1.3.0r9619/src/xutf8/imKStoUCS.c
+--- fltk-1.3.0r9619.org/src/xutf8/imKStoUCS.c 2009-03-13 23:43:43.000000000 +0100
++++ fltk-1.3.0r9619/src/xutf8/imKStoUCS.c 2012-06-18 13:46:07.304320930 +0200
+@@ -266,6 +266,12 @@
+ 0x20a8, 0x20a9, 0x20aa, 0x20ab, 0x20ac /* 0x20a8-0x20af */
+ };
+
++static unsigned short const keysym_to_unicode_fe50_fe60[] = {
++ 0x0300, 0x0301, 0x0302, 0x0303, 0x0304, 0x0306, 0x0307, 0x0308, /* 0xfe50-0xfe57 */
++ 0x030a, 0x030b, 0x030c, 0x0327, 0x0328, 0x1da5, 0x3099, 0x309a, /* 0xfe58-0xfe5f */
++ 0x0323 /* 0xfe60-0xfe67 */
++};
++
+ unsigned int
+ KeySymToUcs4(KeySym keysym)
+ {
+@@ -315,6 +321,8 @@
+ return keysym_to_unicode_1e9f_1eff[keysym - 0x1e9f];
+ else if (keysym > 0x209f && keysym < 0x20ad)
+ return keysym_to_unicode_20a0_20ac[keysym - 0x20a0];
++ else if (keysym > 0xfe4f && keysym < 0xfe61)
++ return keysym_to_unicode_fe50_fe60[keysym - 0xfe50];
+ else
+ return 0;
+ }
--- /dev/null
+diff -up fltk-1.3.2/CMakeLists.txt.cursor fltk-1.3.2/CMakeLists.txt
+--- fltk-1.3.2/CMakeLists.txt.cursor 2013-01-30 16:07:59.510320246 +0100
++++ fltk-1.3.2/CMakeLists.txt 2013-01-30 16:07:59.528319926 +0100
+@@ -529,6 +529,20 @@ else()
+ endif(OPTION_USE_XFIXES)
+
+ #######################################################################
++if(X11_Xcursor_FOUND)
++ option(OPTION_USE_XCURSOR "use lib XCURSOR" ON)
++endif(X11_Xcursor_FOUND)
++
++if(OPTION_USE_XCURSOR)
++ set(HAVE_XCURSOR ${X11_Xcursor_FOUND})
++ include_directories(${X11_Xcursor_INCLUDE_PATH})
++ list(APPEND FLTK_LDLIBS -lXcursor)
++ set(FLTK_XCURSOR_FOUND TRUE)
++else()
++ set(FLTK_XCURSOR_FOUND FALSE)
++endif(OPTION_USE_XCURSOR)
++
++#######################################################################
+ if(X11_Xft_FOUND)
+ option(OPTION_USE_XFT "use lib Xft" ON)
+ endif(X11_Xft_FOUND)
+diff -up fltk-1.3.2/configh.cmake.in.cursor fltk-1.3.2/configh.cmake.in
+--- fltk-1.3.2/configh.cmake.in.cursor 2013-01-30 16:07:59.510320246 +0100
++++ fltk-1.3.2/configh.cmake.in 2013-01-30 16:07:59.529319908 +0100
+@@ -116,6 +116,14 @@
+ #cmakedefine01 HAVE_XFIXES
+
+ /*
++ * HAVE_XCURSOR:
++ *
++ * Do we have the X cursor library?
++ */
++
++#cmakedefine01 HAVE_XCURSOR
++
++/*
+ * __APPLE_QUARTZ__:
+ *
+ * If __APPLE_QUARTZ__ is defined, FLTK will be
+diff -up fltk-1.3.2/configh.in.cursor fltk-1.3.2/configh.in
+--- fltk-1.3.2/configh.in.cursor 2013-01-30 16:07:59.510320246 +0100
++++ fltk-1.3.2/configh.in 2013-01-30 16:07:59.529319908 +0100
+@@ -116,6 +116,14 @@
+ #define HAVE_XFIXES 0
+
+ /*
++ * HAVE_XCURSOR:
++ *
++ * Do we have the X cursor library?
++ */
++
++#define HAVE_XCURSOR 0
++
++/*
+ * __APPLE_QUARTZ__:
+ *
+ * All Apple implementations are now based on Quartz and Cocoa,
+diff -up fltk-1.3.2/configure.in.cursor fltk-1.3.2/configure.in
+--- fltk-1.3.2/configure.in.cursor 2013-01-30 16:07:59.511320228 +0100
++++ fltk-1.3.2/configure.in 2013-01-30 16:07:59.529319908 +0100
+@@ -1009,6 +1009,16 @@ case $uname_GUI in
+ LIBS="-lXfixes $LIBS")
+ fi
+
++ dnl Check for the Xcursor library unless disabled...
++ AC_ARG_ENABLE(xcursor, [ --enable-xcursor turn on Xcursor support [default=yes]])
++
++ if test x$enable_xcursor != xno; then
++ AC_CHECK_HEADER(X11/Xcursor/Xcursor.h, AC_DEFINE(HAVE_XCURSOR),,
++ [#include <X11/Xlib.h>])
++ AC_CHECK_LIB(Xcursor, XcursorImageCreate,
++ LIBS="-lXcursor $LIBS")
++ fi
++
+ dnl Check for overlay visuals...
+ AC_PATH_PROG(XPROP, xprop)
+ AC_CACHE_CHECK(for X overlay visuals, ac_cv_have_overlay,
+diff -up fltk-1.3.2/FL/Enumerations.H.cursor fltk-1.3.2/FL/Enumerations.H
+--- fltk-1.3.2/FL/Enumerations.H.cursor 2013-01-30 16:07:59.486320673 +0100
++++ fltk-1.3.2/FL/Enumerations.H 2013-01-30 16:07:59.530319891 +0100
+@@ -879,35 +879,36 @@ inline Fl_Color fl_color_cube(int r, int
+
+ /** The following constants define the mouse cursors that are available in FLTK.
+
+- The double-headed arrows are bitmaps provided by FLTK on X, the others
+- are provided by system-defined cursors.
++ Cursors are provided by the system when available, or bitmaps built into
++ FLTK as a fallback.
+
+ \todo enum Fl_Cursor needs maybe an image.
+ */
+ enum Fl_Cursor {
+ FL_CURSOR_DEFAULT = 0, /**< the default cursor, usually an arrow. */
+- FL_CURSOR_ARROW = 35, /**< an arrow pointer. */
+- FL_CURSOR_CROSS = 66, /**< crosshair. */
+- FL_CURSOR_WAIT = 76, /**< watch or hourglass. */
+- FL_CURSOR_INSERT = 77, /**< I-beam. */
+- FL_CURSOR_HAND = 31, /**< hand (uparrow on MSWindows). */
+- FL_CURSOR_HELP = 47, /**< question mark. */
+- FL_CURSOR_MOVE = 27, /**< 4-pointed arrow. */
+- // fltk provides bitmaps for these:
+- FL_CURSOR_NS = 78, /**< up/down arrow. */
+- FL_CURSOR_WE = 79, /**< left/right arrow. */
+- FL_CURSOR_NWSE = 80, /**< diagonal arrow. */
+- FL_CURSOR_NESW = 81, /**< diagonal arrow. */
+- FL_CURSOR_NONE =255, /**< invisible. */
+- // for back compatibility (non MSWindows ones):
+- FL_CURSOR_N = 70, /**< for back compatibility. */
+- FL_CURSOR_NE = 69, /**< for back compatibility. */
+- FL_CURSOR_E = 49, /**< for back compatibility. */
+- FL_CURSOR_SE = 8, /**< for back compatibility. */
+- FL_CURSOR_S = 9, /**< for back compatibility. */
+- FL_CURSOR_SW = 7, /**< for back compatibility. */
+- FL_CURSOR_W = 36, /**< for back compatibility. */
+- FL_CURSOR_NW = 68 /**< for back compatibility. */
++ FL_CURSOR_ARROW = 1, /**< an arrow pointer. */
++ FL_CURSOR_CROSS = 2, /**< crosshair. */
++ FL_CURSOR_WAIT = 3, /**< busy indicator (e.g. hourglass). */
++ FL_CURSOR_INSERT = 4, /**< I-beam. */
++ FL_CURSOR_HAND = 5, /**< pointing hand. */
++ FL_CURSOR_HELP = 6, /**< question mark pointer. */
++ FL_CURSOR_MOVE = 7, /**< 4-pointed arrow or hand. */
++
++ /* Resize indicators */
++ FL_CURSOR_NS = 101, /**< up/down resize. */
++ FL_CURSOR_WE = 102, /**< left/right resize. */
++ FL_CURSOR_NWSE = 103, /**< diagonal resize. */
++ FL_CURSOR_NESW = 104, /**< diagonal resize. */
++ FL_CURSOR_NE = 110, /**< upwards, right resize. */
++ FL_CURSOR_N = 111, /**< upwards resize. */
++ FL_CURSOR_NW = 112, /**< upwards, left resize. */
++ FL_CURSOR_E = 113, /**< leftwards resize. */
++ FL_CURSOR_W = 114, /**< rightwards resize. */
++ FL_CURSOR_SE = 115, /**< downwards, right resize. */
++ FL_CURSOR_S = 116, /**< downwards resize. */
++ FL_CURSOR_SW = 117, /**< downwards, left resize. */
++
++ FL_CURSOR_NONE = 255, /**< invisible. */
+ };
+ /*@}*/ // group: Cursors
+
+diff -up fltk-1.3.2/FL/fl_draw.H.cursor fltk-1.3.2/FL/fl_draw.H
+--- fltk-1.3.2/FL/fl_draw.H.cursor 2012-05-08 18:15:34.000000000 +0200
++++ fltk-1.3.2/FL/fl_draw.H 2013-01-30 16:07:59.530319891 +0100
+@@ -751,7 +751,8 @@ FL_EXPORT const char* fl_shortcut_label(
+ FL_EXPORT unsigned int fl_old_shortcut(const char* s);
+ FL_EXPORT void fl_overlay_rect(int x,int y,int w,int h);
+ FL_EXPORT void fl_overlay_clear();
+-FL_EXPORT void fl_cursor(Fl_Cursor, Fl_Color fg=FL_BLACK, Fl_Color bg=FL_WHITE);
++FL_EXPORT void fl_cursor(Fl_Cursor);
++FL_EXPORT void fl_cursor(Fl_Cursor, Fl_Color fg, Fl_Color bg=FL_WHITE);
+ FL_EXPORT const char* fl_expand_text(const char* from, char* buf, int maxbuf,
+ double maxw, int& n, double &width,
+ int wrap, int draw_symbols = 0);
+diff -up fltk-1.3.2/FL/Fl_Window.H.cursor fltk-1.3.2/FL/Fl_Window.H
+--- fltk-1.3.2/FL/Fl_Window.H.cursor 2012-11-06 21:46:14.000000000 +0100
++++ fltk-1.3.2/FL/Fl_Window.H 2013-01-30 16:07:59.531319873 +0100
+@@ -28,6 +28,7 @@
+ #define FL_DOUBLE_WINDOW 0xF1 ///< double window type id
+
+ class Fl_X;
++class Fl_RGB_Image;
+
+ /**
+ This widget produces an actual window. This can either be a main
+@@ -81,7 +82,6 @@ class FL_EXPORT Fl_Window : public Fl_Gr
+ uchar size_range_set;
+ // cursor stuff
+ Fl_Cursor cursor_default;
+- Fl_Color cursor_fg, cursor_bg;
+ void size_range_();
+ void _Fl_Window(); // constructor innards
+ void fullscreen_x(); // platform-specific part of sending a window to full screen
+@@ -466,14 +466,17 @@ public:
+ is different.
+
+ The type Fl_Cursor is an enumeration defined in <FL/Enumerations.H>.
+- (Under X you can get any XC_cursor value by passing
+- Fl_Cursor((XC_foo/2)+1)). The colors only work on X, they are
+- not implemented on WIN32.
+
+- For back compatibility only.
++ \see cursor(const Fl_RGB_Image*, int, int), default_cursor()
+ */
+- void cursor(Fl_Cursor, Fl_Color=FL_BLACK, Fl_Color=FL_WHITE); // platform dependent
+- void default_cursor(Fl_Cursor, Fl_Color=FL_BLACK, Fl_Color=FL_WHITE);
++ void cursor(Fl_Cursor);
++ void cursor(const Fl_RGB_Image*, int, int);
++ void default_cursor(Fl_Cursor);
++
++ /* for legacy compatibility */
++ void cursor(Fl_Cursor c, Fl_Color, Fl_Color=FL_WHITE);
++ void default_cursor(Fl_Cursor c, Fl_Color, Fl_Color=FL_WHITE);
++
+ static void default_callback(Fl_Window*, void* v);
+
+ /** Returns the window width including any frame added by the window manager.
+diff -up fltk-1.3.2/FL/mac.H.cursor fltk-1.3.2/FL/mac.H
+--- fltk-1.3.2/FL/mac.H.cursor 2012-11-13 15:45:42.000000000 +0100
++++ fltk-1.3.2/FL/mac.H 2013-01-30 16:07:59.531319873 +0100
+@@ -120,7 +120,8 @@ public:
+ void collapse(void);
+ WindowRef window_ref(void);
+ void set_key_window(void);
+- void set_cursor(Fl_Cursor);
++ int set_cursor(Fl_Cursor);
++ int set_cursor(const Fl_RGB_Image*, int, int);
+ static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
+ static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
+ static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
+diff -up fltk-1.3.2/FL/win32.H.cursor fltk-1.3.2/FL/win32.H
+--- fltk-1.3.2/FL/win32.H.cursor 2012-03-12 12:55:50.000000000 +0100
++++ fltk-1.3.2/FL/win32.H 2013-01-30 16:07:59.531319873 +0100
+@@ -73,6 +73,7 @@ public:
+ int wait_for_expose;
+ HDC private_dc; // used for OpenGL
+ HCURSOR cursor;
++ int custom_cursor;
+ HDC saved_hdc; // saves the handle of the DC currently loaded
+ // static variables, static functions and member functions
+ static Fl_X* first;
+@@ -83,6 +84,8 @@ public:
+ void flush() {w->flush();}
+ void set_minmax(LPMINMAXINFO minmax);
+ void mapraise();
++ int set_cursor(Fl_Cursor);
++ int set_cursor(const Fl_RGB_Image*, int, int);
+ static Fl_X* make(Fl_Window*);
+ };
+ extern FL_EXPORT HCURSOR fl_default_cursor;
+diff -up fltk-1.3.2/FL/x.H.cursor fltk-1.3.2/FL/x.H
+--- fltk-1.3.2/FL/x.H.cursor 2012-03-23 17:47:53.000000000 +0100
++++ fltk-1.3.2/FL/x.H 2013-01-30 16:07:59.532319855 +0100
+@@ -154,6 +154,8 @@ public:
+ static Fl_X* i(const Fl_Window* wi) {return wi->i;}
+ void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
+ void sendxjunk();
++ int set_cursor(Fl_Cursor);
++ int set_cursor(const Fl_RGB_Image*, int, int);
+ static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
+ static Fl_X* set_xid(Fl_Window*, Window);
+ // kludges to get around protection:
+diff -up fltk-1.3.2/src/CMakeLists.txt.cursor fltk-1.3.2/src/CMakeLists.txt
+--- fltk-1.3.2/src/CMakeLists.txt.cursor 2013-01-30 16:09:11.981032475 +0100
++++ fltk-1.3.2/src/CMakeLists.txt 2013-01-30 16:09:26.497774461 +0100
+@@ -247,6 +247,10 @@ if(HAVE_XFIXES)
+ target_link_libraries(fltk ${X11_Xfixes_LIB})
+ endif(HAVE_XFIXES)
+
++if(HAVE_XCURSOR)
++ target_link_libraries(fltk ${X11_Xcursor_LIB})
++endif(HAVE_XCURSOR)
++
+ if(USE_XFT)
+ target_link_libraries(fltk ${X11_Xft_LIB})
+ endif(USE_XFT)
+diff -up fltk-1.3.2/src/Fl_cocoa.mm.cursor fltk-1.3.2/src/Fl_cocoa.mm
+--- fltk-1.3.2/src/Fl_cocoa.mm.cursor 2013-01-30 16:07:59.522320033 +0100
++++ fltk-1.3.2/src/Fl_cocoa.mm 2013-01-30 16:07:59.533319837 +0100
+@@ -98,7 +98,6 @@ Fl_Display_Device *Fl_Display_Device::_d
+ CGContextRef fl_gc = 0;
+ void *fl_system_menu; // this is really a NSMenu*
+ Fl_Sys_Menu_Bar *fl_sys_menu_bar = 0;
+-void *fl_default_cursor; // this is really a NSCursor*
+ void *fl_capture = 0; // (NSWindow*) we need this to compensate for a missing(?) mouse capture
+ bool fl_show_iconic; // true if called from iconize() - shows the next created window in collapsed state
+ //int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
+@@ -1392,8 +1391,6 @@ void fl_open_display() {
+ dequeue:YES];
+ while (ign_event);
+
+- fl_default_cursor = [NSCursor arrowCursor];
+-
+ // bring the application into foreground without a 'CARB' resource
+ Boolean same_psn;
+ ProcessSerialNumber cur_psn, front_psn;
+@@ -1698,6 +1695,7 @@ static void q_set_window_title(NSWindow
+ - (void)drawRect:(NSRect)rect;
+ - (BOOL)acceptsFirstResponder;
+ - (BOOL)acceptsFirstMouse:(NSEvent*)theEvent;
++- (void)resetCursorRects;
+ - (BOOL)performKeyEquivalent:(NSEvent*)theEvent;
+ - (void)mouseUp:(NSEvent *)theEvent;
+ - (void)rightMouseUp:(NSEvent *)theEvent;
+@@ -1756,6 +1754,16 @@ static void q_set_window_title(NSWindow
+ Fl_Window *first = Fl::first_window();
+ return (first == w || !first->modal());
+ }
++- (void)resetCursorRects {
++ Fl_Window *w = [(FLWindow*)[self window] getFl_Window];
++ Fl_X *i = Fl_X::i(w);
++ // We have to have at least one cursor rect for invalidateCursorRectsForView
++ // to work, hence the "else" clause.
++ if (i->cursor)
++ [self addCursorRect:[self visibleRect] cursor:(NSCursor*)i->cursor];
++ else
++ [self addCursorRect:[self visibleRect] cursor:[NSCursor arrowCursor]];
++}
+ - (void)mouseUp:(NSEvent *)theEvent {
+ cocoaMouseHandler(theEvent);
+ }
+@@ -2331,7 +2339,7 @@ void Fl_X::make(Fl_Window* w)
+ x->other_xid = 0;
+ x->region = 0;
+ x->subRegion = 0;
+- x->cursor = fl_default_cursor;
++ x->cursor = NULL;
+ x->gc = 0; // stay 0 for Quickdraw; fill with CGContext for Quartz
+ Fl_Window *win = w->window();
+ Fl_X *xo = Fl_X::i(win);
+@@ -2427,7 +2435,7 @@ void Fl_X::make(Fl_Window* w)
+ x->other_xid = 0; // room for doublebuffering image map. On OS X this is only used by overlay windows
+ x->region = 0;
+ x->subRegion = 0;
+- x->cursor = fl_default_cursor;
++ x->cursor = NULL;
+ x->xidChildren = 0;
+ x->xidNext = 0;
+ x->gc = 0;
+@@ -2974,6 +2982,10 @@ void Fl_X::map() {
+ Fl_X::relink(w, w->window() );
+ w->redraw();
+ }
++ if (cursor) {
++ [(NSCursor*)cursor release];
++ cursor = NULL;
++ }
+ }
+
+ void Fl_X::unmap() {
+@@ -3078,68 +3090,106 @@ static NSImage *CGBitmapContextToNSImage
+ return [image autorelease];
+ }
+
+-static NSCursor *PrepareCursor(NSCursor *cursor, CGContextRef (*f)() )
++int Fl_X::set_cursor(Fl_Cursor c)
+ {
+- if (cursor == nil) {
+- CGContextRef c = f();
+- NSImage *image = CGBitmapContextToNSImage(c);
+- fl_delete_offscreen( (Fl_Offscreen)c );
+- NSPoint pt = {[image size].width/2, [image size].height/2};
+- cursor = [[NSCursor alloc] initWithImage:image hotSpot:pt];
++ if (cursor) {
++ [(NSCursor*)cursor release];
++ cursor = NULL;
+ }
+- return cursor;
+-}
+
+-void Fl_X::set_cursor(Fl_Cursor c)
+-{
+- NSCursor *icrsr;
+ switch (c) {
+- case FL_CURSOR_CROSS: icrsr = [NSCursor crosshairCursor]; break;
+- case FL_CURSOR_WAIT:
+- static NSCursor *watch = nil;
+- watch = PrepareCursor(watch, &Fl_X::watch_cursor_image);
+- icrsr = watch;
+- break;
+- case FL_CURSOR_INSERT: icrsr = [NSCursor IBeamCursor]; break;
+- case FL_CURSOR_N: icrsr = [NSCursor resizeUpCursor]; break;
+- case FL_CURSOR_S: icrsr = [NSCursor resizeDownCursor]; break;
+- case FL_CURSOR_NS: icrsr = [NSCursor resizeUpDownCursor]; break;
+- case FL_CURSOR_HELP:
+- static NSCursor *help = nil;
+- help = PrepareCursor(help, &Fl_X::help_cursor_image);
+- icrsr = help;
+- break;
+- case FL_CURSOR_HAND: icrsr = [NSCursor pointingHandCursor]; break;
+- case FL_CURSOR_MOVE: icrsr = [NSCursor openHandCursor]; break;
+- case FL_CURSOR_NE:
+- case FL_CURSOR_SW:
+- case FL_CURSOR_NESW:
+- static NSCursor *nesw = nil;
+- nesw = PrepareCursor(nesw, &Fl_X::nesw_cursor_image);
+- icrsr = nesw;
+- break;
+- case FL_CURSOR_E: icrsr = [NSCursor resizeRightCursor]; break;
+- case FL_CURSOR_W: icrsr = [NSCursor resizeLeftCursor]; break;
+- case FL_CURSOR_WE: icrsr = [NSCursor resizeLeftRightCursor]; break;
+- case FL_CURSOR_SE:
+- case FL_CURSOR_NW:
+- case FL_CURSOR_NWSE:
+- static NSCursor *nwse = nil;
+- nwse = PrepareCursor(nwse, &Fl_X::nwse_cursor_image);
+- icrsr = nwse;
+- break;
+- case FL_CURSOR_NONE:
+- static NSCursor *none = nil;
+- none = PrepareCursor(none, &Fl_X::none_cursor_image);
+- icrsr = none;
+- break;
+- case FL_CURSOR_ARROW:
+- case FL_CURSOR_DEFAULT:
+- default: icrsr = [NSCursor arrowCursor];
+- break;
++ case FL_CURSOR_ARROW: cursor = [NSCursor arrowCursor]; break;
++ case FL_CURSOR_CROSS: cursor = [NSCursor crosshairCursor]; break;
++ case FL_CURSOR_INSERT: cursor = [NSCursor IBeamCursor]; break;
++ case FL_CURSOR_HAND: cursor = [NSCursor pointingHandCursor]; break;
++ case FL_CURSOR_MOVE: cursor = [NSCursor openHandCursor]; break;
++ case FL_CURSOR_NS: cursor = [NSCursor resizeUpDownCursor]; break;
++ case FL_CURSOR_WE: cursor = [NSCursor resizeLeftRightCursor]; break;
++ case FL_CURSOR_N: cursor = [NSCursor resizeUpCursor]; break;
++ case FL_CURSOR_E: cursor = [NSCursor resizeRightCursor]; break;
++ case FL_CURSOR_W: cursor = [NSCursor resizeLeftCursor]; break;
++ case FL_CURSOR_S: cursor = [NSCursor resizeDownCursor]; break;
++ default:
++ return 0;
++ }
++
++ [(NSCursor*)cursor retain];
++
++ [(NSWindow*)xid invalidateCursorRectsForView:[(NSWindow*)xid contentView]];
++
++ return 1;
++}
++
++int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
++ if (cursor) {
++ [(NSCursor*)cursor release];
++ cursor = NULL;
++ }
++
++ if ((hotx < 0) || (hotx >= image->w()))
++ return 0;
++ if ((hoty < 0) || (hoty >= image->h()))
++ return 0;
++
++ // OS X >= 10.6 can create a NSImage from a CGImage, but we need to
++ // support older versions, hence this pesky handling.
++
++ NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
++ initWithBitmapDataPlanes:NULL
++ pixelsWide:image->w()
++ pixelsHigh:image->h()
++ bitsPerSample:8
++ samplesPerPixel:image->d()
++ hasAlpha:!(image->d() & 1)
++ isPlanar:NO
++ colorSpaceName:(image->d()<=2) ? NSDeviceWhiteColorSpace : NSDeviceRGBColorSpace
++ bytesPerRow:(image->w() * image->d())
++ bitsPerPixel:(image->d()*8)];
++
++ // Alpha needs to be premultiplied for this format
++
++ const uchar *i = (const uchar*)*image->data();
++ unsigned char *o = [bitmap bitmapData];
++ for (int y = 0;y < image->h();y++) {
++ if (image->d() & 1) {
++ for (int x = 0;x < image->w();x++) {
++ unsigned int alpha;
++ if (image->d() == 4) {
++ alpha = i[3];
++ *o++ = (unsigned char)((unsigned int)*i++ * alpha / 255);
++ *o++ = (unsigned char)((unsigned int)*i++ * alpha / 255);
++ }
++
++ alpha = i[1];
++ *o++ = (unsigned char)((unsigned int)*i++ * alpha / 255);
++ *o++ = alpha;
++ i++;
++ }
++ } else {
++ // No alpha, so we can just copy everything directly.
++ int len = image->w() * image->d();
++ memcpy(o, i, len);
++ o += len;
++ i += len;
++ }
++ i += image->ld();
+ }
+- [icrsr set];
+- cursor = icrsr;
++
++ NSImage *nsimage = [[NSImage alloc]
++ initWithSize:NSMakeSize(image->w(), image->h())];
++
++ [nsimage addRepresentation:bitmap];
++
++ cursor = [[NSCursor alloc]
++ initWithImage:nsimage
++ hotSpot:NSMakePoint(hotx, hoty)];
++
++ [(NSWindow*)xid invalidateCursorRectsForView:[(NSWindow*)xid contentView]];
++
++ [bitmap release];
++ [nsimage release];
++
++ return 1;
+ }
+
+ @interface FLaboutItemTarget : NSObject
+diff -up fltk-1.3.2/src/fl_cursor.cxx.cursor fltk-1.3.2/src/fl_cursor.cxx
+--- fltk-1.3.2/src/fl_cursor.cxx.cursor 2012-03-12 12:55:50.000000000 +0100
++++ fltk-1.3.2/src/fl_cursor.cxx 2013-01-30 16:07:59.534319820 +0100
+@@ -24,297 +24,165 @@
+
+ #include <FL/Fl.H>
+ #include <FL/Fl_Window.H>
++#include <FL/Fl_Pixmap.H>
++#include <FL/Fl_RGB_Image.H>
+ #include <FL/x.H>
+-#if !defined(WIN32) && !defined(__APPLE__)
+-# include <X11/cursorfont.h>
+-#endif
+ #include <FL/fl_draw.H>
+
++#include "fl_cursor_wait.xpm"
++#include "fl_cursor_help.xpm"
++#include "fl_cursor_nwse.xpm"
++#include "fl_cursor_nesw.xpm"
++#include "fl_cursor_none.xpm"
++
+ /**
+ Sets the cursor for the current window to the specified shape and colors.
+ The cursors are defined in the <FL/Enumerations.H> header file.
+ */
++void fl_cursor(Fl_Cursor c) {
++ if (Fl::first_window()) Fl::first_window()->cursor(c);
++}
++
++/* For back compatibility only. */
+ void fl_cursor(Fl_Cursor c, Fl_Color fg, Fl_Color bg) {
+- if (Fl::first_window()) Fl::first_window()->cursor(c,fg,bg);
++ fl_cursor(c);
+ }
++
++
+ /**
+- Sets the default window cursor as well as its color.
++ Sets the default window cursor. This is the cursor that will be used
++ after the mouse pointer leaves a widget with a custom cursor set.
+
+- For back compatibility only.
++ \see cursor(const Fl_RGB_Image*, int, int), default_cursor()
+ */
+-void Fl_Window::default_cursor(Fl_Cursor c, Fl_Color fg, Fl_Color bg) {
+-// if (c == FL_CURSOR_DEFAULT) c = FL_CURSOR_ARROW;
+-
++void Fl_Window::default_cursor(Fl_Cursor c) {
+ cursor_default = c;
+- cursor_fg = fg;
+- cursor_bg = bg;
++ cursor(c);
++}
++
++
++void fallback_cursor(Fl_Window *w, Fl_Cursor c) {
++ const char **xpm;
++ int hotx, hoty;
++
++ // The standard arrow is our final fallback, so something is broken
++ // if we get called back here with that as an argument.
++ if (c == FL_CURSOR_ARROW)
++ return;
++
++ switch (c) {
++ case FL_CURSOR_WAIT:
++ xpm = (const char**)fl_cursor_wait_xpm;
++ hotx = 8;
++ hoty = 15;
++ break;
++ case FL_CURSOR_HELP:
++ xpm = (const char**)fl_cursor_help_xpm;
++ hotx = 1;
++ hoty = 3;
++ break;
++ case FL_CURSOR_NWSE:
++ xpm = (const char**)fl_cursor_nwse_xpm;
++ hotx = 7;
++ hoty = 7;
++ break;
++ case FL_CURSOR_NESW:
++ xpm = (const char**)fl_cursor_nesw_xpm;
++ hotx = 7;
++ hoty = 7;
++ break;
++ case FL_CURSOR_NONE:
++ xpm = (const char**)fl_cursor_none_xpm;
++ hotx = 0;
++ hoty = 0;
++ break;
++ default:
++ w->cursor(FL_CURSOR_ARROW);
++ return;
++ }
+
+- cursor(c, fg, bg);
++ Fl_Pixmap pxm(xpm);
++ Fl_RGB_Image image(&pxm);
++
++ w->cursor(&image, hotx, hoty);
+ }
+
+-#ifdef WIN32
+
+-# ifndef IDC_HAND
+-# define IDC_HAND MAKEINTRESOURCE(32649)
+-# endif // !IDC_HAND
++void Fl_Window::cursor(Fl_Cursor c) {
++ int ret;
+
+-void Fl_Window::cursor(Fl_Cursor c, Fl_Color c1, Fl_Color c2) {
+- if (!shown()) return;
+ // the cursor must be set for the top level window, not for subwindows
+ Fl_Window *w = window(), *toplevel = this;
+- while (w) { toplevel = w; w = w->window(); }
+- if (toplevel != this) { toplevel->cursor(c, c1, c2); return; }
+- // now set the actual cursor
+- if (c == FL_CURSOR_DEFAULT) {
+- c = cursor_default;
+- }
+- if (c > FL_CURSOR_NESW) {
+- i->cursor = 0;
+- } else if (c == FL_CURSOR_DEFAULT) {
+- i->cursor = fl_default_cursor;
+- } else {
+- LPSTR n;
+- switch (c) {
+- case FL_CURSOR_ARROW: n = IDC_ARROW; break;
+- case FL_CURSOR_CROSS: n = IDC_CROSS; break;
+- case FL_CURSOR_WAIT: n = IDC_WAIT; break;
+- case FL_CURSOR_INSERT: n = IDC_IBEAM; break;
+- case FL_CURSOR_HELP: n = IDC_HELP; break;
+- case FL_CURSOR_HAND: {
+- OSVERSIONINFO osvi;
+-
+- // Get the OS version: Windows 98 and 2000 have a standard
+- // hand cursor.
+- memset(&osvi, 0, sizeof(OSVERSIONINFO));
+- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+- GetVersionEx(&osvi);
+-
+- if (osvi.dwMajorVersion > 4 ||
+- (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion > 0 &&
+- osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)) n = IDC_HAND;
+- else n = IDC_UPARROW;
+- } break;
+- case FL_CURSOR_MOVE: n = IDC_SIZEALL; break;
+- case FL_CURSOR_N:
+- case FL_CURSOR_S:
+- case FL_CURSOR_NS: n = IDC_SIZENS; break;
+- case FL_CURSOR_NE:
+- case FL_CURSOR_SW:
+- case FL_CURSOR_NESW: n = IDC_SIZENESW; break;
+- case FL_CURSOR_E:
+- case FL_CURSOR_W:
+- case FL_CURSOR_WE: n = IDC_SIZEWE; break;
+- case FL_CURSOR_SE:
+- case FL_CURSOR_NW:
+- case FL_CURSOR_NWSE: n = IDC_SIZENWSE; break;
+- default: n = IDC_NO; break;
+- }
+- i->cursor = LoadCursor(NULL, n);
++
++ while (w) {
++ toplevel = w;
++ w = w->window();
+ }
+- SetCursor(i->cursor);
+-}
+
+-#elif defined(__APPLE__)
++ if (toplevel != this) {
++ toplevel->cursor(c);
++ return;
++ }
+
+-#ifdef __BIG_ENDIAN__
+-# define E(x) x
+-#elif defined __LITTLE_ENDIAN__
+-// Don't worry. This will be resolved at compile time
+-# define E(x) (x>>8)|((x<<8)&0xff00)
+-#else
+-# error "Either __LITTLE_ENDIAN__ or __BIG_ENDIAN__ must be defined"
+-#endif
+-
+-CGContextRef Fl_X::help_cursor_image(void)
+-{
+- int w = 20, h = 20;
+- Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h);
+- fl_begin_offscreen(off);
+- CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
+- fl_rectf(0,0,w,h);
+- fl_color(FL_BLACK);
+- fl_font(FL_COURIER_BOLD, 20);
+- fl_draw("?", 1, h-1);
+- fl_end_offscreen();
+- return (CGContextRef)off;
+-}
++ if (c == FL_CURSOR_DEFAULT)
++ c = cursor_default;
+
+-CGContextRef Fl_X::none_cursor_image(void)
+-{
+- int w = 20, h = 20;
+- Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h);
+- fl_begin_offscreen(off);
+- CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
+- fl_rectf(0,0,w,h);
+- fl_end_offscreen();
+- return (CGContextRef)off;
+-}
++ if (!i)
++ return;
+
+-CGContextRef Fl_X::watch_cursor_image(void)
+-{
+- int w, h, r = 5;
+- w = 2*r+6;
+- h = 4*r;
+- Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h);
+- fl_begin_offscreen(off);
+- CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
+- fl_rectf(0,0,w,h);
+- CGContextTranslateCTM( (CGContextRef)off, w/2, h/2);
+- fl_color(FL_WHITE);
+- fl_circle(0, 0, r+1);
+- fl_color(FL_BLACK);
+- fl_rectf(int(-r*0.7), int(-r*1.7), int(1.4*r), int(3.4*r));
+- fl_rectf(r-1, -1, 3, 3);
+- fl_color(FL_WHITE);
+- fl_pie(-r, -r, 2*r, 2*r, 0, 360);
+- fl_color(FL_BLACK);
+- fl_circle(0,0,r);
+- fl_xyline(0, 0, int(-r*.7));
+- fl_xyline(0, 0, 0, int(-r*.7));
+- fl_end_offscreen();
+- return (CGContextRef)off;
+-}
++ ret = i->set_cursor(c);
++ if (ret)
++ return;
+
+-CGContextRef Fl_X::nesw_cursor_image(void)
+-{
+- int c = 7, r = 2*c;
+- int w = r, h = r;
+- Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h);
+- fl_begin_offscreen(off);
+- CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
+- fl_rectf(0,0,w,h);
+- CGContextTranslateCTM( (CGContextRef)off, 0, h);
+- CGContextScaleCTM( (CGContextRef)off, 1, -1);
+- fl_color(FL_BLACK);
+- fl_polygon(0, 0, c, 0, 0, c);
+- fl_polygon(r, r, r, r-c, r-c, r);
+- fl_line_style(FL_SOLID, 2, 0);
+- fl_line(0,1, r,r+1);
+- fl_line_style(FL_SOLID, 0, 0);
+- fl_end_offscreen();
+- return (CGContextRef)off;
++ fallback_cursor(this, c);
+ }
+
+-CGContextRef Fl_X::nwse_cursor_image(void)
+-{
+- int c = 7, r = 2*c;
+- int w = r, h = r;
+- Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h);
+- fl_begin_offscreen(off);
+- CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
+- fl_rectf(0,0,w,h);
+- CGContextTranslateCTM( (CGContextRef)off, 0, h);
+- CGContextScaleCTM( (CGContextRef)off, 1, -1);
+- fl_color(FL_BLACK);
+- fl_polygon(r-1, 0, r-1, c, r-1-c, 0);
+- fl_polygon(-1, r, c-1, r, -1, r-c);
+- fl_line_style(FL_SOLID, 2, 0);
+- fl_line(r-1,1, -1,r+1);
+- fl_line_style(FL_SOLID, 0, 0);
+- fl_end_offscreen();
+- return (CGContextRef)off;
+-}
+-
+-void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
+- if (c == FL_CURSOR_DEFAULT) {
+- c = cursor_default;
+- }
+- if (i) i->set_cursor(c);
+-}
++/**
++ Changes the cursor for this window. This always calls the system, if
++ you are changing the cursor a lot you may want to keep track of how
++ you set it in a static variable and call this only if the new cursor
++ is different.
+
+-#else
++ The default cursor will be used if the provided image cannot be used
++ as a cursor.
+
+-// I like the MSWindows resize cursors, so I duplicate them here:
++ \see cursor(Fl_Cursor), default_cursor()
++*/
++void Fl_Window::cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
++ int ret;
+
+-#define CURSORSIZE 16
+-#define HOTXY 7
+-static struct TableEntry {
+- uchar bits[CURSORSIZE*CURSORSIZE/8];
+- uchar mask[CURSORSIZE*CURSORSIZE/8];
+- Cursor cursor;
+-} table[] = {
+- {{ // FL_CURSOR_NS
+- 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0x80, 0x01, 0x80, 0x01,
+- 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
+- 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00},
+- {
+- 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0xf0, 0x0f, 0xc0, 0x03,
+- 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x0f,
+- 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01}},
+- {{ // FL_CURSOR_EW
+- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10,
+- 0x0c, 0x30, 0xfe, 0x7f, 0xfe, 0x7f, 0x0c, 0x30, 0x08, 0x10, 0x00, 0x00,
+- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+- {
+- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x1c, 0x38,
+- 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0x1c, 0x38, 0x18, 0x18,
+- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
+- {{ // FL_CURSOR_NWSE
+- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x38, 0x00, 0x78, 0x00,
+- 0xe8, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x17, 0x00, 0x1e, 0x00, 0x1c,
+- 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+- {
+- 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0x7c, 0x00, 0xfc, 0x00,
+- 0xfc, 0x01, 0xec, 0x03, 0xc0, 0x37, 0x80, 0x3f, 0x00, 0x3f, 0x00, 0x3e,
+- 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00}},
+- {{ // FL_CURSOR_NESW
+- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x1c, 0x00, 0x1e,
+- 0x00, 0x17, 0x80, 0x03, 0xc0, 0x01, 0xe8, 0x00, 0x78, 0x00, 0x38, 0x00,
+- 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+- {
+- 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3f,
+- 0x80, 0x3f, 0xc0, 0x37, 0xec, 0x03, 0xfc, 0x01, 0xfc, 0x00, 0x7c, 0x00,
+- 0xfc, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00}},
+- {{0}, {0}} // FL_CURSOR_NONE & unknown
+-};
++ // the cursor must be set for the top level window, not for subwindows
++ Fl_Window *w = window(), *toplevel = this;
+
+-void Fl_Window::cursor(Fl_Cursor c, Fl_Color fg, Fl_Color bg) {
+- if (!shown()) return;
+- Cursor xc;
+- int deleteit = 0;
+- if (c == FL_CURSOR_DEFAULT) {
+- c = cursor_default;
+- fg = cursor_fg;
+- bg = cursor_bg;
++ while (w) {
++ toplevel = w;
++ w = w->window();
+ }
+
+- if (!c) {
+- xc = None;
+- } else {
+- if (c >= FL_CURSOR_NS) {
+- TableEntry *q = (c > FL_CURSOR_NESW) ? table+4 : table+(c-FL_CURSOR_NS);
+- if (!(q->cursor)) {
+- XColor dummy = { 0 };
+- Pixmap p = XCreateBitmapFromData(fl_display,
+- RootWindow(fl_display, fl_screen), (const char*)(q->bits),
+- CURSORSIZE, CURSORSIZE);
+- Pixmap m = XCreateBitmapFromData(fl_display,
+- RootWindow(fl_display, fl_screen), (const char*)(q->mask),
+- CURSORSIZE, CURSORSIZE);
+- q->cursor = XCreatePixmapCursor(fl_display, p,m,&dummy, &dummy,
+- HOTXY, HOTXY);
+- XFreePixmap(fl_display, m);
+- XFreePixmap(fl_display, p);
+- }
+- xc = q->cursor;
+- } else {
+- xc = XCreateFontCursor(fl_display, (c-1)*2);
+- deleteit = 1;
+- }
+- XColor fgc;
+- uchar r,g,b;
+- Fl::get_color(fg,r,g,b);
+- fgc.red = r<<8; fgc.green = g<<8; fgc.blue = b<<8;
+- XColor bgc;
+- Fl::get_color(bg,r,g,b);
+- bgc.red = r<<8; bgc.green = g<<8; bgc.blue = b<<8;
+- XRecolorCursor(fl_display, xc, &fgc, &bgc);
++ if (toplevel != this) {
++ toplevel->cursor(image, hotx, hoty);
++ return;
+ }
+- XDefineCursor(fl_display, fl_xid(this), xc);
+- if (deleteit) XFreeCursor(fl_display, xc);
++
++ if (!i)
++ return;
++
++ ret = i->set_cursor(image, hotx, hoty);
++ if (ret)
++ return;
++
++ cursor(FL_CURSOR_DEFAULT);
+ }
+
+-#endif
++/* For back compatibility only. */
++void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
++ cursor(c);
++};
++
++void Fl_Window::default_cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
++ default_cursor(c);
++};
++
+
+ //
+ // End of "$Id: fl_cursor.cxx 9278 2012-03-12 11:55:50Z manolo $".
+diff -up fltk-1.3.2/src/fl_cursor_help.xpm.cursor fltk-1.3.2/src/fl_cursor_help.xpm
+--- fltk-1.3.2/src/fl_cursor_help.xpm.cursor 2013-01-30 16:07:59.534319820 +0100
++++ fltk-1.3.2/src/fl_cursor_help.xpm 2013-01-30 16:07:59.534319820 +0100
+@@ -0,0 +1,95 @@
++/* XPM */
++static const char * fl_cursor_help_xpm[] = {
++"16 27 65 1",
++" c None",
++". c #FFFFFF",
++"+ c #E2E2E2",
++"@ c #1C1C1C",
++"# c #E7E7E7",
++"$ c #000000",
++"% c #212121",
++"& c #EAEAEA",
++"* c #262626",
++"= c #EDEDED",
++"- c #2C2C2C",
++"; c #F0F0F0",
++"> c #333333",
++", c #F1F1F1",
++"' c #393939",
++") c #F3F3F3",
++"! c #404040",
++"~ c #484848",
++"{ c #F4F4F4",
++"] c #050505",
++"^ c #202020",
++"/ c #707070",
++"( c #F5F5F5",
++"_ c #040404",
++": c #E1E1E1",
++"< c #EEEEEE",
++"[ c #EFEFEF",
++"} c #FEFEFE",
++"| c #3D3D3D",
++"1 c #7E7E7E",
++"2 c #696969",
++"3 c #414141",
++"4 c #131313",
++"5 c #080808",
++"6 c #454545",
++"7 c #F2F2F2",
++"8 c #878787",
++"9 c #7D7D7D",
++"0 c #101010",
++"a c #111111",
++"b c #FDFDFD",
++"c c #8A8A8A",
++"d c #E6E6E6",
++"e c #7B7B7B",
++"f c #4C4C4C",
++"g c #5C5C5C",
++"h c #9F9F9F",
++"i c #F9F9F9",
++"j c #F7F7F7",
++"k c #B1B1B1",
++"l c #2E2E2E",
++"m c #767676",
++"n c #DCDCDC",
++"o c #DEDEDE",
++"p c #C7C7C7",
++"q c #1B1B1B",
++"r c #6B6B6B",
++"s c #575757",
++"t c #797979",
++"u c #020202",
++"v c #010101",
++"w c #FBFBFB",
++"x c #D7D7D7",
++"y c #D8D8D8",
++"z c #060606",
++" ",
++". ",
++".+ ",
++".@# ",
++".$%& ",
++".$$*= ",
++".$$$-; ",
++".$$$$>, ",
++".$$$$$') ",
++".$$$$$$!) ",
++".$$$$$$$~{ ",
++".$$$$]^^^/( ",
++".$$$$_:(<<[} ",
++".$$|1$2< ",
++".$3,(45[ ",
++".67 78$9, ",
++".7 {0a( .... ",
++"b ,c5[defgh, ",
++" )ijk_la$m.",
++" no.p$q.",
++" .r$s.",
++" .t$-= ",
++" 7uv+ ",
++" wxy. ",
++" :$z. ",
++" :$z. ",
++" .... "};
+diff -up fltk-1.3.2/src/fl_cursor_nesw.xpm.cursor fltk-1.3.2/src/fl_cursor_nesw.xpm
+--- fltk-1.3.2/src/fl_cursor_nesw.xpm.cursor 2013-01-30 16:07:59.534319820 +0100
++++ fltk-1.3.2/src/fl_cursor_nesw.xpm 2013-01-30 16:07:59.534319820 +0100
+@@ -0,0 +1,46 @@
++/* XPM */
++static const char * fl_cursor_nesw_xpm[] = {
++"15 15 28 1",
++" c None",
++". c #FFFFFF",
++"+ c #767676",
++"@ c #000000",
++"# c #4E4E4E",
++"$ c #0C0C0C",
++"% c #494949",
++"& c #4D4D4D",
++"* c #1B1B1B",
++"= c #515151",
++"- c #646464",
++"; c #363636",
++"> c #6A6A6A",
++", c #545454",
++"' c #585858",
++") c #242424",
++"! c #797979",
++"~ c #2E2E2E",
++"{ c #444444",
++"] c #3B3B3B",
++"^ c #0A0A0A",
++"/ c #595959",
++"( c #F7F7F7",
++"_ c #080808",
++": c #6B6B6B",
++"< c #FDFDFD",
++"[ c #FCFCFC",
++"} c #FEFEFE",
++" ..........",
++" .+@@@@@@.",
++" .#@@@@@.",
++" .$@@@@.",
++" .%@@@@@.",
++". .&@@@*@@.",
++".. .=@@@-.;@.",
++".>. .,@@@'. .).",
++".@!.'@@@#. ..",
++".@@~@@@{. .",
++".@@@@@]. ",
++".@@@@^. ",
++".@@@@@/( ",
++".______:( ",
++"<[[[[[[[[} "};
+diff -up fltk-1.3.2/src/fl_cursor_none.xpm.cursor fltk-1.3.2/src/fl_cursor_none.xpm
+--- fltk-1.3.2/src/fl_cursor_none.xpm.cursor 2013-01-30 16:07:59.534319820 +0100
++++ fltk-1.3.2/src/fl_cursor_none.xpm 2013-01-30 16:07:59.534319820 +0100
+@@ -0,0 +1,19 @@
++/* XPM */
++static const char * fl_cursor_none_xpm[] = {
++"15 15 1 1",
++" c None",
++" ",
++" ",
++" ",
++" ",
++" ",
++" ",
++" ",
++" ",
++" ",
++" ",
++" ",
++" ",
++" ",
++" ",
++" "};
+diff -up fltk-1.3.2/src/fl_cursor_nwse.xpm.cursor fltk-1.3.2/src/fl_cursor_nwse.xpm
+--- fltk-1.3.2/src/fl_cursor_nwse.xpm.cursor 2013-01-30 16:07:59.534319820 +0100
++++ fltk-1.3.2/src/fl_cursor_nwse.xpm 2013-01-30 16:07:59.535319802 +0100
+@@ -0,0 +1,46 @@
++/* XPM */
++static const char * fl_cursor_nwse_xpm[] = {
++"15 15 28 1",
++" c None",
++". c #FFFFFF",
++"+ c #000000",
++"@ c #767676",
++"# c #4E4E4E",
++"$ c #0C0C0C",
++"% c #494949",
++"& c #1B1B1B",
++"* c #4D4D4D",
++"= c #363636",
++"- c #646464",
++"; c #515151",
++"> c #242424",
++", c #585858",
++"' c #545454",
++") c #6A6A6A",
++"! c #797979",
++"~ c #444444",
++"{ c #2E2E2E",
++"] c #3B3B3B",
++"^ c #0A0A0A",
++"/ c #F7F7F7",
++"( c #595959",
++"_ c #6B6B6B",
++": c #080808",
++"< c #FEFEFE",
++"[ c #FCFCFC",
++"} c #FDFDFD",
++".......... ",
++".++++++@. ",
++".+++++#. ",
++".++++$. ",
++".+++++%. ",
++".++&+++*. .",
++".+=.-+++;. ..",
++".>. .,+++'. .).",
++".. .#+++,.!+.",
++". .~+++{++.",
++" .]+++++.",
++" .^++++.",
++" /(+++++.",
++" /_::::::.",
++" <[[[[[[[[}"};
+diff -up fltk-1.3.2/src/fl_cursor_wait.xpm.cursor fltk-1.3.2/src/fl_cursor_wait.xpm
+--- fltk-1.3.2/src/fl_cursor_wait.xpm.cursor 2013-01-30 16:07:59.535319802 +0100
++++ fltk-1.3.2/src/fl_cursor_wait.xpm 2013-01-30 16:07:59.535319802 +0100
+@@ -0,0 +1,72 @@
++/* XPM */
++static const char * fl_cursor_wait_xpm[] = {
++"17 32 37 1",
++" c None",
++". c #FFFFFF",
++"+ c #2E2E2E",
++"@ c #202020",
++"# c #F1F1F1",
++"$ c #2D2D2D",
++"% c #000000",
++"& c #EDEDED",
++"* c #585858",
++"= c #575757",
++"- c #FBFBFB",
++"; c #848484",
++"> c #B8B8B8",
++", c #E5E5E5",
++"' c #F7F7F7",
++") c #181818",
++"! c #F0F0F0",
++"~ c #616161",
++"{ c #B7B7B7",
++"] c #F5F5F5",
++"^ c #050505",
++"/ c #D4D4D4",
++"( c #EEEEEE",
++"_ c #595959",
++": c #7B7B7B",
++"< c #E9E9E9",
++"[ c #131313",
++"} c #E3E3E3",
++"| c #767676",
++"1 c #505050",
++"2 c #F3F3F3",
++"3 c #2A2A2A",
++"4 c #070707",
++"5 c #343434",
++"6 c #939393",
++"7 c #191919",
++"8 c #6A6A6A",
++".................",
++".+@@@@@@@@@@@@@+.",
++".................",
++" #$%%%%%%%%%%%$# ",
++" &*%%%%%%%%%%%=& ",
++" -;%%%%%%%%%%%;- ",
++" >%%%%%%%%%%%> ",
++" ,%%%%%%%%%%%, ",
++" ')%%%%%%%%%)' ",
++" !~%%%%%%%%%~! ",
++" {%%%%%%%%%{ ",
++" ]^/...../^] ",
++" (_:.....:_( ",
++" <[}...}[< ",
++" !|1...1|! ",
++" 2[3.3[2 ",
++" 2[%.%[2 ",
++" !|%%.%%|! ",
++" <4%%.%%4< ",
++" (_%%%.%%%_( ",
++" ]^%%%.%%%^] ",
++" {%%%%.%%%%{ ",
++" !~%%%%.%%%%~! ",
++" ')%%%%.%%%%)' ",
++" ,%%56{.{65%%, ",
++" >%*.......*%> ",
++" -;7&.......&7;- ",
++" &*8.........8=& ",
++" #$%%%%%%%%%%%$# ",
++".................",
++".+@@@@@@@@@@@@@+.",
++"................."};
+diff -up fltk-1.3.2/src/Fl_win32.cxx.cursor fltk-1.3.2/src/Fl_win32.cxx
+--- fltk-1.3.2/src/Fl_win32.cxx.cursor 2013-01-30 16:07:59.519320086 +0100
++++ fltk-1.3.2/src/Fl_win32.cxx 2013-01-30 16:07:59.536319784 +0100
+@@ -1633,7 +1633,6 @@ void fl_fix_focus(); // in Fl.cxx
+
+ char fl_show_iconic; // hack for Fl_Window::iconic()
+ // int fl_background_pixel = -1; // color to use for background
+-HCURSOR fl_default_cursor;
+ UINT fl_wake_msg = 0;
+ int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
+
+@@ -1682,7 +1681,7 @@ Fl_X* Fl_X::make(Fl_Window* w) {
+ if (!w->icon())
+ w->icon((void *)LoadIcon(NULL, IDI_APPLICATION));
+ wcw.hIcon = wcw.hIconSm = (HICON)w->icon();
+- wcw.hCursor = fl_default_cursor = LoadCursor(NULL, IDC_ARROW);
++ wcw.hCursor = LoadCursor(NULL, IDC_ARROW);
+ //uchar r,g,b; Fl::get_color(FL_GRAY,r,g,b);
+ //wc.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(r,g,b));
+ wcw.hbrBackground = NULL;
+@@ -1774,7 +1773,8 @@ Fl_X* Fl_X::make(Fl_Window* w) {
+ x->setwindow(w);
+ x->region = 0;
+ x->private_dc = 0;
+- x->cursor = fl_default_cursor;
++ x->cursor = LoadCursor(NULL, IDC_ARROW);
++ x->custom_cursor = 0;
+ if (!fl_codepage) fl_get_codepage();
+
+ WCHAR *lab = NULL;
+@@ -2025,6 +2025,153 @@ void Fl_Window::label(const char *name,c
+ }
+
+ ////////////////////////////////////////////////////////////////
++
++#ifndef IDC_HAND
++# define IDC_HAND MAKEINTRESOURCE(32649)
++#endif // !IDC_HAND
++
++int Fl_X::set_cursor(Fl_Cursor c) {
++ LPSTR n;
++ HCURSOR new_cursor;
++
++ if (c == FL_CURSOR_NONE)
++ new_cursor = NULL;
++ else {
++ switch (c) {
++ case FL_CURSOR_ARROW: n = IDC_ARROW; break;
++ case FL_CURSOR_CROSS: n = IDC_CROSS; break;
++ case FL_CURSOR_WAIT: n = IDC_WAIT; break;
++ case FL_CURSOR_INSERT: n = IDC_IBEAM; break;
++ case FL_CURSOR_HAND: n = IDC_HAND; break;
++ case FL_CURSOR_HELP: n = IDC_HELP; break;
++ case FL_CURSOR_MOVE: n = IDC_SIZEALL; break;
++ case FL_CURSOR_N:
++ case FL_CURSOR_S:
++ // FIXME: Should probably have fallbacks for these instead
++ case FL_CURSOR_NS: n = IDC_SIZENS; break;
++ case FL_CURSOR_NE:
++ case FL_CURSOR_SW:
++ // FIXME: Dito.
++ case FL_CURSOR_NESW: n = IDC_SIZENESW; break;
++ case FL_CURSOR_E:
++ case FL_CURSOR_W:
++ // FIXME: Dito.
++ case FL_CURSOR_WE: n = IDC_SIZEWE; break;
++ case FL_CURSOR_SE:
++ case FL_CURSOR_NW:
++ // FIXME: Dito.
++ case FL_CURSOR_NWSE: n = IDC_SIZENWSE; break;
++ default:
++ return 0;
++ }
++
++ new_cursor = LoadCursor(NULL, n);
++ if (new_cursor == NULL)
++ return 0;
++ }
++
++ if ((cursor != NULL) && custom_cursor)
++ DestroyIcon(cursor);
++
++ cursor = new_cursor;
++ custom_cursor = 0;
++
++ SetCursor(cursor);
++
++ return 1;
++}
++
++int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
++ BITMAPV5HEADER bi;
++ HBITMAP bitmap, mask;
++ DWORD *bits;
++ HCURSOR new_cursor;
++
++ if ((hotx < 0) || (hotx >= image->w()))
++ return 0;
++ if ((hoty < 0) || (hoty >= image->h()))
++ return 0;
++
++ memset(&bi, 0, sizeof(BITMAPV5HEADER));
++
++ bi.bV5Size = sizeof(BITMAPV5HEADER);
++ bi.bV5Width = image->w();
++ bi.bV5Height = -image->h(); // Negative for top-down
++ bi.bV5Planes = 1;
++ bi.bV5BitCount = 32;
++ bi.bV5Compression = BI_BITFIELDS;
++ bi.bV5RedMask = 0x00FF0000;
++ bi.bV5GreenMask = 0x0000FF00;
++ bi.bV5BlueMask = 0x000000FF;
++ bi.bV5AlphaMask = 0xFF000000;
++
++ HDC hdc;
++
++ hdc = GetDC(NULL);
++ bitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
++ ReleaseDC(NULL, hdc);
++
++ if (bits == NULL)
++ return 0;
++
++ const uchar *i = (const uchar*)*image->data();
++ for (int y = 0;y < image->h();y++) {
++ for (int x = 0;x < image->w();x++) {
++ switch (image->d()) {
++ case 1:
++ *bits = (0xff<<24) | (i[0]<<16) | (i[0]<<8) | i[0];
++ break;
++ case 2:
++ *bits = (i[1]<<24) | (i[0]<<16) | (i[0]<<8) | i[0];
++ break;
++ case 3:
++ *bits = (0xff<<24) | (i[0]<<16) | (i[1]<<8) | i[2];
++ break;
++ case 4:
++ *bits = (i[3]<<24) | (i[0]<<16) | (i[1]<<8) | i[2];
++ break;
++ }
++ i += image->d();
++ bits++;
++ }
++ i += image->ld();
++ }
++
++ // A mask bitmap is still needed even though it isn't used
++ mask = CreateBitmap(image->w(),image->h(),1,1,NULL);
++ if (mask == NULL) {
++ DeleteObject(bitmap);
++ return 0;
++ }
++
++ ICONINFO ii;
++
++ ii.fIcon = FALSE;
++ ii.xHotspot = hotx;
++ ii.yHotspot = hoty;
++ ii.hbmMask = mask;
++ ii.hbmColor = bitmap;
++
++ new_cursor = CreateIconIndirect(&ii);
++
++ DeleteObject(bitmap);
++ DeleteObject(mask);
++
++ if (new_cursor == NULL)
++ return 0;
++
++ if ((cursor != NULL) && custom_cursor)
++ DestroyIcon(cursor);
++
++ cursor = new_cursor;
++ custom_cursor = 1;
++
++ SetCursor(cursor);
++
++ return 1;
++}
++
++////////////////////////////////////////////////////////////////
+ // Implement the virtual functions for the base Fl_Window class:
+
+ // If the box is a filled rectangle, we can make the redisplay *look*
+diff -up fltk-1.3.2/src/Fl_Window.cxx.cursor fltk-1.3.2/src/Fl_Window.cxx
+--- fltk-1.3.2/src/Fl_Window.cxx.cursor 2012-11-06 21:46:14.000000000 +0100
++++ fltk-1.3.2/src/Fl_Window.cxx 2013-01-30 16:07:59.536319784 +0100
+@@ -62,8 +62,6 @@ void Fl_Window::_Fl_Window() {
+ Fl_Window::Fl_Window(int X,int Y,int W, int H, const char *l)
+ : Fl_Group(X, Y, W, H, l) {
+ cursor_default = FL_CURSOR_DEFAULT;
+- cursor_fg = FL_BLACK;
+- cursor_bg = FL_WHITE;
+
+ _Fl_Window();
+ set_flag(FORCE_POSITION);
+@@ -73,8 +71,6 @@ Fl_Window::Fl_Window(int W, int H, const
+ // fix common user error of a missing end() with current(0):
+ : Fl_Group((Fl_Group::current(0),0), 0, W, H, l) {
+ cursor_default = FL_CURSOR_DEFAULT;
+- cursor_fg = FL_BLACK;
+- cursor_bg = FL_WHITE;
+
+ _Fl_Window();
+ clear_visible();
+diff -up fltk-1.3.2/src/Fl_x.cxx.cursor fltk-1.3.2/src/Fl_x.cxx
+--- fltk-1.3.2/src/Fl_x.cxx.cursor 2013-01-30 16:07:59.512320211 +0100
++++ fltk-1.3.2/src/Fl_x.cxx 2013-01-30 16:07:59.537319766 +0100
+@@ -59,6 +59,11 @@ static int xfixes_event_base = 0;
+ static bool have_xfixes = false;
+ # endif
+
++# include <X11/cursorfont.h>
++
++# if HAVE_XCURSOR
++# include <X11/Xcursor/Xcursor.h>
++# endif
+ static Fl_Xlib_Graphics_Driver fl_xlib_driver;
+ static Fl_Display_Device fl_xlib_display(&fl_xlib_driver);
+ Fl_Display_Device *Fl_Display_Device::_display = &fl_xlib_display;// the platform display
+@@ -2259,6 +2264,94 @@ void Fl_Window::size_range_() {
+ }
+
+ ////////////////////////////////////////////////////////////////
++
++int Fl_X::set_cursor(Fl_Cursor c) {
++ unsigned int shape;
++ Cursor xc;
++
++ switch (c) {
++ case FL_CURSOR_ARROW: shape = XC_left_ptr; break;
++ case FL_CURSOR_CROSS: shape = XC_tcross; break;
++ case FL_CURSOR_WAIT: shape = XC_watch; break;
++ case FL_CURSOR_INSERT: shape = XC_xterm; break;
++ case FL_CURSOR_HAND: shape = XC_hand2; break;
++ case FL_CURSOR_HELP: shape = XC_question_arrow; break;
++ case FL_CURSOR_MOVE: shape = XC_fleur; break;
++ case FL_CURSOR_NS: shape = XC_sb_v_double_arrow; break;
++ case FL_CURSOR_WE: shape = XC_sb_h_double_arrow; break;
++ case FL_CURSOR_NE: shape = XC_top_right_corner; break;
++ case FL_CURSOR_N: shape = XC_top_side; break;
++ case FL_CURSOR_NW: shape = XC_top_left_corner; break;
++ case FL_CURSOR_E: shape = XC_right_side; break;
++ case FL_CURSOR_W: shape = XC_left_side; break;
++ case FL_CURSOR_SE: shape = XC_bottom_right_corner; break;
++ case FL_CURSOR_S: shape = XC_bottom_side; break;
++ case FL_CURSOR_SW: shape = XC_bottom_left_corner; break;
++ default:
++ return 0;
++ }
++
++ xc = XCreateFontCursor(fl_display, shape);
++ XDefineCursor(fl_display, xid, xc);
++ XFreeCursor(fl_display, xc);
++
++ return 1;
++}
++
++int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
++#if ! HAVE_XCURSOR
++ return 0;
++#else
++ XcursorImage *cursor;
++ Cursor xc;
++
++ if ((hotx < 0) || (hotx >= image->w()))
++ return 0;
++ if ((hoty < 0) || (hoty >= image->h()))
++ return 0;
++
++ cursor = XcursorImageCreate(image->w(), image->h());
++ if (!cursor)
++ return 0;
++
++ const uchar *i = (const uchar*)*image->data();
++ XcursorPixel *o = cursor->pixels;
++ for (int y = 0;y < image->h();y++) {
++ for (int x = 0;x < image->w();x++) {
++ switch (image->d()) {
++ case 1:
++ *o = (0xff<<24) | (i[0]<<16) | (i[0]<<8) | i[0];
++ break;
++ case 2:
++ *o = (i[1]<<24) | (i[0]<<16) | (i[0]<<8) | i[0];
++ break;
++ case 3:
++ *o = (0xff<<24) | (i[0]<<16) | (i[1]<<8) | i[2];
++ break;
++ case 4:
++ *o = (i[3]<<24) | (i[0]<<16) | (i[1]<<8) | i[2];
++ break;
++ }
++ i += image->d();
++ o++;
++ }
++ i += image->ld();
++ }
++
++ cursor->xhot = hotx;
++ cursor->yhot = hoty;
++
++ xc = XcursorImageLoadCursor(fl_display, cursor);
++ XDefineCursor(fl_display, xid, xc);
++ XFreeCursor(fl_display, xc);
++
++ XcursorImageDestroy(cursor);
++
++ return 1;
++#endif
++}
++
++////////////////////////////////////////////////////////////////
+
+ // returns pointer to the filename, or null if name ends with '/'
+ const char *fl_filename_name(const char *name) {
+diff -up fltk-1.3.2/test/cursor.cxx.cursor fltk-1.3.2/test/cursor.cxx
+--- fltk-1.3.2/test/cursor.cxx.cursor 2011-07-19 06:49:30.000000000 +0200
++++ fltk-1.3.2/test/cursor.cxx 2013-01-30 16:07:59.537319766 +0100
+@@ -23,8 +23,6 @@
+ #include <FL/fl_draw.H>
+ #include <FL/Fl_Box.H>
+
+-Fl_Color fg = FL_BLACK;
+-Fl_Color bg = FL_WHITE;
+ Fl_Cursor cursor = FL_CURSOR_DEFAULT;
+
+ Fl_Hor_Value_Slider *cursor_slider;
+@@ -32,7 +30,7 @@ Fl_Hor_Value_Slider *cursor_slider;
+ void choice_cb(Fl_Widget *, void *v) {
+ cursor = (Fl_Cursor)(fl_intptr_t)v;
+ cursor_slider->value(cursor);
+- fl_cursor(cursor,fg,bg);
++ fl_cursor(cursor);
+ }
+
+ Fl_Menu_Item choices[] = {
+@@ -48,8 +46,6 @@ Fl_Menu_Item choices[] = {
+ {"FL_CURSOR_WE",0,choice_cb,(void*)FL_CURSOR_WE},
+ {"FL_CURSOR_NWSE",0,choice_cb,(void*)FL_CURSOR_NWSE},
+ {"FL_CURSOR_NESW",0,choice_cb,(void*)FL_CURSOR_NESW},
+- {"FL_CURSOR_NONE",0,choice_cb,(void*)FL_CURSOR_NONE},
+-#if 0
+ {"FL_CURSOR_N",0,choice_cb,(void*)FL_CURSOR_N},
+ {"FL_CURSOR_NE",0,choice_cb,(void*)FL_CURSOR_NE},
+ {"FL_CURSOR_E",0,choice_cb,(void*)FL_CURSOR_E},
+@@ -58,26 +54,14 @@ Fl_Menu_Item choices[] = {
+ {"FL_CURSOR_SW",0,choice_cb,(void*)FL_CURSOR_SW},
+ {"FL_CURSOR_W",0,choice_cb,(void*)FL_CURSOR_W},
+ {"FL_CURSOR_NW",0,choice_cb,(void*)FL_CURSOR_NW},
+-#endif
++ {"FL_CURSOR_NONE",0,choice_cb,(void*)FL_CURSOR_NONE},
+ {0}
+ };
+
+ void setcursor(Fl_Widget *o, void *) {
+ Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
+ cursor = Fl_Cursor((int)slider->value());
+- fl_cursor(cursor,fg,bg);
+-}
+-
+-void setfg(Fl_Widget *o, void *) {
+- Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
+- fg = Fl_Color((int)slider->value());
+- fl_cursor(cursor,fg,bg);
+-}
+-
+-void setbg(Fl_Widget *o, void *) {
+- Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
+- bg = Fl_Color((int)slider->value());
+- fl_cursor(cursor,fg,bg);
++ fl_cursor(cursor);
+ }
+
+ // draw the label without any ^C or \nnn conversions:
+@@ -103,29 +87,11 @@ int main(int argc, char **argv) {
+ slider1.align(FL_ALIGN_LEFT);
+ slider1.step(1);
+ slider1.precision(0);
+- slider1.bounds(0,100);
++ slider1.bounds(0,255);
+ slider1.value(0);
+ slider1.callback(setcursor);
+ slider1.value(cursor);
+
+- Fl_Hor_Value_Slider slider2(80,220,310,30,"fgcolor:");
+- slider2.align(FL_ALIGN_LEFT);
+- slider2.step(1);
+- slider2.precision(0);
+- slider2.bounds(0,255);
+- slider2.value(0);
+- slider2.callback(setfg);
+- slider2.value(fg);
+-
+- Fl_Hor_Value_Slider slider3(80,260,310,30,"bgcolor:");
+- slider3.align(FL_ALIGN_LEFT);
+- slider3.step(1);
+- slider3.precision(0);
+- slider3.bounds(0,255);
+- slider3.value(0);
+- slider3.callback(setbg);
+- slider3.value(bg);
+-
+ #if 0
+ // draw the manual's diagram of cursors...
+ window.size(400,800);
--- /dev/null
+diff -up fltk-1.3.2/CMakeLists.txt.clp-x11 fltk-1.3.2/CMakeLists.txt
+--- fltk-1.3.2/CMakeLists.txt.clp-x11 2012-09-13 16:19:01.000000000 +0200
++++ fltk-1.3.2/CMakeLists.txt 2013-01-30 15:56:25.810663430 +0100
+@@ -515,6 +515,20 @@ else()
+ endif(OPTION_USE_XINERAMA)
+
+ #######################################################################
++if(X11_Xfixes_FOUND)
++ option(OPTION_USE_XFIXES "use lib XFIXES" ON)
++endif(X11_Xfixes_FOUND)
++
++if(OPTION_USE_XFIXES)
++ set(HAVE_XFIXES ${X11_Xfixes_FOUND})
++ include_directories(${X11_Xfixes_INCLUDE_PATH})
++ list(APPEND FLTK_LDLIBS -lXfixes)
++ set(FLTK_XFIXES_FOUND TRUE)
++else()
++ set(FLTK_XFIXES_FOUND FALSE)
++endif(OPTION_USE_XFIXES)
++
++#######################################################################
+ if(X11_Xft_FOUND)
+ option(OPTION_USE_XFT "use lib Xft" ON)
+ endif(X11_Xft_FOUND)
+diff -up fltk-1.3.2/configh.cmake.in.clp-x11 fltk-1.3.2/configh.cmake.in
+--- fltk-1.3.2/configh.cmake.in.clp-x11 2011-07-19 06:49:30.000000000 +0200
++++ fltk-1.3.2/configh.cmake.in 2013-01-30 15:56:25.810663430 +0100
+@@ -108,6 +108,14 @@
+ #define USE_XDBE HAVE_XDBE
+
+ /*
++ * HAVE_XFIXES:
++ *
++ * Do we have the X fixes extension?
++ */
++
++#cmakedefine01 HAVE_XFIXES
++
++/*
+ * __APPLE_QUARTZ__:
+ *
+ * If __APPLE_QUARTZ__ is defined, FLTK will be
+diff -up fltk-1.3.2/configh.in.clp-x11 fltk-1.3.2/configh.in
+--- fltk-1.3.2/configh.in.clp-x11 2011-10-04 11:21:47.000000000 +0200
++++ fltk-1.3.2/configh.in 2013-01-30 15:56:25.810663430 +0100
+@@ -108,6 +108,14 @@
+ #define USE_XDBE HAVE_XDBE
+
+ /*
++ * HAVE_XFIXES:
++ *
++ * Do we have the X fixes extension?
++ */
++
++#define HAVE_XFIXES 0
++
++/*
+ * __APPLE_QUARTZ__:
+ *
+ * All Apple implementations are now based on Quartz and Cocoa,
+diff -up fltk-1.3.2/configure.in.clp-x11 fltk-1.3.2/configure.in
+--- fltk-1.3.2/configure.in.clp-x11 2013-01-30 15:56:25.802663573 +0100
++++ fltk-1.3.2/configure.in 2013-01-30 15:56:25.810663430 +0100
+@@ -999,6 +999,16 @@ case $uname_GUI in
+ LIBS="-lXext $LIBS")
+ fi
+
++ dnl Check for the Xfixes extension unless disabled...
++ AC_ARG_ENABLE(xfixes, [ --enable-xfixes turn on Xfixes support [default=yes]])
++
++ if test x$enable_xfixes != xno; then
++ AC_CHECK_HEADER(X11/extensions/Xfixes.h, AC_DEFINE(HAVE_XFIXES),,
++ [#include <X11/Xlib.h>])
++ AC_CHECK_LIB(Xfixes, XFixesQueryExtension,
++ LIBS="-lXfixes $LIBS")
++ fi
++
+ dnl Check for overlay visuals...
+ AC_PATH_PROG(XPROP, xprop)
+ AC_CACHE_CHECK(for X overlay visuals, ac_cv_have_overlay,
+diff -up fltk-1.3.2/fluid/CMakeLists.txt.clp-x11 fltk-1.3.2/fluid/CMakeLists.txt
+diff -up fltk-1.3.2/src/CMakeLists.txt.clp-x11 fltk-1.3.2/src/CMakeLists.txt
+--- fltk-1.3.2/src/CMakeLists.txt.clp-x11 2013-01-30 16:06:00.785430590 +0100
++++ fltk-1.3.2/src/CMakeLists.txt 2013-01-30 16:06:17.883126642 +0100
+@@ -243,6 +243,10 @@ if(HAVE_XINERAMA)
+ target_link_libraries(fltk ${X11_Xinerama_LIB})
+ endif(HAVE_XINERAMA)
+
++if(HAVE_XFIXES)
++ target_link_libraries(fltk ${X11_Xfixes_LIB})
++endif(HAVE_XFIXES)
++
+ if(USE_XFT)
+ target_link_libraries(fltk ${X11_Xft_LIB})
+ endif(USE_XFT)
+diff -up fltk-1.3.2/src/Fl_x.cxx.clp-x11 fltk-1.3.2/src/Fl_x.cxx
+--- fltk-1.3.2/src/Fl_x.cxx.clp-x11 2013-01-30 15:56:25.793663733 +0100
++++ fltk-1.3.2/src/Fl_x.cxx 2013-01-30 16:03:37.355981103 +0100
+@@ -53,6 +53,12 @@ static XRRUpdateConfiguration_type XRRUp
+ static int randrEventBase; // base of RandR-defined events
+ #endif
+
++# if HAVE_XFIXES
++# include <X11/extensions/Xfixes.h>
++static int xfixes_event_base = 0;
++static bool have_xfixes = false;
++# endif
++
+ static Fl_Xlib_Graphics_Driver fl_xlib_driver;
+ static Fl_Display_Device fl_xlib_display(&fl_xlib_driver);
+ Fl_Display_Device *Fl_Display_Device::_display = &fl_xlib_display;// the platform display
+@@ -307,6 +313,9 @@ static Atom WM_PROTOCOLS;
+ static Atom fl_MOTIF_WM_HINTS;
+ static Atom TARGETS;
+ static Atom CLIPBOARD;
++static Atom TIMESTAMP;
++static Atom PRIMARY_TIMESTAMP;
++static Atom CLIPBOARD_TIMESTAMP;
+ Atom fl_XdndAware;
+ Atom fl_XdndSelection;
+ Atom fl_XdndEnter;
+@@ -667,6 +676,9 @@ void fl_open_display(Display* d) {
+ fl_MOTIF_WM_HINTS = XInternAtom(d, "_MOTIF_WM_HINTS", 0);
+ TARGETS = XInternAtom(d, "TARGETS", 0);
+ CLIPBOARD = XInternAtom(d, "CLIPBOARD", 0);
++ TIMESTAMP = XInternAtom(d, "TIMESTAMP", 0);
++ PRIMARY_TIMESTAMP = XInternAtom(d, "PRIMARY_TIMESTAMP", 0);
++ CLIPBOARD_TIMESTAMP = XInternAtom(d, "CLIPBOARD_TIMESTAMP", 0);
+ fl_XdndAware = XInternAtom(d, "XdndAware", 0);
+ fl_XdndSelection = XInternAtom(d, "XdndSelection", 0);
+ fl_XdndEnter = XInternAtom(d, "XdndEnter", 0);
+@@ -713,6 +725,15 @@ void fl_open_display(Display* d) {
+ #if !USE_COLORMAP
+ Fl::visual(FL_RGB);
+ #endif
++
++#if HAVE_XFIXES
++ int error_base;
++ if (XFixesQueryExtension(fl_display, &xfixes_event_base, &error_base))
++ have_xfixes = true;
++ else
++ have_xfixes = false;
++#endif
++
+ #if USE_XRANDR
+ void *libxrandr_addr = dlopen("libXrandr.so.2", RTLD_LAZY);
+ if (!libxrandr_addr) libxrandr_addr = dlopen("libXrandr.so", RTLD_LAZY);
+@@ -901,6 +922,107 @@ void Fl::copy(const char *stuff, int len
+ }
+
+ ////////////////////////////////////////////////////////////////
++// Code for tracking clipboard changes:
++
++static Time primary_timestamp = -1;
++static Time clipboard_timestamp = -1;
++
++extern bool fl_clipboard_notify_empty(void);
++extern void fl_trigger_clipboard_notify(int source);
++
++static void poll_clipboard_owner(void) {
++ Window xid;
++
++#if HAVE_XFIXES
++ // No polling needed with Xfixes
++ if (have_xfixes)
++ return;
++#endif
++
++ // No one is interested, so no point polling
++ if (fl_clipboard_notify_empty())
++ return;
++
++ // We need a window for this to work
++ if (!Fl::first_window())
++ return;
++ xid = fl_xid(Fl::first_window());
++ if (!xid)
++ return;
++
++ // Request an update of the selection time for both the primary and
++ // clipboard selections. Magic continues when we get a SelectionNotify.
++ if (!fl_i_own_selection[0])
++ XConvertSelection(fl_display, XA_PRIMARY, TIMESTAMP, PRIMARY_TIMESTAMP,
++ xid, fl_event_time);
++ if (!fl_i_own_selection[1])
++ XConvertSelection(fl_display, CLIPBOARD, TIMESTAMP, CLIPBOARD_TIMESTAMP,
++ xid, fl_event_time);
++}
++
++static void clipboard_timeout(void *data)
++{
++ // No one is interested, so stop polling
++ if (fl_clipboard_notify_empty())
++ return;
++
++ poll_clipboard_owner();
++
++ Fl::repeat_timeout(0.5, clipboard_timeout);
++}
++
++static void handle_clipboard_timestamp(int clipboard, Time time)
++{
++ Time *timestamp;
++
++ timestamp = clipboard ? &clipboard_timestamp : &primary_timestamp;
++
++#if HAVE_XFIXES
++ if (!have_xfixes)
++#endif
++ {
++ // Initial scan, just store the value
++ if (*timestamp == (Time)-1) {
++ *timestamp = time;
++ return;
++ }
++ }
++
++ // Same selection
++ if (time == *timestamp)
++ return;
++
++ *timestamp = time;
++
++ // The clipboard change is the event that caused us to request
++ // the clipboard data, so use that time as the latest event.
++ if (time > fl_event_time)
++ fl_event_time = time;
++
++ // Something happened! Let's tell someone!
++ fl_trigger_clipboard_notify(clipboard);
++}
++
++void fl_clipboard_notify_change() {
++ // Reset the timestamps if we've going idle so that you don't
++ // get a bogus immediate trigger next time they're activated.
++ if (fl_clipboard_notify_empty()) {
++ primary_timestamp = -1;
++ clipboard_timestamp = -1;
++ } else {
++#if HAVE_XFIXES
++ if (!have_xfixes)
++#endif
++ {
++ poll_clipboard_owner();
++
++ if (!Fl::has_timeout(clipboard_timeout))
++ Fl::add_timeout(0.5, clipboard_timeout);
++ }
++ }
++}
++
++////////////////////////////////////////////////////////////////
+
+ const XEvent* fl_xevent; // the current x event
+ ulong fl_event_time; // the last timestamp from an x event
+@@ -1024,7 +1141,6 @@ int fl_handle(const XEvent& thisevent)
+ return 0;
+
+ case SelectionNotify: {
+- if (!fl_selection_requestor) return 0;
+ static unsigned char* buffer = 0;
+ if (buffer) {XFree(buffer); buffer = 0;}
+ long bytesread = 0;
+@@ -1040,6 +1156,19 @@ int fl_handle(const XEvent& thisevent)
+ bytesread/4, 65536, 1, 0,
+ &actual, &format, &count, &remaining,
+ &portion)) break; // quit on error
++
++ if ((fl_xevent->xselection.property == PRIMARY_TIMESTAMP) ||
++ (fl_xevent->xselection.property == CLIPBOARD_TIMESTAMP)) {
++ if (portion && format == 32 && count == 1) {
++ Time t = *(unsigned int*)portion;
++ if (fl_xevent->xselection.property == CLIPBOARD_TIMESTAMP)
++ handle_clipboard_timestamp(1, t);
++ else
++ handle_clipboard_timestamp(0, t);
++ }
++ return true;
++ }
++
+ if (actual == TARGETS || actual == XA_ATOM) {
+ Atom type = XA_STRING;
+ for (unsigned i = 0; i<count; i++) {
+@@ -1076,6 +1205,9 @@ int fl_handle(const XEvent& thisevent)
+ buffer[bytesread] = 0;
+ convert_crlf(buffer, bytesread);
+ }
++
++ if (!fl_selection_requestor) return 0;
++
+ Fl::e_text = buffer ? (char*)buffer : (char *)"";
+ Fl::e_length = bytesread;
+ int old_event = Fl::e_number;
+@@ -1096,6 +1228,7 @@ int fl_handle(const XEvent& thisevent)
+ case SelectionClear: {
+ int clipboard = fl_xevent->xselectionclear.selection == CLIPBOARD;
+ fl_i_own_selection[clipboard] = 0;
++ poll_clipboard_owner();
+ return 1;}
+
+ case SelectionRequest: {
+@@ -1308,6 +1441,9 @@ int fl_handle(const XEvent& thisevent)
+ case FocusIn:
+ if (fl_xim_ic) XSetICFocus(fl_xim_ic);
+ event = FL_FOCUS;
++ // If the user has toggled from another application to this one,
++ // then it's a good time to check for clipboard changes.
++ poll_clipboard_owner();
+ break;
+
+ case FocusOut:
+@@ -1676,6 +1812,25 @@ int fl_handle(const XEvent& thisevent)
+ }
+ }
+
++#if HAVE_XFIXES
++ switch (xevent.type - xfixes_event_base) {
++ case XFixesSelectionNotify: {
++ // Someone feeding us bogus events?
++ if (!have_xfixes)
++ return true;
++
++ XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)&xevent;
++
++ if ((selection_notify->selection == XA_PRIMARY) && !fl_i_own_selection[0])
++ handle_clipboard_timestamp(0, selection_notify->selection_timestamp);
++ else if ((selection_notify->selection == CLIPBOARD) && !fl_i_own_selection[1])
++ handle_clipboard_timestamp(1, selection_notify->selection_timestamp);
++
++ return true;
++ }
++ }
++#endif
++
+ return Fl::handle(event, window);
+ }
+
+@@ -1995,6 +2150,16 @@ void Fl_X::make_xid(Fl_Window* win, XVis
+ XChangeProperty(fl_display, xp->xid, net_wm_type, XA_ATOM, 32, PropModeReplace, (unsigned char*)&net_wm_type_kind, 1);
+ }
+
++#if HAVE_XFIXES
++ // register for clipboard change notifications
++ if (have_xfixes && !win->parent()) {
++ XFixesSelectSelectionInput(fl_display, xp->xid, XA_PRIMARY,
++ XFixesSetSelectionOwnerNotifyMask);
++ XFixesSelectSelectionInput(fl_display, xp->xid, CLIPBOARD,
++ XFixesSetSelectionOwnerNotifyMask);
++ }
++#endif
++
+ XMapWindow(fl_display, xp->xid);
+ if (showit) {
+ win->set_visible();
+diff -up fltk-1.3.2/test/CMakeLists.txt.clp-x11 fltk-1.3.2/test/CMakeLists.txt
--- /dev/null
+diff -ur fltk-1.3.0r9619.org/configure.in fltk-1.3.0r9619/configure.in
+--- fltk-1.3.0r9619.org/configure.in 2012-04-22 04:45:09.000000000 +0200
++++ fltk-1.3.0r9619/configure.in 2012-06-18 13:47:33.290447462 +0200
+@@ -865,6 +865,8 @@
+ Darwin*)
+ # MacOS X uses Cocoa for graphics.
+ LIBS="$LIBS -framework Cocoa"
++ # And some Carbon for keyboard handling
++ LIBS="$LIBS -framework Carbon"
+
+ if test x$have_pthread = xyes; then
+ AC_DEFINE(HAVE_PTHREAD)
+diff -ur fltk-1.3.0r9619.org/src/Fl_cocoa.mm fltk-1.3.0r9619/src/Fl_cocoa.mm
+--- fltk-1.3.0r9619.org/src/Fl_cocoa.mm 2012-06-16 10:49:52.000000000 +0200
++++ fltk-1.3.0r9619/src/Fl_cocoa.mm 2012-06-18 13:47:42.944910782 +0200
+@@ -53,6 +53,7 @@
+ #include <math.h>
+
+ #import <Cocoa/Cocoa.h>
++#import <Carbon/Carbon.h>
+
+ #ifndef NSINTEGER_DEFINED // appears with 10.5 in NSObjCRuntime.h
+ #if defined(__LP64__) && __LP64__
+@@ -114,6 +115,8 @@
+ extern Fl_Window* fl_xmousewin;
+ #endif
+
++bool use_simple_keyboard = false;
++
+ enum { FLTKTimerEvent = 1, FLTKDataReadyEvent };
+
+
+@@ -130,6 +133,39 @@
+ {
+ }
+
++// Undocumented voodoo. Taken from Mozilla.
++#define ENABLE_ROMAN_KYBDS_ONLY -23
++
++void fl_update_focus(void)
++{
++ Fl_Widget *focus;
++
++ focus = Fl::grab();
++ if (!focus)
++ focus = Fl::focus();
++ if (!focus)
++ return;
++
++ if (focus->simple_keyboard())
++ use_simple_keyboard = true;
++ else
++ use_simple_keyboard = false;
++
++ // Force a "Roman" or "ASCII" keyboard, which both the Mozilla and
++ // Safari people seem to think implies turning off advanced IME stuff
++ // (see nsTSMManager::SyncKeyScript in Mozilla and enableSecureTextInput
++ // in Safari/Webcore). Should be good enough for us then...
++#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
++ CFArrayRef inputSources = TISCreateASCIICapableInputSourceList();
++ TSMSetDocumentProperty(TSMGetActiveDocument(),
++ kTSMDocumentEnabledInputSourcesPropertyTag,
++ sizeof(CFArrayRef), &inputSources);
++ CFRelease(inputSources);
++#else
++ KeyScript(use_simple_keyboard ? ENABLE_ROMAN_KYBDS_ONLY : smKeyEnableKybds);
++#endif
++}
++
+ /*
+ * Mac keyboard lookup table
+ */
+@@ -908,6 +944,25 @@
+ }
+ @end
+
++static const char* cocoaDead2FLTK(const char *in)
++{
++ if (strcmp(in, "\140") == 0) // GRAVE ACCENT
++ return "\314\200"; // COMBINING GRAVE ACCENT
++ if (strcmp(in, "\302\264") == 0) // ACUTE ACCENT
++ return "\314\201"; // COMBINING ACUTE ACCENT
++ if (strcmp(in, "\136") == 0) // CIRCUMFLEX ACCENT
++ return "\314\202"; // COMBINING CIRCUMFLEX ACCENT
++ if (strcmp(in, "\176") == 0) // TILDE
++ return "\314\203"; // COMBINING TILDE
++ if (strcmp(in, "\302\250") == 0) // DIAERESIS
++ return "\314\210"; // COMBINING DIAERESIS
++ // FIXME: OS X dead key behaviour isn't documented and I don't have
++ // any more keyboards to test with...
++
++ // hope that OS X gave us something proper to begin with
++ return in;
++}
++
+ /*
+ Handle cocoa keyboard events
+ Events during a character composition sequence:
+@@ -1648,6 +1703,7 @@
+ - (void)rightMouseDragged:(NSEvent *)theEvent;
+ - (void)otherMouseDragged:(NSEvent *)theEvent;
+ - (void)scrollWheel:(NSEvent *)theEvent;
+++ (NSString *)keyTranslate:(UInt16)keyCode withModifierFlags:(UInt32)modifierFlags;
+ - (BOOL)handleKeyDown:(NSEvent *)theEvent;
+ - (void)keyDown:(NSEvent *)theEvent;
+ - (void)keyUp:(NSEvent *)theEvent;
+@@ -1726,6 +1782,130 @@
+ - (void)scrollWheel:(NSEvent *)theEvent {
+ cocoaMouseWheelHandler(theEvent);
+ }
+++ (NSString *)keyTranslate:(UInt16)keyCode withModifierFlags:(UInt32)modifierFlags {
++ const UCKeyboardLayout *layout;
++ OSStatus err;
++
++ layout = NULL;
++
++#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
++ TISInputSourceRef keyboard;
++ CFDataRef uchr;
++
++ keyboard = TISCopyCurrentKeyboardInputSource();
++ uchr = (CFDataRef)TISGetInputSourceProperty(keyboard,
++ kTISPropertyUnicodeKeyLayoutData);
++ if (uchr == NULL)
++ return nil;
++
++ layout = (const UCKeyboardLayout*)CFDataGetBytePtr(uchr);
++#else
++ KeyboardLayoutRef old_layout;
++ int kind;
++
++ err = KLGetCurrentKeyboardLayout(&old_layout);
++ if (err != noErr)
++ return nil;
++
++ err = KLGetKeyboardLayoutProperty(old_layout, kKLKind,
++ (const void**)&kind);
++ if (err != noErr)
++ return nil;
++
++ // Old, crufty layout format?
++ if (kind == kKLKCHRKind) {
++ void *kchr_layout;
++
++ UInt32 chars, state;
++ char buf[3];
++
++ unichar result[16];
++ ByteCount in_len, out_len;
++
++ err = KLGetKeyboardLayoutProperty(old_layout, kKLKCHRData,
++ (const void**)&kchr_layout);
++ if (err != noErr)
++ return nil;
++
++ state = 0;
++
++ keyCode &= 0x7f;
++ modifierFlags &= 0xff00;
++
++ chars = KeyTranslate(kchr_layout, keyCode | modifierFlags, &state);
++
++ buf[0] = (chars >> 16) & 0xff;
++ buf[1] = chars & 0xff;
++ buf[2] = '\0';
++
++ if (buf[0] == '\0') {
++ buf[0] = buf[1];
++ buf[1] = '\0';
++ }
++
++ // The data is now in some layout specific encoding. Need to convert
++ // this to unicode.
++
++ ScriptCode script;
++ TextEncoding encoding;
++ TECObjectRef converter;
++
++ script = (ScriptCode)GetScriptManagerVariable(smKeyScript);
++
++ err = UpgradeScriptInfoToTextEncoding(script, kTextLanguageDontCare,
++ kTextRegionDontCare, NULL,
++ &encoding);
++ if (err != noErr)
++ return nil;
++
++ err = TECCreateConverter(&converter, encoding, kTextEncodingUnicodeV4_0);
++ if (err != noErr)
++ return nil;
++
++ in_len = strlen(buf);
++ out_len = sizeof(result);
++
++ err = TECConvertText(converter, (ConstTextPtr)buf, in_len, &in_len,
++ (TextPtr)result, out_len, &out_len);
++
++ TECDisposeConverter(converter);
++
++ if (err != noErr)
++ return nil;
++
++ return [NSString stringWithCharacters:result
++ length:(out_len / sizeof(unichar))];
++ }
++
++ if ((kind != kKLKCHRuchrKind) && (kind != kKLuchrKind))
++ return nil;
++
++ err = KLGetKeyboardLayoutProperty(old_layout, kKLuchrData,
++ (const void**)&layout);
++ if (err != noErr)
++ return nil;
++#endif
++
++ if (layout == NULL)
++ return nil;
++
++ UInt32 dead_state;
++ UniCharCount max_len, actual_len;
++ UniChar string[255];
++
++ dead_state = 0;
++ max_len = sizeof(string)/sizeof(*string);
++
++ modifierFlags = (modifierFlags >> 8) & 0xff;
++
++ err = UCKeyTranslate(layout, keyCode, kUCKeyActionDown, modifierFlags,
++ LMGetKbdType(), 0, &dead_state, max_len, &actual_len,
++ string);
++ if (err != noErr)
++ return nil;
++
++ return [NSString stringWithCharacters:string length:actual_len];
++}
+ - (BOOL)handleKeyDown:(NSEvent *)theEvent {
+ //NSLog(@"handleKeyDown");
+ fl_lock_function();
+@@ -1752,14 +1932,47 @@
+ break;
+ }
+ }
+- if (!no_text_key && !(Fl::e_state & FL_META) ) {
+- // Don't send cmd-<key> to interpretKeyEvents because it beeps.
++ if (!no_text_key) {
++ // The simple keyboard model will ignore insertText, so we need to grab
++ // the symbol directly from the event. Note that we still use setMarkedText.
++ if (use_simple_keyboard) {
++ NSString *simple_chars;
++ UInt32 modifiers;
++
++ // We want a "normal" symbol out of the event, which basically means
++ // we only respect the shift and alt/altgr modifiers. Cocoa can help
++ // us if we only wanted shift, but as we also want alt/altgr, we'll
++ // have to do some lookup ourselves. This matches our behaviour on
++ // other platforms.
++
++ modifiers = 0;
++ if ([theEvent modifierFlags] & NSAlphaShiftKeyMask)
++ modifiers |= alphaLock;
++ if ([theEvent modifierFlags] & NSShiftKeyMask)
++ modifiers |= shiftKey;
++ if ([theEvent modifierFlags] & NSAlternateKeyMask)
++ modifiers |= optionKey;
++
++ simple_chars = [FLView keyTranslate:[theEvent keyCode]
++ withModifierFlags:modifiers];
++ if (simple_chars == nil) {
++ // Something went wrong. Fall back to what Cocoa gave us...
++ simple_chars = [theEvent charactersIgnoringModifiers];
++ }
++
++ [FLView prepareEtext:simple_chars];
++ }
++
+ // Then we can let the OS have a stab at it and see if it thinks it
+ // should result in some text
+- NSText *edit = [[theEvent window] fieldEditor:YES forObject:nil];
+- in_key_event = true;
+- [edit interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
+- in_key_event = false;
++
++ // Don't send cmd-<key> to interpretKeyEvents because it beeps.
++ if (!(Fl::e_state & FL_META)) {
++ NSText *edit = [[theEvent window] fieldEditor:YES forObject:nil];
++ in_key_event = true;
++ [edit interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
++ in_key_event = false;
++ }
+ }
+ //NSLog(@"to text=%@ l=%d", [NSString stringWithUTF8String:Fl::e_text], Fl::e_length);
+ int handled = Fl::handle(FL_KEYDOWN, window);
+@@ -1937,21 +2150,30 @@
+ //NSLog(@"insertText: received=%@",received);
+
+ if (!in_key_event) fl_lock_function();
++
++ // Simple keyboard widgets do not want these side channel inputs.
++ if (use_simple_keyboard)
++ goto end;
++
+ [FLView prepareEtext:received];
++
+ // We can get called outside of key events (e.g. from the character
+- // palette). Transform such actions to FL_PASTE events.
++ // palette). We need to fake our own key event at that point.
+ if (!in_key_event) {
+ Fl_Window *target = [(FLWindow*)[self window] getFl_Window];
+- Fl::handle(FL_PASTE, target);
++ Fl::e_keysym = Fl::e_original_keysym = 0;
++ Fl::handle(FL_KEYDOWN, target);
+ // for some reason, the window does not redraw until the next mouse move or button push
+ // sending a 'redraw()' or 'awake()' does not solve the issue!
+ Fl::flush();
+ }
++
++end:
+ if (!in_key_event) fl_unlock_function();
+ }
+
+ - (void)setMarkedText:(id)aString selectedRange:(NSRange)newSelection {
+- NSString *received;
++ NSString *received, *current, *aggregate;
+ if (newSelection.location == 0) {
+ [self unmarkText];
+ return;
+@@ -1962,11 +2184,47 @@
+ received = (NSString*)aString;
+ }
+ //NSLog(@"setMarkedText: %@ %d %d",received,newSelection.location,newSelection.length);
++
++ fl_lock_function();
++
++ // Simple keyboard widgets generally do not want these side channel
++ // inputs, but we have no other way of getting dead keys so we make
++ // an exception in that case.
++ if (use_simple_keyboard) {
++ if (in_key_event && (Fl::e_length == 0)) {
++ [FLView prepareEtext:received];
++
++ Fl::e_text = (char*)cocoaDead2FLTK(Fl::e_text);
++ Fl::e_length = strlen(Fl::e_text);
++ }
++ goto end;
++ }
++
+ // This code creates the OS X behaviour of seeing dead keys as things
+ // are being composed.
++ //
++ // Note: The concatenation thing is because of how OS X deals with
++ // invalid sequences. At that point it will spit out one call
++ // to insertText with the now aborted sequence, and one new
++ // call to setMarkedText with the new sequence. Since we want
++ // both to be visible, we need to concatenate.
+ next_compose_length = newSelection.location;
+- [FLView prepareEtext:received];
+- //NSLog(@"Fl::e_text=%@ Fl::e_length=%d next_compose_length=%d", received, Fl::e_length, next_compose_length);
++ current = [NSString stringWithUTF8String:Fl::e_text];
++ aggregate = [current stringByAppendingString:received];
++
++ [FLView prepareEtext:aggregate];
++ //NSLog(@"Fl::e_text=%@ Fl::e_length=%d next_compose_length=%d", aggregate, Fl::e_length, next_compose_length);
++
++ // We can get called outside of key events (e.g. from the character
++ // palette). We need to fake our own key event at that point.
++ if (!in_key_event) {
++ Fl_Window *target = [(FLWindow*)[self window] getFl_Window];
++ Fl::e_keysym = Fl::e_original_keysym = 0;
++ Fl::handle(FL_KEYDOWN, target);
++ }
++
++end:
++ fl_unlock_function();
+ }
+
+ - (void)unmarkText {
--- /dev/null
+--- hw/xfree86/parser/Makefile.am.orig 2010-06-06 03:16:52.000000000 +0200
++++ hw/xfree86/parser/Makefile.am 2010-08-23 14:05:50.000000000 +0200
+@@ -34,7 +34,7 @@
+ $(INTERNAL_SOURCES)
+ libxf86config_a_CFLAGS = $(AM_CFLAGS)
+
+-AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS) \
++AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS) -fPIC \
+ -DSYSCONFDIR=\"$(sysconfdir)\" \
+ -DDATADIR=\"$(datadir)\"
+
--- /dev/null
+Index: hw/xfree86/common/xf86Helper.c
+================================================================================
+--- hw/xfree86/common/xf86Helper.c
++++ hw/xfree86/common/xf86Helper.c
+@@ -2183,6 +2183,13 @@
+ &errmaj, &errmin);
+ if (!ret)
+ LoaderErrorMsg(pScrn->name, name, errmaj, errmin);
++
++ /* "drm" module has been merged into "dri" module, but some drivers
++ are still trying to load it explictely and fail if it doesn't exist :-( */
++ if (!ret && !strcmp(name,"drm")) {
++ ret = (pointer) -1;
++ }
++
+ return ret;
+ }
+
--- /dev/null
+--- configure.ac
++++ configure.ac
+@@ -505,11 +505,15 @@
+ XORG_FONTSUBDIR(FONTTYPE1DIR, fonttype1dir, Type1)
+ XORG_FONTSUBDIR(FONT75DPIDIR, font75dpidir, 75dpi)
+ XORG_FONTSUBDIR(FONT100DPIDIR, font100dpidir, 100dpi)
++XORG_FONTSUBDIR(FONTURWDIR, fonturwdir, URW)
++XORG_FONTSUBDIR(FONTCYRILLICDIR, fontcyrillicdir, cyrillic)
++XORG_FONTSUBDIR(FONTSGIDIR, fontsgidir, misc/sgi)
++XORG_FONTSUBDIR(FONTTRUETYPEDIR, fonttruetypedir, truetype)
+
+ dnl Uses --default-font-path if set, otherwise checks for /etc/X11/fontpath.d,
+ dnl otherwise uses standard subdirectories of FONTROOTDIR. When cross
+ dnl compiling, assume default font path uses standard FONTROOTDIR directories.
+-DEFAULT_FONT_PATH="${FONTMISCDIR}:unscaled,${FONTTTFDIR}/,${FONTOTFDIR}/,${FONTTYPE1DIR}/,${FONT100DPIDIR}/,${FONT75DPIDIR}/"
++DEFAULT_FONT_PATH="${FONTMISCDIR}:unscaled,${FONTTTFDIR}/,${FONTOTFDIR}/,${FONTTYPE1DIR}/,${FONT100DPIDIR}:unscaled,${FONT75DPIDIR}:unscaled,${FONTURWDIR}/,${FONTCYRILLICDIR}:unscaled,${FONTSGIDIR}:unscaled,${FONTTRUETYPEDIR}/"
+ if test "$cross_compiling" != yes; then
+ AC_CHECK_FILE([${sysconfdir}/X11/fontpath.d],
+ [DEFAULT_FONT_PATH='catalogue:${sysconfdir}/X11/fontpath.d'],
--- /dev/null
+Index: hw/xfree86/common/xf86Configure.c
+================================================================================
+--- hw/xfree86/common/xf86Configure.c
++++ hw/xfree86/common/xf86Configure.c
+@@ -64,8 +64,8 @@
+ static char *DFLT_MOUSE_DEV = "/dev/sysmouse";
+ static char *DFLT_MOUSE_PROTO = "auto";
+ #elif defined(linux)
+-static char DFLT_MOUSE_DEV[] = "/dev/input/mice";
+-static char DFLT_MOUSE_PROTO[] = "auto";
++static char* DFLT_MOUSE_DEV = "/dev/input/mice";
++static char* DFLT_MOUSE_PROTO = "auto";
+ #else
+ static char *DFLT_MOUSE_DEV = "/dev/mouse";
+ static char *DFLT_MOUSE_PROTO = "auto";
--- /dev/null
+Index: hw/xfree86/common/xf86Configure.c
+================================================================================
+--- hw/xfree86/common/xf86Configure.c
++++ hw/xfree86/common/xf86Configure.c
+@@ -250,23 +250,35 @@
+
+ /* Crude mechanism to auto-detect mouse (os dependent) */
+ {
+- int fd;
++ int fd = -1;
+ #ifdef WSCONS_SUPPORT
+- fd = open("/dev/wsmouse", 0);
+- if (fd >= 0) {
+- DFLT_MOUSE_DEV = "/dev/wsmouse";
+- DFLT_MOUSE_PROTO = "wsmouse";
+- close(fd);
+- } else {
+- ErrorF("cannot open /dev/wsmouse\n");
++ if (fd == -1) {
++ fd = open("/dev/wsmouse", 0);
++ if (fd != -1) {
++ DFLT_MOUSE_DEV = "/dev/wsmouse";
++ DFLT_MOUSE_PROTO = "wsmouse";
++ close(fd);
++ } else {
++ ErrorF("cannot open /dev/wsmouse\n");
++ }
+ }
+ #endif
+
+ #ifndef __SCO__
+- fd = open(DFLT_MOUSE_DEV, 0);
+- if (fd != -1) {
+- foundMouse = TRUE;
+- close(fd);
++ if (fd == -1) {
++ fd = open(DFLT_MOUSE_DEV, 0);
++# ifdef linux
++ if (fd == -1) {
++ char *name = "/dev/input/mice";
++ fd = open(name, 0);
++ if (fd != -1)
++ DFLT_MOUSE_DEV = name;
++ }
++# endif
++ if (fd != -1) {
++ foundMouse = TRUE;
++ close(fd);
++ }
+ }
+ #else
+ foundMouse = TRUE;
--- /dev/null
+Index: hw/xfree86/common/xf86Globals.c
+================================================================================
+--- hw/xfree86/common/xf86Globals.c
++++ hw/xfree86/common/xf86Globals.c
+@@ -144,7 +144,7 @@
+ };
+ const char *xf86ConfigFile = NULL;
+ const char *xf86ConfigDir = NULL;
+-const char *xf86ModulePath = DEFAULT_MODULE_PATH;
++const char *xf86ModulePath = DEFAULT_MODULE_PATH "/updates," DEFAULT_MODULE_PATH;
+ MessageType xf86ModPathFrom = X_DEFAULT;
+ const char *xf86LogFile = DEFAULT_LOGPREFIX;
+ MessageType xf86LogFileFrom = X_DEFAULT;
--- /dev/null
+Index: os/connection.c
+================================================================================
+--- os/connection.c
++++ os/connection.c
+@@ -999,7 +999,7 @@
+ do {
+ r = Select (curclient + 1, &tmask, NULL, NULL, ¬ime);
+ } while (r < 0 && (errno == EINTR || errno == EAGAIN));
+- if (r < 0)
++ if (r < 0 && (errno == EBADF))
+ if (ConnectionTranslation[curclient] > 0)
+ CloseDownClient(clients[ConnectionTranslation[curclient]]);
+ mask &= ~((fd_mask)1 << curoff);
--- /dev/null
+Index: build-GucBkyZ/xorg-server-1.6.3.901/hw/xnest/GCOps.c
+================================================================================
+--- BUILD/xorg-server-1.7.99/hw/xnest/GCOps.c
++++ BUILD/xorg-server-1.7.99/hw/xnest/GCOps.c
+@@ -94,6 +94,13 @@
+ }
+ }
+
++static int
++xnestIgnoreErrorHandler (Display *display,
++ XErrorEvent *event)
++{
++ return False; /* return value is ignored */
++}
++
+ void
+ xnestGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
+ unsigned int format, unsigned long planeMask,
+@@ -101,9 +108,13 @@
+ {
+ XImage *ximage;
+ int length;
++ int (*old_handler)(Display*, XErrorEvent*);
+
++ /* we may get BadMatch error when xnest window is minimized */
++ old_handler = XSetErrorHandler (xnestIgnoreErrorHandler);
+ ximage = XGetImage(xnestDisplay, xnestDrawable(pDrawable),
+ x, y, w, h, planeMask, format);
++ XSetErrorHandler (old_handler);
+
+ if (ximage) {
+ length = ximage->bytes_per_line * ximage->height;
--- /dev/null
+Index: hw/xfree86/os-support/linux/lnx_acpi.c
+================================================================================
+--- hw/xfree86/os-support/linux/lnx_acpi.c
++++ hw/xfree86/os-support/linux/lnx_acpi.c
+@@ -32,8 +32,10 @@
+ #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
+ #define ACPI_VIDEO_HEAD_END (~0u)
+
++static PMClose doLnxACPIOpen(void);
+ static void lnxCloseACPI(void);
+ static pointer ACPIihPtr = NULL;
++static OsTimerPtr acpiTimer = NULL;
+ PMClose lnxACPIOpen(void);
+
+ /* in milliseconds */
+@@ -52,6 +54,22 @@
+
+ #define LINE_LENGTH 80
+
++static CARD32
++lnxACPICheckTimer(OsTimerPtr timer, CARD32 now, pointer arg)
++{
++#if DEBUG
++ ErrorF("ACPI: trying to reopen\n");
++#endif
++ if (doLnxACPIOpen()) {
++#if DEBUG
++ ErrorF("ACPI: successfully reopened\n");
++#endif
++ acpiTimer = NULL;
++ return 0;
++ }
++ return 5000;
++}
++
+ static int
+ lnxACPIGetEventFromOs(int fd, pmEvent *events, int num)
+ {
+@@ -127,15 +145,14 @@
+ }
+ }
+
+-PMClose
+-lnxACPIOpen(void)
++static PMClose
++doLnxACPIOpen(void)
+ {
+ int fd;
+ struct sockaddr_un addr;
+ int r = -1;
+ static int warned = 0;
+
+- DebugF("ACPI: OSPMOpen called\n");
+ if (ACPIihPtr || !xf86Info.pmFlag)
+ return NULL;
+
+@@ -164,6 +181,27 @@
+ return lnxCloseACPI;
+ }
+
++PMClose
++lnxACPIPoll(void)
++{
++ TimerSet(NULL, 0, 5000, lnxACPICheckTimer, NULL);
++ return lnxCloseACPI;
++}
++
++PMClose
++lnxACPIOpen(void)
++{
++ PMClose ret;
++#ifdef DEBUG
++ ErrorF("ACPI: OSPMOpen called\n");
++#endif
++ if (!(ret = doLnxACPIOpen()))
++ xf86MsgVerb(X_WARNING,3,"Open ACPI failed (%s) (%s)\n", ACPI_SOCKET,
++ strerror(errno));
++
++ return ret;
++}
++
+ static void
+ lnxCloseACPI(void)
+ {
+@@ -175,5 +213,11 @@
+ shutdown(fd, 2);
+ close(fd);
+ ACPIihPtr = NULL;
++ xf86PMGetEventFromOs = NULL;
++ xf86PMConfirmEventToOs = NULL;
++ if (acpiTimer) {
++ TimerCancel(acpiTimer);
++ acpiTimer = NULL;
++ }
+ }
+ }
+--- hw/xfree86/os-support/linux/lnx_apm.c
++++ hw/xfree86/os-support/linux/lnx_apm.c
+@@ -12,6 +12,7 @@
+
+ #ifdef HAVE_ACPI
+ extern PMClose lnxACPIOpen(void);
++extern PMClose lnxACPIPoll(void);
+ #endif
+
+ #ifdef HAVE_APM
+@@ -149,6 +150,14 @@
+ ret = lnxAPMOpen();
+ #endif
+
++#ifdef HAVE_ACPI
++ /* if we can neither open ACPI nor APM poll for an ACPI service to
++ become available */
++
++ if (!ret && !xf86acpiDisableFlag)
++ ret = lnxACPIPoll();
++#endif
++
+ return ret;
+ }
+
--- /dev/null
+From: Michel Dänzer <michel@daenzer.net>
+Subject: Pad size of system memory copy for 1x1 pixmaps
+References: bfo#32803 bnc#652523
+
+Temporary description by: Jeff Mahoney <jeffm@suse.com>
+ This patch fixes a crash that occured frequently with glibc malloc
+ perturbing enabled and was a bit more random otherwise. The issue
+ appears to be that the pExaPixmap for 1x1 pixmaps was allocating a single
+ byte. The patch uses paddedWidth, which I expect is 4 bytes instead.
+
+Acked-by: Jeff Mahoney <jeffm@suse.com>
+---
+
+ exa/exa_mixed.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/exa/exa_mixed.c b/exa/exa_mixed.c
+index ef20eb5..606f1e1 100644
+--- a/exa/exa_mixed.c
++++ b/exa/exa_mixed.c
+@@ -98,7 +98,7 @@ exaCreatePixmap_mixed(ScreenPtr pScreen, int w, int h, int depth,
+ pExaPixmap->use_gpu_copy = FALSE;
+
+ if (w == 1 && h == 1) {
+- pExaPixmap->sys_ptr = malloc((pPixmap->drawable.bitsPerPixel + 7) / 8);
++ pExaPixmap->sys_ptr = malloc(paddedWidth);
+
+ /* Set up damage tracking */
+ pExaPixmap->pDamage = DamageCreate(exaDamageReport_mixed, NULL,
--- /dev/null
+Index: hw/xfree86/os-support/bus/linuxPci.c
+================================================================================
+--- hw/xfree86/os-support/bus/linuxPci.c
++++ hw/xfree86/os-support/bus/linuxPci.c
+@@ -397,6 +397,7 @@
+ * legacy_mem interface is unavailable.
+ */
+ if ((Base > 1024*1024) || ((fd = linuxOpenLegacy(dev, "legacy_mem")) < 0))
++ fallback:
+ return linuxMapPci(ScreenNum, Flags, dev, Base, Size,
+ PCIIOC_MMAP_IS_MEM);
+ else
+@@ -405,6 +406,8 @@
+ if (fd >= 0)
+ close(fd);
+ if (addr == NULL || addr == MAP_FAILED) {
++ if (errno == ENXIO)
++ goto fallback;
+ perror("mmap failure");
+ FatalError("xf86MapDomainMem(): mmap() failure\n");
+ }
--- /dev/null
+Index: xorg-server-1.8.0/hw/xfree86/common/compiler.h
+===================================================================
+--- xorg-server-1.8.0.orig/hw/xfree86/common/compiler.h
++++ xorg-server-1.8.0/hw/xfree86/common/compiler.h
+@@ -409,12 +409,18 @@ extern _X_EXPORT unsigned int inl(unsign
+ # undef inb
+ # undef inw
+ # undef inl
+-extern _X_EXPORT void outb(unsigned long port, unsigned char val);
+-extern _X_EXPORT void outw(unsigned long port, unsigned short val);
+-extern _X_EXPORT void outl(unsigned long port, unsigned int val);
+-extern _X_EXPORT unsigned int inb(unsigned long port);
+-extern _X_EXPORT unsigned int inw(unsigned long port);
+-extern _X_EXPORT unsigned int inl(unsigned long port);
++#define outb(p,v) outb_ia64(p,v)
++#define outw(p,v) outw_ia64(p,v)
++#define outl(p,v) outl_ia64(p,v)
++#define inb(p) inb_ia64(p)
++#define inw(p) inw_ia64(p)
++#define inl(p) inl_ia64(p)
++extern _X_EXPORT void outb_ia64(unsigned long port, unsigned char val);
++extern _X_EXPORT void outw_ia64(unsigned long port, unsigned short val);
++extern _X_EXPORT void outl_ia64(unsigned long port, unsigned int val);
++extern _X_EXPORT unsigned int inb_ia64(unsigned long port);
++extern _X_EXPORT unsigned int inw_ia64(unsigned long port);
++extern _X_EXPORT unsigned int inl_ia64(unsigned long port);
+
+ # elif (defined(linux) || defined(__FreeBSD__)) && defined(__amd64__)
+
+Index: xorg-server-1.8.0/hw/xfree86/os-support/shared/ia64Pci.c
+===================================================================
+--- xorg-server-1.8.0.orig/hw/xfree86/os-support/shared/ia64Pci.c
++++ xorg-server-1.8.0/hw/xfree86/os-support/shared/ia64Pci.c
+@@ -60,7 +60,7 @@ static int ia64_port_to_fd(unsigned long
+ return (port >> 24) & 0xffffffff;
+ }
+
+-void outb(unsigned long port, unsigned char val)
++void outb_ia64(unsigned long port, unsigned char val)
+ {
+ int fd = ia64_port_to_fd(port);
+
+@@ -80,7 +80,7 @@ void outb(unsigned long port, unsigned c
+ return;
+ }
+
+-void outw(unsigned long port, unsigned short val)
++void outw_ia64(unsigned long port, unsigned short val)
+ {
+ int fd = ia64_port_to_fd(port);
+
+@@ -100,7 +100,7 @@ void outw(unsigned long port, unsigned s
+ return;
+ }
+
+-void outl(unsigned long port, unsigned int val)
++void outl_ia64(unsigned long port, unsigned int val)
+ {
+ int fd = ia64_port_to_fd(port);
+
+@@ -120,7 +120,7 @@ void outl(unsigned long port, unsigned i
+ return;
+ }
+
+-unsigned int inb(unsigned long port)
++unsigned int inb_ia64(unsigned long port)
+ {
+ int fd = ia64_port_to_fd(port);
+ unsigned char val;
+@@ -142,7 +142,7 @@ unsigned int inb(unsigned long port)
+ return val;
+ }
+
+-unsigned int inw(unsigned long port)
++unsigned int inw_ia64(unsigned long port)
+ {
+ int fd = ia64_port_to_fd(port);
+ unsigned short val;
+@@ -164,7 +164,7 @@ unsigned int inw(unsigned long port)
+ return val;
+ }
+
+-unsigned int inl(unsigned long port)
++unsigned int inl_ia64(unsigned long port)
+ {
+ int fd = ia64_port_to_fd(port);
+ unsigned int val;
--- /dev/null
+Index: include/miscstruct.h
+================================================================================
+--- include/miscstruct.h
++++ include/miscstruct.h
+@@ -50,7 +50,7 @@
+
+ #include "misc.h"
+ #include <X11/Xprotostr.h>
+-#include <pixman.h>
++#include <pixman-1/pixman.h>
+
+ typedef xPoint DDXPointRec;
+
--- /dev/null
+diff -ur fltk-1.3.2.org/FL/Fl_Image.H fltk-1.3.2/FL/Fl_Image.H
+--- fltk-1.3.2.org/FL/Fl_Image.H 2012-11-09 17:02:08.000000000 +0100
++++ fltk-1.3.2/FL/Fl_Image.H 2013-01-16 14:40:51.543230638 +0100
+@@ -26,6 +26,7 @@
+ #include <stdlib.h>
+
+ class Fl_Widget;
++class Fl_Pixmap;
+ struct Fl_Menu_Item;
+ struct Fl_Label;
+
+@@ -203,6 +204,7 @@
+ */
+ Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0) :
+ Fl_Image(W,H,D), array(bits), alloc_array(0), id_(0), mask_(0) {data((const char **)&array, 1); ld(LD);}
++ Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg=FL_GRAY);
+ virtual ~Fl_RGB_Image();
+ virtual Fl_Image *copy(int W, int H);
+ Fl_Image *copy() { return copy(w(), h()); }
+diff -ur fltk-1.3.2.org/src/fl_draw_pixmap.cxx fltk-1.3.2/src/fl_draw_pixmap.cxx
+--- fltk-1.3.2.org/src/fl_draw_pixmap.cxx 2012-04-22 05:09:31.000000000 +0200
++++ fltk-1.3.2/src/fl_draw_pixmap.cxx 2013-01-16 14:40:51.542230588 +0100
+@@ -58,99 +58,6 @@
+ return 1;
+ }
+
+-#ifdef U64
+-
+-// The callback from fl_draw_image to get a row of data passes this:
+-struct pixmap_data {
+- int w, h;
+- const uchar*const* data;
+- union {
+- U64 colors[256];
+- U64* byte1[256];
+- };
+-};
+-
+-// callback for 1 byte per pixel:
+-static void cb1(void*v, int x, int y, int w, uchar* buf) {
+- pixmap_data& d = *(pixmap_data*)v;
+- const uchar* p = d.data[y]+x;
+- U64* q = (U64*)buf;
+- for (int X=w; X>0; X-=2, p += 2) {
+- if (X>1) {
+-# if WORDS_BIGENDIAN
+- *q++ = (d.colors[p[0]]<<32) | d.colors[p[1]];
+-# else
+- *q++ = (d.colors[p[1]]<<32) | d.colors[p[0]];
+-# endif
+- } else {
+-# if WORDS_BIGENDIAN
+- *q++ = d.colors[p[0]]<<32;
+-# else
+- *q++ = d.colors[p[0]];
+-# endif
+- }
+- }
+-}
+-
+-// callback for 2 bytes per pixel:
+-static void cb2(void*v, int x, int y, int w, uchar* buf) {
+- pixmap_data& d = *(pixmap_data*)v;
+- const uchar* p = d.data[y]+2*x;
+- U64* q = (U64*)buf;
+- for (int X=w; X>0; X-=2) {
+- U64* colors = d.byte1[*p++];
+- int index = *p++;
+- if (X>1) {
+- U64* colors1 = d.byte1[*p++];
+- int index1 = *p++;
+-# if WORDS_BIGENDIAN
+- *q++ = (colors[index]<<32) | colors1[index1];
+-# else
+- *q++ = (colors1[index1]<<32) | colors[index];
+-# endif
+- } else {
+-# if WORDS_BIGENDIAN
+- *q++ = colors[index]<<32;
+-# else
+- *q++ = colors[index];
+-# endif
+- }
+- }
+-}
+-
+-#else // U32
+-
+-// The callback from fl_draw_image to get a row of data passes this:
+-struct pixmap_data {
+- int w, h;
+- const uchar*const* data;
+- union {
+- U32 colors[256];
+- U32* byte1[256];
+- };
+-};
+-
+-// callback for 1 byte per pixel:
+-static void cb1(void*v, int x, int y, int w, uchar* buf) {
+- pixmap_data& d = *(pixmap_data*)v;
+- const uchar* p = d.data[y]+x;
+- U32* q = (U32*)buf;
+- for (int X=w; X--;) *q++ = d.colors[*p++];
+-}
+-
+-// callback for 2 bytes per pixel:
+-static void cb2(void*v, int x, int y, int w, uchar* buf) {
+- pixmap_data& d = *(pixmap_data*)v;
+- const uchar* p = d.data[y]+2*x;
+- U32* q = (U32*)buf;
+- for (int X=w; X--;) {
+- U32* colors = d.byte1[*p++];
+- *q++ = colors[*p++];
+- }
+-}
+-
+-#endif // U64 else U32
+-
+ uchar **fl_mask_bitmap; // if non-zero, create bitmap and store pointer here
+
+ /**
+@@ -200,34 +107,33 @@
+ }
+ #endif
+
+-/**
+- Draw XPM image data, with the top-left corner at the given position.
+- \see fl_draw_pixmap(char* const* data, int x, int y, Fl_Color bg)
+- */
+-int fl_draw_pixmap(const char*const* cdata, int x, int y, Fl_Color bg) {
+- pixmap_data d;
+- if (!fl_measure_pixmap(cdata, d.w, d.h)) return 0;
++int fl_convert_pixmap(const char*const* cdata, uchar* out, Fl_Color bg) {
++ int w, h;
+ const uchar*const* data = (const uchar*const*)(cdata+1);
+ int transparent_index = -1;
++
++ if (!fl_measure_pixmap(cdata, w, h))
++ return 0;
++
++ if ((chars_per_pixel < 1) || (chars_per_pixel > 2))
++ return 0;
++
++ uchar colors[1<<(chars_per_pixel*8)][4];
++
+ #ifdef WIN32
+ uchar *transparent_c = (uchar *)0; // such that transparent_c[0,1,2] are the RGB of the transparent color
+ color_count = 0;
+ used_colors = (uchar *)malloc(abs(ncolors)*3*sizeof(uchar));
+ #endif
+
+- if (ncolors < 0) { // FLTK (non standard) compressed colormap
++ if (ncolors < 0) {
++ // FLTK (non standard) compressed colormap
+ ncolors = -ncolors;
+ const uchar *p = *data++;
+ // if first color is ' ' it is transparent (put it later to make
+ // it not be transparent):
+ if (*p == ' ') {
+- uchar* c = (uchar*)&d.colors[(int)' '];
+-#ifdef U64
+- *(U64*)c = 0;
+-# if WORDS_BIGENDIAN
+- c += 4;
+-# endif
+-#endif
++ uchar* c = colors[(int)' '];
+ transparent_index = ' ';
+ Fl::get_color(bg, c[0], c[1], c[2]); c[3] = 0;
+ #ifdef WIN32
+@@ -238,13 +144,7 @@
+ }
+ // read all the rest of the colors:
+ for (int i=0; i < ncolors; i++) {
+- uchar* c = (uchar*)&d.colors[*p++];
+-#ifdef U64
+- *(U64*)c = 0;
+-# if WORDS_BIGENDIAN
+- c += 4;
+-# endif
+-#endif
++ uchar* c = colors[*p++];
+ #ifdef WIN32
+ used_colors[3*color_count] = *p;
+ used_colors[3*color_count+1] = *(p+1);
+@@ -254,69 +154,44 @@
+ *c++ = *p++;
+ *c++ = *p++;
+ *c++ = *p++;
+-#ifdef __APPLE_QUARTZ__
+ *c = 255;
+-#else
+- *c = 0;
+-#endif
+ }
+- } else { // normal XPM colormap with names
+- if (chars_per_pixel>1) memset(d.byte1, 0, sizeof(d.byte1));
++ } else {
++ // normal XPM colormap with names
+ for (int i=0; i<ncolors; i++) {
+ const uchar *p = *data++;
+ // the first 1 or 2 characters are the color index:
+ int ind = *p++;
+ uchar* c;
+- if (chars_per_pixel>1) {
+-#ifdef U64
+- U64* colors = d.byte1[ind];
+- if (!colors) colors = d.byte1[ind] = new U64[256];
+-#else
+- U32* colors = d.byte1[ind];
+- if (!colors) colors = d.byte1[ind] = new U32[256];
+-#endif
+- c = (uchar*)&colors[*p];
+- ind = (ind<<8)|*p++;
+- } else {
+- c = (uchar *)&d.colors[ind];
+- }
++ if (chars_per_pixel>1)
++ ind = (ind<<8)|*p++;
++ c = colors[ind];
+ // look for "c word", or last word if none:
+ const uchar *previous_word = p;
+ for (;;) {
+- while (*p && isspace(*p)) p++;
+- uchar what = *p++;
+- while (*p && !isspace(*p)) p++;
+- while (*p && isspace(*p)) p++;
+- if (!*p) {p = previous_word; break;}
+- if (what == 'c') break;
+- previous_word = p;
+- while (*p && !isspace(*p)) p++;
++ while (*p && isspace(*p)) p++;
++ uchar what = *p++;
++ while (*p && !isspace(*p)) p++;
++ while (*p && isspace(*p)) p++;
++ if (!*p) {p = previous_word; break;}
++ if (what == 'c') break;
++ previous_word = p;
++ while (*p && !isspace(*p)) p++;
+ }
+-#ifdef U64
+- *(U64*)c = 0;
+-# if WORDS_BIGENDIAN
+- c += 4;
+-# endif
+-#endif
+-#ifdef __APPLE_QUARTZ__
+- c[3] = 255;
+-#endif
+ int parse = fl_parse_color((const char*)p, c[0], c[1], c[2]);
++ c[3] = 255;
+ if (parse) {
+ #ifdef WIN32
+- used_colors[3*color_count] = c[0];
+- used_colors[3*color_count+1] = c[1];
+- used_colors[3*color_count+2] = c[2];
+- color_count++;
++ used_colors[3*color_count] = c[0];
++ used_colors[3*color_count+1] = c[1];
++ used_colors[3*color_count+2] = c[2];
++ color_count++;
+ #endif
+- }
+- else {
++ } else {
+ // assume "None" or "#transparent" for any errors
+- // "bg" should be transparent...
+- Fl::get_color(bg, c[0], c[1], c[2]);
+-#ifdef __APPLE_QUARTZ__
++ // "bg" should be transparent...
++ Fl::get_color(bg, c[0], c[1], c[2]);
+ c[3] = 0;
+-#endif
+ transparent_index = ind;
+ #ifdef WIN32
+ transparent_c = c;
+@@ -324,7 +199,6 @@
+ }
+ }
+ }
+- d.data = data;
+ #ifdef WIN32
+ if (transparent_c) {
+ make_unused_color(transparent_c[0], transparent_c[1], transparent_c[2]);
+@@ -334,77 +208,76 @@
+ make_unused_color(r, g, b);
+ }
+ #endif
++
++ U32 *q = (U32*)out;
++ for (int Y = 0; Y < h; Y++) {
++ const uchar* p = data[Y];
++ if (chars_per_pixel <= 1) {
++ for (int X = 0; X < w; X++)
++ memcpy(q++, colors[*p++], 4);
++ } else {
++ for (int X = 0; X < w; X++) {
++ int ind = (*p++)<<8;
++ ind |= *p++;
++ memcpy(q++, colors[ind], 4);
++ }
++ }
++ }
+
++ return 1;
++}
++
++/**
++ Draw XPM image data, with the top-left corner at the given position.
++ \see fl_draw_pixmap(char* const* data, int x, int y, Fl_Color bg)
++ */
++int fl_draw_pixmap(const char*const* cdata, int x, int y, Fl_Color bg) {
++ int w, h;
++
++ if (!fl_measure_pixmap(cdata, w, h))
++ return 0;
++
++ uchar buffer[w*h*4];
++
++ if (!fl_convert_pixmap(cdata, buffer, bg))
++ return 0;
++
++ // FIXME: Hack until fl_draw_image() supports alpha properly
+ #ifdef __APPLE_QUARTZ__
+ if (Fl_Surface_Device::surface() == Fl_Display_Device::display_device()) {
+- U32 *array = new U32[d.w * d.h], *q = array;
+- for (int Y = 0; Y < d.h; Y++) {
+- const uchar* p = data[Y];
+- if (chars_per_pixel <= 1) {
+- for (int X = 0; X < d.w; X++) {
+- *q++ = d.colors[*p++];
+- }
+- } else {
+- for (int X = 0; X < d.w; X++) {
+- U32* colors = (U32*)d.byte1[*p++];
+- *q++ = colors[*p++];
+- }
+- }
+- }
+- Fl_RGB_Image* rgb = new Fl_RGB_Image((uchar*)array, d.w, d.h, 4);
++ Fl_RGB_Image* rgb = new Fl_RGB_Image(buffer, w, h, 4);
+ rgb->draw(x, y);
+ delete rgb;
+- delete[] array;
+- }
+- else {
++ } else {
+ #endif // __APPLE_QUARTZ__
+-
+ // build the mask bitmap used by Fl_Pixmap:
+- if (fl_mask_bitmap && transparent_index >= 0) {
+- int W = (d.w+7)/8;
+- uchar* bitmap = new uchar[W * d.h];
++ if (fl_mask_bitmap) {
++ int W = (w+7)/8;
++ uchar* bitmap = new uchar[W * h];
+ *fl_mask_bitmap = bitmap;
+- for (int Y = 0; Y < d.h; Y++) {
+- const uchar* p = data[Y];
+- if (chars_per_pixel <= 1) {
+- int dw = d.w;
+- for (int X = 0; X < W; X++) {
+- uchar b = (dw-->0 && *p++ != transparent_index);
+- if (dw-->0 && *p++ != transparent_index) b |= 2;
+- if (dw-->0 && *p++ != transparent_index) b |= 4;
+- if (dw-->0 && *p++ != transparent_index) b |= 8;
+- if (dw-->0 && *p++ != transparent_index) b |= 16;
+- if (dw-->0 && *p++ != transparent_index) b |= 32;
+- if (dw-->0 && *p++ != transparent_index) b |= 64;
+- if (dw-->0 && *p++ != transparent_index) b |= 128;
++ const uchar *p = &buffer[3];
++ uchar b = 0;
++ for (int Y = 0; Y < h; Y++) {
++ b = 0;
++ for (int X = 0, bit = 1; X < w; X++, p += 4) {
++ if (*p > 127) b |= bit;
++ bit <<= 1;
++ if (bit > 0x80 || X == w-1) {
+ *bitmap++ = b;
+- }
+- } else {
+- uchar b = 0, bit = 1;
+- for (int X = 0; X < d.w; X++) {
+- int ind = *p++;
+- ind = (ind<<8) | (*p++);
+- if (ind != transparent_index) b |= bit;
+-
+- if (bit < 128) bit <<= 1;
+- else {
+- *bitmap++ = b;
+- b = 0;
+- bit = 1;
++ bit = 1;
++ b = 0;
+ }
+ }
+-
+- if (bit > 1) *bitmap++ = b;
+ }
+- }
++
+ }
+
+- fl_draw_image(chars_per_pixel==1 ? cb1 : cb2, &d, x, y, d.w, d.h, 4);
++ fl_draw_image(buffer, x, y, w, h, 4);
++
+ #ifdef __APPLE_QUARTZ__
+ }
+ #endif
+
+- if (chars_per_pixel > 1) for (int i = 0; i < 256; i++) delete[] d.byte1[i];
+ return 1;
+ }
+
+diff -ur fltk-1.3.2.org/src/Fl_Image.cxx fltk-1.3.2/src/Fl_Image.cxx
+--- fltk-1.3.2.org/src/Fl_Image.cxx 2012-11-09 17:02:08.000000000 +0100
++++ fltk-1.3.2/src/Fl_Image.cxx 2013-01-16 14:41:38.404162795 +0100
+@@ -165,7 +165,22 @@
+ //
+ size_t Fl_RGB_Image::max_size_ = ~((size_t)0);
+
+-/** The destructor free all memory and server resources that are used by the image. */
++int fl_convert_pixmap(const char*const* cdata, uchar* out, Fl_Color bg);
++
++/** The constructor creates a new RGBA image from the specified Fl_Pixmap.
++
++ The RGBA image is built fully opaque except for the transparent area
++ of the pixmap that is assigned the \par bg color with full transparency */
++Fl_RGB_Image::Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg):
++ Fl_Image(pxm->w(), pxm->h(), 4), id_(0), mask_(0)
++{
++ array = new uchar[w() * h() * d()];
++ alloc_array = 1;
++ fl_convert_pixmap(pxm->data(), (uchar*)array, bg);
++ data((const char **)&array, 1);
++}
++
++/** The destructor frees all memory and server resources that are used by the image. */
+ Fl_RGB_Image::~Fl_RGB_Image() {
+ uncache();
+ if (alloc_array) delete[] (uchar *)array;
+diff -ur fltk-1.3.2.org/src/ps_image.cxx fltk-1.3.2/src/ps_image.cxx
+--- fltk-1.3.2.org/src/ps_image.cxx 2011-07-19 06:49:30.000000000 +0200
++++ fltk-1.3.2/src/ps_image.cxx 2013-01-16 14:40:51.541228080 +0100
+@@ -185,72 +185,38 @@
+
+ extern uchar **fl_mask_bitmap;
+
++struct callback_data {
++ const uchar *data;
++ int D, LD;
++};
+
+-void Fl_PostScript_Graphics_Driver::draw_image(const uchar *data, int ix, int iy, int iw, int ih, int D, int LD) {
+- double x = ix, y = iy, w = iw, h = ih;
+
+- if (D<3){ //mono
+- draw_image_mono(data, ix, iy, iw, ih, D, LD);
+- return;
+- }
++static void draw_image_cb(void *data, int x, int y, int w, uchar *buf) {
++ struct callback_data *cb_data;
++ const uchar *curdata;
+
++ cb_data = (struct callback_data*)data;
++ curdata = cb_data->data + x*cb_data->D + y*cb_data->LD;
+
+- int i,j, k;
++ memcpy(buf, curdata, w*cb_data->D);
++}
+
+- fprintf(output,"save\n");
+
+- const char * interpol;
+- if (lang_level_>1){
+- if (interpolate_)
+- interpol="true";
+- else
+- interpol="false";
+- if (mask && lang_level_>2)
+- fprintf(output, "%g %g %g %g %i %i %i %i %s CIM\n", x , y+h , w , -h , iw , ih, mx, my, interpol);
+- else
+- fprintf(output, "%g %g %g %g %i %i %s CII\n", x , y+h , w , -h , iw , ih, interpol);
+- } else
+- fprintf(output , "%g %g %g %g %i %i CI", x , y+h , w , -h , iw , ih);
++void Fl_PostScript_Graphics_Driver::draw_image(const uchar *data, int ix, int iy, int iw, int ih, int D, int LD) {
++ if (D<3){ //mono
++ draw_image_mono(data, ix, iy, iw, ih, D, LD);
++ return;
++ }
+
++ struct callback_data cb_data;
+
+ if (!LD) LD = iw*D;
+- uchar *curmask=mask;
+-
+- for (j=0; j<ih;j++){
+- if (mask){
+-
+- for (k=0;k<my/ih;k++){
+- for (i=0; i<((mx+7)/8);i++){
+- if (!(i%80)) fprintf(output, "\n");
+- fprintf(output, "%.2x",swap_byte(*curmask));
+- curmask++;
+- }
+- fprintf(output,"\n");
+- }
+- }
+- const uchar *curdata=data+j*LD;
+- for (i=0 ; i<iw ; i++) {
+- uchar r = curdata[0];
+- uchar g = curdata[1];
+- uchar b = curdata[2];
+- if (lang_level_<3 && D>3) { //can do mixing using bg_* colors)
+- unsigned int a2 = curdata[3]; //must be int
+- unsigned int a = 255-a2;
+- r = (a2 * r + bg_r * a)/255;
+- g = (a2 * g + bg_g * a)/255;
+- b = (a2 * b + bg_b * a)/255;
+- }
+- if (!(i%40)) fprintf(output, "\n");
+- fprintf(output, "%.2x%.2x%.2x", r, g, b);
+- curdata +=D;
+- }
+- fprintf(output,"\n");
+-
+- }
+-
+- fprintf(output," >\nrestore\n" );
+
++ cb_data.data = data;
++ cb_data.D = D;
++ cb_data.LD = LD;
+
++ draw_image(draw_image_cb, &cb_data, ix, iy, iw, ih, D);
+ }
+
+ void Fl_PostScript_Graphics_Driver::draw_image(Fl_Draw_Image_Cb call, void *data, int ix, int iy, int iw, int ih, int D) {
+@@ -325,6 +291,14 @@
+ uchar g = curdata[1];
+ uchar b = curdata[2];
+
++ if (lang_level_<3 && D>3) { //can do mixing using bg_* colors)
++ unsigned int a2 = curdata[3]; //must be int
++ unsigned int a = 255-a2;
++ r = (a2 * r + bg_r * a)/255;
++ g = (a2 * g + bg_g * a)/255;
++ b = (a2 * b + bg_b * a)/255;
++ }
++
+ if (!(i%40)) fputs("\n", output);
+ fprintf(output, "%.2x%.2x%.2x", r, g, b);
+
--- /dev/null
+Index: hw/xfree86/xaa/xaaImage.c
+================================================================================
+--- hw/xfree86/xaa/xaaImage.c
++++ hw/xfree86/xaa/xaaImage.c
+@@ -238,12 +238,16 @@
+ (*infoRec->SetupForImageWrite)(pScrn, rop, planemask, trans, bpp, depth);
+ (*infoRec->SubsequentImageWriteRect)(pScrn, x, y, w, h, skipleft);
+
++#if 0
+ if(beCareful) {
+ /* in cases with bad alignment we have to be careful not
+ to read beyond the end of the source */
+ if(((x * Bpp) + (dwords << 2)) > srcwidth) h--;
+ else beCareful = FALSE;
+ }
++#endif
++ if (beCareful)
++ h--;
+
+ if(dwords > infoRec->ImageWriteRange) {
+ while(h--) {
--- /dev/null
+Index: xorg-server-1.6.3.901/hw/xfree86/common/xf86RandR.c
+================================================================================
+--- xorg-server-1.7.99/hw/xfree86/common/xf86RandR.c
++++ xorg-server-1.7.99/hw/xfree86/common/xf86RandR.c
+@@ -247,6 +247,9 @@
+ Bool useVirtual = FALSE;
+ Rotation oldRotation = randrp->rotation;
+
++ if (!scrp->vtSema)
++ return FALSE;
++
+ miPointerGetPosition(inputInfo.pointer, &px, &py);
+ for (mode = scrp->modes; ; mode = mode->next)
+ {
--- /dev/null
+--- xorg-server-1.9.1/Xext/sync.c 2010-11-16 23:11:56.751124639 -0500
++++ xorg-server-1.9.1/Xext/sync.c 2010-11-16 23:13:16.327862535 -0500
+@@ -2264,8 +2264,44 @@
+ static void
+ IdleTimeQueryValue (pointer pCounter, CARD64 *pValue_return)
+ {
+- CARD32 idle = GetTimeInMillis() - lastDeviceEventTime.milliseconds;
++ static CARD32 previousLastDeviceEventTimeMilliseconds = 0;
++ CARD32 now = GetTimeInMillis();
++ CARD32 idle = now - lastDeviceEventTime.milliseconds;
++ CARD32 previousIdle = now - previousLastDeviceEventTimeMilliseconds;
++ SyncCounter *pIdleTimeCounter = (SyncCounter*)pCounter;
++
+ XSyncIntsToValue (pValue_return, idle, 0);
++
++ if (pCounter == NULL)
++ {
++ return;
++ }
++ if (previousLastDeviceEventTimeMilliseconds == 0)
++ {
++ /* initialize static var when this function is invoked the first time. */
++ previousLastDeviceEventTimeMilliseconds = lastDeviceEventTime.milliseconds;
++ return;
++ }
++
++ if (previousLastDeviceEventTimeMilliseconds == lastDeviceEventTime.milliseconds)
++ {
++ /* no new user event, no need to change idle counter. */
++ return;
++ }
++ previousLastDeviceEventTimeMilliseconds = lastDeviceEventTime.milliseconds;
++
++ /*
++ * Some user event occured; now update idle counter with previous
++ * event time, so idle counter has the most up-to-date value with
++ * respect to previous user event (we need old and new counter
++ * value to compute if a transition occured). Recompute bracket
++ * values if this is system counter.
++ */
++
++ XSyncIntsToValue (&pIdleTimeCounter->value, previousIdle, 0);
++ if (IsSystemCounter(pIdleTimeCounter)) {
++ SyncComputeBracketValues(pIdleTimeCounter);
++ }
+ }
+
+ static void
+@@ -2342,7 +2378,7 @@
+ if (!pIdleTimeValueLess && !pIdleTimeValueGreater)
+ return;
+
+- IdleTimeQueryValue (NULL, &idle);
++ IdleTimeQueryValue (IdleTimeCounter, &idle);
+
+ if ((pIdleTimeValueGreater &&
+ XSyncValueGreaterOrEqual (idle, *pIdleTimeValueGreater)) ||
--- /dev/null
+diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx
+index 40d08ae..7a571ec 100644
+--- a/vncviewer/DesktopWindow.cxx
++++ b/vncviewer/DesktopWindow.cxx
+@@ -186,6 +186,8 @@ DesktopWindow::~DesktopWindow()
+
+ OptionsDialog::removeCallback(handleOptions);
+
++ delete viewport;
++
+ // FLTK automatically deletes all child widgets, so we shouldn't touch
+ // them ourselves here
+ }
+diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx
+index e308a63..41733f9 100644
+--- a/vncviewer/Viewport.cxx
++++ b/vncviewer/Viewport.cxx
+@@ -112,6 +112,11 @@ Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_)
+
+ Viewport::~Viewport()
+ {
++ // Send release for every pressed key
++ for(DownMap::iterator iter = downKeySym.begin(); iter != downKeySym.end(); ++iter) {
++ cc->writer()->keyEvent(iter->second, false);
++ }
++
+ // Unregister all timeouts in case they get a change tro trigger
+ // again later when this object is already gone.
+ Fl::remove_timeout(handleUpdateTimeout, this);
+diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx
+index 37d63a6..5bb811d 100644
+--- a/vncviewer/vncviewer.cxx
++++ b/vncviewer/vncviewer.cxx
+@@ -83,6 +83,8 @@ char vncServerName[VNCSERVERNAMELEN] = { '\0' };
+ static bool exitMainloop = false;
+ static const char *exitError = NULL;
+
++static CConn *cc;
++
+ void exit_vncviewer(const char *error)
+ {
+ // Prioritise the first error we get as that is probably the most
+@@ -110,6 +112,16 @@ static void CleanupSignalHandler(int sig)
+ // CleanupSignalHandler allows C++ object cleanup to happen because it calls
+ // exit() rather than the default which is to abort.
+ vlog.info("CleanupSignalHandler called");
++ delete cc;
++ exit(1);
++}
++
++static int CleanupXIOErrorHandler(Display *dpy)
++{
++ // CleanupSignalHandler allows C++ object cleanup to happen because it calls
++ // exit() rather than the default which is to abort.
++ vlog.info("XErrorHandler called");
++ delete cc;
+ exit(1);
+ }
+
+@@ -384,6 +396,10 @@ int main(int argc, char** argv)
+
+ init_fltk();
+
++ fl_open_display();
++
++ XSetIOErrorHandler(CleanupXIOErrorHandler);
++
+ Configuration::enableViewerParams();
+
+ /* Load the default parameter settings */
+@@ -484,7 +500,7 @@ int main(int argc, char** argv)
+ #endif
+ }
+
+- CConn *cc = new CConn(vncServerName, sock);
++ cc = new CConn(vncServerName, sock);
+
+ while (!exitMainloop) {
+ int next_timer;
--- /dev/null
+diff -up a/vncviewer/CConn.cxx.newfbsize b/vncviewer/CConn.cxx
+--- a/vncviewer/CConn.cxx.newfbsize 2008-10-23 13:00:59.000000000 +0200
++++ b/vncviewer/CConn.cxx 2008-10-23 13:01:11.000000000 +0200
+@@ -327,6 +327,8 @@ void CConn::beginRect(const Rect& r, uns
+ if (encoding != encodingCopyRect) {
+ lastServerEncoding = encoding;
+ }
++ if (encoding == pseudoEncodingDesktopSize)
++ setDesktopSize( r.width(), r.height() );
+ }
+
+ void CConn::endRect(const Rect& r, int encoding)
--- /dev/null
+--- xorg-server-1.9.3/dix/dixfonts.c.orig 2010-10-31 03:47:09.000000000 +0100
++++ xorg-server-1.9.3/dix/dixfonts.c 2013-10-28 16:12:38.696658572 +0100
+@@ -1500,6 +1500,7 @@
+ GC *pGC;
+ unsigned char *data;
+ ITclosurePtr new_closure;
++ ITclosurePtr old_closure;
+
+ /* We're putting the client to sleep. We need to
+ save some state. Similar problem to that handled
+@@ -1512,6 +1513,7 @@
+ err = BadAlloc;
+ goto bail;
+ }
++ old_closure = c;
+ *new_closure = *c;
+ c = new_closure;
+
+@@ -1519,6 +1521,7 @@
+ if (!data)
+ {
+ free(c);
++ c = old_closure;
+ err = BadAlloc;
+ goto bail;
+ }
+@@ -1530,6 +1533,7 @@
+ {
+ free(c->data);
+ free(c);
++ c = old_closure;
+ err = BadAlloc;
+ goto bail;
+ }
+@@ -1543,6 +1547,7 @@
+ FreeScratchGC(pGC);
+ free(c->data);
+ free(c);
++ c = old_closure;
+ err = BadAlloc;
+ goto bail;
+ }
--- /dev/null
+Author: Michal Srb <msrb@suse.com>
+Subject: Fix use after free in ZRLEEncoder.
+Patch-Mainline: To be upstreamed
+References: bnc#840433
+
+There is use after free crash when client using zrle disconnects:
+ZRLEEncoder contains zos variable (rdr::ZlibOutStream) and mos variable (pointer to rdr::MemOutStream).
+mos is always allocated in constructor (it could be a copy of static sharedMos pointer if sharedMos != 0, but it is always 0).
+When ZRLEEncoder::writeRect is called, any of zrleEncode* functions sets mos as an underlying stream of zos.
+When ZRLEEncoder is destructed, mos is deleted (sharedMos is always 0), then zos is implicitly destructed, but zos accesses it's underlying stream in it's destructor!
+
+We need to destruct mos first and zos second when ZRLEEncoder is destructed.
+As sharedMos is never used, we can remove that, simplify ZRLEEncoder and turn zos into a member variable same as mos. They will be both implicitly destructed in reverse order of declaration.
+
+diff -ur tigervnc-1.3.0-orig/common/rfb/ZRLEEncoder.cxx tigervnc-1.3.0/common/rfb/ZRLEEncoder.cxx
+--- tigervnc-1.3.0-orig/common/rfb/ZRLEEncoder.cxx 2013-09-17 00:18:28.557911306 +0300
++++ tigervnc-1.3.0/common/rfb/ZRLEEncoder.cxx 2013-09-17 00:19:57.487915741 +0300
+@@ -26,7 +26,6 @@
+
+ using namespace rfb;
+
+-rdr::MemOutStream* ZRLEEncoder::sharedMos = 0;
+ int ZRLEEncoder::maxLen = 4097 * 1024; // enough for width 16384 32-bit pixels
+
+ IntParameter zlibLevel("ZlibLevel","Zlib compression level",-1);
+@@ -55,33 +54,27 @@
+ }
+
+ ZRLEEncoder::ZRLEEncoder(SMsgWriter* writer_)
+- : writer(writer_), zos(0,0,zlibLevel)
++ : writer(writer_), zos(0,0,zlibLevel), mos(129*1024)
+ {
+- if (sharedMos)
+- mos = sharedMos;
+- else
+- mos = new rdr::MemOutStream(129*1024);
+ }
+
+ ZRLEEncoder::~ZRLEEncoder()
+ {
+- if (!sharedMos)
+- delete mos;
+ }
+
+ bool ZRLEEncoder::writeRect(const Rect& r, TransImageGetter* ig, Rect* actual)
+ {
+ rdr::U8* imageBuf = writer->getImageBuf(64 * 64 * 4 + 4);
+- mos->clear();
++ mos.clear();
+ bool wroteAll = true;
+ *actual = r;
+
+ switch (writer->bpp()) {
+ case 8:
+- wroteAll = zrleEncode8(r, mos, &zos, imageBuf, maxLen, actual, ig);
++ wroteAll = zrleEncode8(r, &mos, &zos, imageBuf, maxLen, actual, ig);
+ break;
+ case 16:
+- wroteAll = zrleEncode16(r, mos, &zos, imageBuf, maxLen, actual, ig);
++ wroteAll = zrleEncode16(r, &mos, &zos, imageBuf, maxLen, actual, ig);
+ break;
+ case 32:
+ {
+@@ -94,16 +87,16 @@
+ if ((fitsInLS3Bytes && pf.isLittleEndian()) ||
+ (fitsInMS3Bytes && pf.isBigEndian()))
+ {
+- wroteAll = zrleEncode24A(r, mos, &zos, imageBuf, maxLen, actual, ig);
++ wroteAll = zrleEncode24A(r, &mos, &zos, imageBuf, maxLen, actual, ig);
+ }
+ else if ((fitsInLS3Bytes && pf.isBigEndian()) ||
+ (fitsInMS3Bytes && pf.isLittleEndian()))
+ {
+- wroteAll = zrleEncode24B(r, mos, &zos, imageBuf, maxLen, actual, ig);
++ wroteAll = zrleEncode24B(r, &mos, &zos, imageBuf, maxLen, actual, ig);
+ }
+ else
+ {
+- wroteAll = zrleEncode32(r, mos, &zos, imageBuf, maxLen, actual, ig);
++ wroteAll = zrleEncode32(r, &mos, &zos, imageBuf, maxLen, actual, ig);
+ }
+ break;
+ }
+@@ -111,8 +104,8 @@
+
+ writer->startRect(*actual, encodingZRLE);
+ rdr::OutStream* os = writer->getOutStream();
+- os->writeU32(mos->length());
+- os->writeBytes(mos->data(), mos->length());
++ os->writeU32(mos.length());
++ os->writeBytes(mos.data(), mos.length());
+ writer->endRect();
+ return wroteAll;
+ }
+diff -ur tigervnc-1.3.0-orig/common/rfb/ZRLEEncoder.h tigervnc-1.3.0/common/rfb/ZRLEEncoder.h
+--- tigervnc-1.3.0-orig/common/rfb/ZRLEEncoder.h 2013-09-17 00:18:28.558911306 +0300
++++ tigervnc-1.3.0/common/rfb/ZRLEEncoder.h 2013-09-17 00:20:34.372917581 +0300
+@@ -38,16 +38,11 @@
+ // width, in this example about 128 bytes).
+ static void setMaxLen(int m) { maxLen = m; }
+
+- // setSharedMos() sets a MemOutStream to be shared amongst all
+- // ZRLEEncoders. Should be called before any ZRLEEncoders are created.
+- static void setSharedMos(rdr::MemOutStream* mos_) { sharedMos = mos_; }
+-
+ private:
+ ZRLEEncoder(SMsgWriter* writer);
+ SMsgWriter* writer;
++ rdr::MemOutStream mos;
+ rdr::ZlibOutStream zos;
+- rdr::MemOutStream* mos;
+- static rdr::MemOutStream* sharedMos;
+ static int maxLen;
+ };
+ }
--- /dev/null
+--- xorg-server-1.9.3/hw/vfb/InitOutput.c 2010-06-11 08:10:22.000000000 +0200
++++ xorg-server-1.9.3.new/hw/vfb/InitOutput.c 2013-07-03 15:31:50.119407430 +0200
+@@ -66,6 +66,7 @@
+ #endif /* HAS_SHM */
+ #include "dix.h"
+ #include "miline.h"
++#include "randrstr.h"
+
+ #define VFB_DEFAULT_WIDTH 1280
+ #define VFB_DEFAULT_HEIGHT 1024
+@@ -804,6 +805,165 @@
+ }
+
+ static Bool
++vfbRROutputValidateMode(ScreenPtr pScreen,
++ RROutputPtr output,
++ RRModePtr mode)
++{
++ rrScrPriv(pScreen);
++
++ if (pScrPriv->minWidth <= mode->mode.width &&
++ pScrPriv->maxWidth >= mode->mode.width &&
++ pScrPriv->minHeight <= mode->mode.height &&
++ pScrPriv->maxHeight >= mode->mode.height)
++ return TRUE;
++ else
++ return FALSE;
++}
++
++static Bool
++vfbRRScreenSetSize(ScreenPtr pScreen,
++ CARD16 width,
++ CARD16 height,
++ CARD32 mmWidth,
++ CARD32 mmHeight)
++{
++ WindowPtr root = pScreen->root;
++ WindowPtr layer;
++ WindowPtr child;
++ BoxRec box;
++
++ pScreen->width = width;
++ pScreen->height = height;
++ pScreen->mmWidth = mmWidth;
++ pScreen->mmHeight = mmHeight;
++
++ // Resize the root window & adjust its clipping
++ box.x1 = 0;
++ box.y1 = 0;
++ box.x2 = pScreen->width;
++ box.y2 = pScreen->height;
++ REGION_INIT(pScreen, &root->winSize, &box, 1);
++ REGION_INIT(pScreen, &root->borderSize, &box, 1);
++ REGION_RESET(pScreen, &root->borderClip, &box);
++ root->drawable.width = pScreen->width;
++ root->drawable.height = pScreen->height;
++ REGION_BREAK (pScreen, &root->clipList);
++
++ // Update the clipping regions of all windows
++ for (child = root->firstChild; child; child = child->nextSib)
++ (*pScreen->MarkOverlappedWindows)(child, child, &layer);
++
++ if (root->firstChild)
++ {
++ (*pScreen->MarkOverlappedWindows)(root->firstChild,
++ root->firstChild,
++ (WindowPtr *)NULL);
++ }
++ else
++ {
++ (*pScreen->MarkWindow) (root);
++ }
++
++ (*pScreen->ValidateTree)(root, NullWindow, VTOther);
++ (*pScreen->HandleExposures)(root);
++
++ // Reposition top-level windows to fit new root size
++ // XXX I assume this is what it does, but I'm not sure
++ ResizeChildrenWinSize (root, 0, 0, 0, 0);
++
++
++ // Check the pointer position
++ WindowsRestructured ();
++
++ RRScreenSizeNotify (pScreen);
++ RRTellChanged(pScreen);
++
++ // Flush resulting events, etc to clients
++ FlushAllOutput ();
++
++ return TRUE;
++}
++
++static Bool
++vfbRRCrtcSet(ScreenPtr pScreen,
++ RRCrtcPtr crtc,
++ RRModePtr mode,
++ int x,
++ int y,
++ Rotation rotation,
++ int numOutput,
++ RROutputPtr *outputs)
++{
++ return RRCrtcNotify(crtc, mode, x, y, rotation, NULL, numOutput, outputs);
++}
++
++static Bool
++vfbRRGetInfo(ScreenPtr pScreen, Rotation *rotations)
++{
++ return TRUE;
++}
++
++static Bool
++vfbRandRInit(ScreenPtr pScreen)
++{
++ rrScrPrivPtr pScrPriv;
++#if RANDR_12_INTERFACE
++ RRModePtr mode;
++ RRCrtcPtr crtc;
++ RROutputPtr output;
++ xRRModeInfo modeInfo;
++ char name[64];
++#endif
++
++ if (!RRScreenInit (pScreen))
++ return FALSE;
++ pScrPriv = rrGetScrPriv(pScreen);
++ pScrPriv->rrGetInfo = vfbRRGetInfo;
++#if RANDR_12_INTERFACE
++ pScrPriv->rrCrtcSet = vfbRRCrtcSet;
++ pScrPriv->rrScreenSetSize = vfbRRScreenSetSize;
++ pScrPriv->rrOutputSetProperty = NULL;
++#if RANDR_13_INTERFACE
++ pScrPriv->rrOutputGetProperty = NULL;
++#endif
++ pScrPriv->rrOutputValidateMode = vfbRROutputValidateMode;
++ pScrPriv->rrModeDestroy = NULL;
++
++ RRScreenSetSizeRange (pScreen,
++ 1, 1,
++ pScreen->width, pScreen->height);
++
++ sprintf (name, "%dx%d", pScreen->width, pScreen->height);
++ memset (&modeInfo, '\0', sizeof (modeInfo));
++ modeInfo.width = pScreen->width;
++ modeInfo.height = pScreen->height;
++ modeInfo.nameLength = strlen (name);
++
++ mode = RRModeGet (&modeInfo, name);
++ if (!mode)
++ return FALSE;
++
++ crtc = RRCrtcCreate (pScreen, NULL);
++ if (!crtc)
++ return FALSE;
++
++ output = RROutputCreate (pScreen, "screen", 6, NULL);
++ if (!output)
++ return FALSE;
++ if (!RROutputSetClones (output, NULL, 0))
++ return FALSE;
++ if (!RROutputSetModes (output, &mode, 1, 0))
++ return FALSE;
++ if (!RROutputSetCrtcs (output, &crtc, 1))
++ return FALSE;
++ if (!RROutputSetConnection (output, RR_Connected))
++ return FALSE;
++ RRCrtcNotify (crtc, mode, 0, 0, RR_Rotate_0, NULL, 1, &output);
++#endif
++ return TRUE;
++}
++
++static Bool
+ vfbScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
+ {
+ vfbScreenInfoPtr pvfb = &vfbScreens[index];
+@@ -875,6 +1035,9 @@
+
+ if (!ret) return FALSE;
+
++ if (!vfbRandRInit(pScreen))
++ return FALSE;
++
+ miInitializeBackingStore(pScreen);
+
+ /*
--- /dev/null
+From ee0e658bb6cb0d1290072090f1de90ff44145365 Mon Sep 17 00:00:00 2001
+From: Dan Nicholson <dbn.lists@gmail.com>
+Date: Thu, 16 Dec 2010 06:01:06 -0800
+Subject: [PATCH] xfree86: Use last Screen section found to prefer xorg.conf
+
+Allowing multiple .conf files with xorg.conf.d works well for InputClass
+where any section in xorg.conf would override settings from previous
+.conf files typically installed by the distro. This does not work well
+with Screen sections where the first section found has been used when
+the Layout doesn't specify a Screen. Instead, use the last Screen
+section found to give preference to xorg.conf and match the InputScreen
+semantics.
+
+Signed-off-by: Dan Nicholson <dbn.lists@gmail.com>
+---
+ hw/xfree86/common/xf86Config.c | 10 ++++++++--
+ 1 files changed, 8 insertions(+), 2 deletions(-)
+
+diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
+index 5800700..b2fc8e3 100644
+--- a/hw/xfree86/common/xf86Config.c
++++ b/hw/xfree86/common/xf86Config.c
+@@ -1678,7 +1678,7 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
+ }
+
+ /*
+- * No layout section, so find the first Screen section and set that up as
++ * No layout section, so find the last Screen section and set that up as
+ * the only active screen.
+ */
+ static Bool
+@@ -1697,7 +1697,7 @@ configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen,
+ /*
+ * which screen section is the active one?
+ *
+- * If there is a -screen option, use that one, otherwise use the first
++ * If there is a -screen option, use that one, otherwise use the last
+ * one.
+ */
+
+@@ -1710,6 +1710,12 @@ configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen,
+ }
+ conf_screen = s;
+ from = X_CMDLINE;
++ } else if (conf_screen) {
++ /* Use the last Screen in the list */
++ s = conf_screen;
++ while (s->list.next)
++ s = s->list.next;
++ conf_screen = s;
+ }
+
+ /* We have exactly one screen */
+--
+1.7.2.3
+
--- /dev/null
+Index: hw/xfree86/common/xf86VidMode.c
+================================================================================
+--- hw/xfree86/common/xf86VidMode.c
++++ hw/xfree86/common/xf86VidMode.c
+@@ -220,6 +220,8 @@
+
+ pScrn = xf86Screens[scrnIndex];
+ pVidMode = VMPTR(pScrn->pScreen);
++ if (!pScrn->modes)
++ return FALSE;
+ pVidMode->First = pScrn->modes;
+ pVidMode->Next = pVidMode->First->next;
+
--- /dev/null
+## Name: VNC mini-HTTP server
+## Description: Opens the VNC HTTP ports so that browsers can connect.
+
+TCP="5800:5899"
--- /dev/null
+## Name: VNC
+## Description: Opens VNC server ports so that viewers can connect.
+
+TCP="5900:5999"
--- /dev/null
+#############################################################################
+#
+# OpenSLP registration file
+#
+# register VNC remote logins via kdm
+# You need also to allow remote logins
+#
+#############################################################################
+
+# Register VNC service for krdc (KDE VNC client in kdenetwork)
+service:remotedesktop.kde:vnc://$HOSTNAME:5901,en,65535
+tcp-port=5901
+description=VNC remote login [1024x768]
+
+# Register VNC service for krdc (KDE VNC client in kdenetwork)
+service:remotedesktop.kde:vnc://$HOSTNAME:5902,en,65535
+tcp-port=5902
+description=VNC remote login [1280x1024]
+
+# Register VNC service for krdc (KDE VNC client in kdenetwork)
+service:remotedesktop.kde:vnc://$HOSTNAME:5903,en,65535
+tcp-port=5903
+description=VNC remote login [1600x1200]
+
+# Register VNC service for Java clients
+# Can be used with every Web browser with enabled Java
+service:remotedesktop.java:http://$HOSTNAME:5801,en,65535
+tcp-port=5801
+description=VNC remote login [1024x768]
+
+# Register VNC service for Java clients
+# Can be used with every Web browser with enabled Java
+service:remotedesktop.java:http://$HOSTNAME:5802,en,65535
+tcp-port=5802
+description=VNC remote login [1280x1024]
+
+# Register VNC service for Java clients
+# Can be used with every Web browser with enabled Java
+service:remotedesktop.java:http://$HOSTNAME:5803,en,65535
+tcp-port=5803
+description=VNC remote login [1600x1200]
+
--- /dev/null
+# default: off
+# description: This serves out a VNC connection which starts at a KDM login \
+# prompt. This VNC connection has a resolution of 1024x768, 16bit depth.
+service vnc1
+{
+ type = UNLISTED
+ port = 5901
+ socket_type = stream
+ protocol = tcp
+ wait = no
+ user = nobody
+ server = /usr/bin/Xvnc
+ server_args = -noreset -inetd -once -query localhost -geometry 1024x768 -depth 16 -securitytypes none
+ disable = yes
+}
+# default: off
+# description: This serves out a VNC connection which starts at a KDM login \
+# prompt. This VNC connection has a resolution of 1280x1024, 16bit depth.
+service vnc2
+{
+ type = UNLISTED
+ port = 5902
+ socket_type = stream
+ protocol = tcp
+ wait = no
+ user = nobody
+ server = /usr/bin/Xvnc
+ server_args = -noreset -inetd -once -query localhost -geometry 1280x1024 -depth 16 -securitytypes none
+ disable = yes
+}
+# default: off
+# description: This serves out a VNC connection which starts at a KDM login \
+# prompt. This VNC connection has a resolution of 1600x1200, 16bit depth.
+service vnc3
+{
+ type = UNLISTED
+ port = 5903
+ socket_type = stream
+ protocol = tcp
+ wait = no
+ user = nobody
+ server = /usr/bin/Xvnc
+ server_args = -noreset -inetd -once -query localhost -geometry 1600x1200 -depth 16 -securitytypes none
+ disable = yes
+}
+# default: off
+# description: This serves out the vncviewer Java applet for the VNC \
+# server running on port 5901, (vnc port 1).
+service vnchttpd1
+{
+ type = UNLISTED
+ port = 5801
+ socket_type = stream
+ protocol = tcp
+ wait = no
+ user = nobody
+ server = /usr/bin/vnc_inetd_httpd
+ server_args = 1024 768 5901
+ disable = yes
+}
+# default: off
+# description: This serves out the vncviewer Java applet for the VNC \
+# server running on port 5902, (vnc port 2).
+service vnchttpd2
+{
+ type = UNLISTED
+ port = 5802
+ socket_type = stream
+ protocol = tcp
+ wait = no
+ user = nobody
+ server = /usr/bin/vnc_inetd_httpd
+ server_args = 1280 1024 5902
+ disable = yes
+}
+# default: off
+# description: This serves out the vncviewer Java applet for the VNC \
+# server running on port 5902, (vnc port 3).
+service vnchttpd3
+{
+ type = UNLISTED
+ port = 5803
+ socket_type = stream
+ protocol = tcp
+ wait = no
+ user = nobody
+ server = /usr/bin/vnc_inetd_httpd
+ server_args = 1600 1200 5903
+ disable = yes
+}
--- /dev/null
+#!/bin/bash
+read request url httptype || exit 0
+url="${url/\r/}"
+httptype="${httptype/\r/}"
+
+width=$1
+height=$2
+port=$3
+
+if [ "x$httptype" != "x" ]; then
+ line="x"
+ while [ -n "$line" ]; do
+ read line || exit 0
+ line="${line/\r/}"
+ done
+fi
+case "$url" in
+/)
+ # We need the size of the display for the current applet.
+ # The VNC menubar is 20 pixels high ...
+ height=$((height+20))
+ ctype="text/html"
+ content="
+<HTML><HEAD><TITLE>Remote Desktop</TITLE></HEAD>
+<BODY>
+<APPLET CODE=VncViewer.class ARCHIVE=VncViewer.jar WIDTH=$width HEIGHT=$height>
+ <param name=PORT value=$port>
+</APPLET>
+</BODY></HTML>"
+ ;;
+*.jar|*.class)
+ # Use basename to make sure we have just a filename, not ../../...
+ url=${url/.*\/}
+ ctype="application/octet-stream"
+ cfile="/usr/share/vnc/classes/$url"
+ content="FILE"
+ ;;
+esac
+
+if [ "x$httptype" != "x" ]; then
+ echo "HTTP/1.0 200 OK"
+ echo "Content-Type: $ctype"
+ if [ "$content" == "FILE" ]; then
+ clen=`wc -c "$cfile"`
+ else
+ clen=`echo "$content"|wc -c`
+ fi
+ echo "Content-Length: $clen"
+ echo "Connection: close"
+ echo
+fi
+
+if [ "$request" == "GET" ]; then
+ if [ "$content" == "FILE" ]; then
+ cat "$cfile"
+ else
+ echo "$content"
+ fi
+fi
+exit 0
--- /dev/null
+Index: hw/kdrive/Makefile.am
+================================================================================
+--- hw/kdrive/Makefile.am
++++ hw/kdrive/Makefile.am
+@@ -1,5 +1,5 @@
+ if BUILD_KDRIVEFBDEVLIB
+-FBDEV_SUBDIRS = fbdev
++FBDEV_SUBDIRS =
+ endif
+
+ if XFAKESERVER
+@@ -16,8 +16,7 @@
+
+ SERVER_SUBDIRS = \
+ $(FBDEV_SUBDIRS) \
+- $(XEPHYR_SUBDIRS) \
+- $(XFAKE_SUBDIRS)
++ $(XEPHYR_SUBDIRS)
+
+ SUBDIRS = \
+ src \
--- /dev/null
+Index: xorg-server-1.6.3.901/hw/xfree86/common/xf86pciBus.c
+===============================================================================
+--- xorg-server-1.7.99/hw/xfree86/common/xf86pciBus.c
++++ xorg-server-1.7.99/hw/xfree86/common/xf86pciBus.c
+@@ -186,12 +186,14 @@
+ case 0x3d3d: driverList[0] = "glint"; break;
+ case 0x105d: driverList[0] = "i128"; break;
+ case 0x8086:
+- if ((dev->device_id == 0x00d1) || (dev->device_id == 0x7800)) {
+- driverList[0] = "i740";
+- } else if (dev->device_id == 0x8108) {
+- break; /* "hooray" for poulsbo */
+- } else {
+- driverList[0] = "intel";
++ switch (dev->device_id)
++ {
++ case 0x00d1: case 0x7800:
++ driverList[0] = "i740"; break;
++ case 0x8109: case 0x8108: case 0x4102:
++ driverList[0] = "psb"; driverList[1] = "psb_drv"; break;
++ default:
++ driverList[0] = "intel"; break;
+ }
+ break;
+ case 0x102b: driverList[0] = "mga"; break;
--- /dev/null
+--- man/Makefile.am.orig 2010-09-14 01:25:46.000000000 +0200
++++ man/Makefile.am 2010-11-12 13:28:31.000000000 +0100
+@@ -23,12 +23,8 @@
+ miscmandir = $(MISC_MAN_DIR)
+
+ miscman_PRE = \
+- Consortium.man \
+ Xsecurity.man \
+- Standards.man \
+- X.man \
+- XOrgFoundation.man \
+- XProjectTeam.man
++ X.man
+
+ miscman_DATA = $(miscman_PRE:man=@MISC_MAN_SUFFIX@)
+
+--- Makefile.am.orig 2010-11-12 13:45:19.000000000 +0100
++++ Makefile.am 2010-11-12 13:45:32.000000000 +0100
+@@ -20,9 +20,7 @@
+ #
+ # Process this file with autoconf to create configure.
+
+-SUBDIRS = general man specs
+-
+-dist_doc_DATA = MAINTAINERS
++SUBDIRS = man
+
+ MAINTAINERCLEANFILES = ChangeLog INSTALL
+ EXTRA_DIST = \
--- /dev/null
+--- config/Makefile.am.orig 2010-06-11 04:14:57.000000000 +0200
++++ config/Makefile.am 2010-08-23 15:47:19.000000000 +0200
+@@ -9,7 +9,7 @@
+ libconfig_la_SOURCES += udev.c
+ libconfig_la_LIBADD = $(UDEV_LIBS)
+
+-xorgconfddir = $(datadir)/X11/$(XF86CONFIGDIR)
++xorgconfddir = $(sysconfdir)/X11/$(XF86CONFIGDIR)
+ xorgconfd_DATA = 10-evdev.conf
+
+ else
--- /dev/null
+Index: xorg-server-1.6.3/hw/xfree86/os-support/linux/lnx_init.c
+===================================================================
+Index: xorg-server-1.6.3/hw/xfree86/os-support/linux/lnx_video.c
+===================================================================
+--- xorg-server-1.6.3.orig/hw/xfree86/os-support/linux/lnx_video.c
++++ xorg-server-1.6.3/hw/xfree86/os-support/linux/lnx_video.c
+@@ -51,6 +51,7 @@
+ #define MAP_FAILED ((void *)-1)
+ #endif
+
++extern Bool NoHwAccess;
+ static Bool ExtendedEnabled = FALSE;
+
+ #ifdef __ia64__
+@@ -509,6 +510,9 @@ xf86EnableIO(void)
+ int fd;
+ unsigned int ioBase_phys;
+ #endif
++ /* Fake it... */
++ if (NoHwAccess)
++ return TRUE;
+
+ if (ExtendedEnabled)
+ return TRUE;
+--- xorg-server-1.9.0/hw/xfree86/os-support/linux/lnx_init.c.orig 2010-06-10 16:07:55.000000000 +0200
++++ xorg-server-1.9.0/hw/xfree86/os-support/linux/lnx_init.c 2010-08-23 15:38:45.000000000 +0200
+@@ -42,6 +42,7 @@ static Bool KeepTty = FALSE;
+ static int VTnum = -1;
+ static Bool VTSwitch = TRUE;
+ static Bool ShareVTs = FALSE;
++Bool NoHwAccess = FALSE;
+ static int activeVT = -1;
+
+ static int vtPermSave[4];
+@@ -377,6 +378,11 @@ xf86ProcessArgument(int argc, char *argv
+ ShareVTs = TRUE;
+ return 1;
+ }
++ if (!strcmp(argv[i], "-nohwaccess"))
++ {
++ NoHwAccess = TRUE;
++ return(1);
++ }
+ if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
+ {
+ if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
+@@ -398,4 +404,5 @@ xf86UseMsg(void)
+ ErrorF("don't detach controlling tty (for debugging only)\n");
+ ErrorF("-novtswitch don't immediately switch to new VT\n");
+ ErrorF("-sharevts share VTs with another X server\n");
++ ErrorF("-nohwaccess don't access hardware ports directly\n");
+ }
--- /dev/null
+--- hw/xfree86/parser/InputClass.c.orig 2010-08-13 07:53:48.000000000 +0200
++++ hw/xfree86/parser/InputClass.c 2010-08-23 15:55:16.000000000 +0200
+@@ -65,6 +65,47 @@ xf86ConfigSymTabRec InputClassTab[] =
+
+ #define TOKEN_SEP "|"
+
++/*
++ * Tokenize a string into a NULL terminated array of strings. Always returns
++ * an allocated array unless an error occurs.
++ */
++char**
++m_xstrtokenize(const char *str, const char *separators)
++{
++ char **list, **nlist;
++ char *tok, *tmp;
++ unsigned num = 0, n;
++
++ if (!str)
++ return NULL;
++ list = calloc(1, sizeof(*list));
++ if (!list)
++ return NULL;
++ tmp = strdup(str);
++ if (!tmp)
++ goto error;
++ for (tok = strtok(tmp, separators); tok; tok = strtok(NULL, separators)) {
++ nlist = realloc(list, (num + 2) * sizeof(*list));
++ if (!nlist)
++ goto error;
++ list = nlist;
++ list[num] = strdup(tok);
++ if (!list[num])
++ goto error;
++ list[++num] = NULL;
++ }
++ free(tmp);
++ return list;
++
++error:
++ free(tmp);
++ for (n = 0; n < num; n++)
++ free(list[n]);
++ free(list);
++ return NULL;
++}
++
++
+ static void
+ add_group_entry(struct list *head, char **values)
+ {
+@@ -125,49 +166,49 @@ xf86parseInputClassSection(void)
+ if (xf86getSubToken(&(ptr->comment)) != STRING)
+ Error(QUOTE_MSG, "MatchProduct");
+ add_group_entry(&ptr->match_product,
+- xstrtokenize(val.str, TOKEN_SEP));
++ m_xstrtokenize(val.str, TOKEN_SEP));
+ break;
+ case MATCH_VENDOR:
+ if (xf86getSubToken(&(ptr->comment)) != STRING)
+ Error(QUOTE_MSG, "MatchVendor");
+ add_group_entry(&ptr->match_vendor,
+- xstrtokenize(val.str, TOKEN_SEP));
++ m_xstrtokenize(val.str, TOKEN_SEP));
+ break;
+ case MATCH_DEVICE_PATH:
+ if (xf86getSubToken(&(ptr->comment)) != STRING)
+ Error(QUOTE_MSG, "MatchDevicePath");
+ add_group_entry(&ptr->match_device,
+- xstrtokenize(val.str, TOKEN_SEP));
++ m_xstrtokenize(val.str, TOKEN_SEP));
+ break;
+ case MATCH_OS:
+ if (xf86getSubToken(&(ptr->comment)) != STRING)
+ Error(QUOTE_MSG, "MatchOS");
+ add_group_entry(&ptr->match_os,
+- xstrtokenize(val.str, TOKEN_SEP));
++ m_xstrtokenize(val.str, TOKEN_SEP));
+ break;
+ case MATCH_PNPID:
+ if (xf86getSubToken(&(ptr->comment)) != STRING)
+ Error(QUOTE_MSG, "MatchPnPID");
+ add_group_entry(&ptr->match_pnpid,
+- xstrtokenize(val.str, TOKEN_SEP));
++ m_xstrtokenize(val.str, TOKEN_SEP));
+ break;
+ case MATCH_USBID:
+ if (xf86getSubToken(&(ptr->comment)) != STRING)
+ Error(QUOTE_MSG, "MatchUSBID");
+ add_group_entry(&ptr->match_usbid,
+- xstrtokenize(val.str, TOKEN_SEP));
++ m_xstrtokenize(val.str, TOKEN_SEP));
+ break;
+ case MATCH_DRIVER:
+ if (xf86getSubToken(&(ptr->comment)) != STRING)
+ Error(QUOTE_MSG, "MatchDriver");
+ add_group_entry(&ptr->match_driver,
+- xstrtokenize(val.str, TOKEN_SEP));
++ m_xstrtokenize(val.str, TOKEN_SEP));
+ break;
+ case MATCH_TAG:
+ if (xf86getSubToken(&(ptr->comment)) != STRING)
+ Error(QUOTE_MSG, "MatchTag");
+ add_group_entry(&ptr->match_tag,
+- xstrtokenize(val.str, TOKEN_SEP));
++ m_xstrtokenize(val.str, TOKEN_SEP));
+ break;
+ case MATCH_IS_KEYBOARD:
+ if (xf86getSubToken(&(ptr->comment)) != STRING)
+--- hw/xfree86/parser/Layout.c
++++ hw/xfree86/parser/Layout.c
+@@ -449,7 +449,10 @@
+ /* add all AutoServerLayout devices to the server layout */
+ while (input)
+ {
+- if (xf86CheckBoolOption(input->inp_option_lst, "AutoServerLayout", FALSE))
++ Bool asl_value = FALSE;
++ char *s = xf86findOptionValue(input->inp_option_lst ,"AutoServerLayout");
++ Bool asl_found = xf86getBoolValue(&asl_value, s);
++ if (asl_found == TRUE && asl_value == TRUE)
+ {
+ XF86ConfInputrefPtr iref = layout->lay_input_lst;
+
--- /dev/null
+From a6b9e8f1e5d5d0b3b0f121a6f677eeca7aab1950 Mon Sep 17 00:00:00 2001
+From: Adam Jackson <ajax@redhat.com>
+Date: Wed, 25 Aug 2010 15:06:38 +0000
+Subject: linux: Fix CPU usage bug in console fd flushing
+
+If the vt gets a vhangup from under us, then the tty will appear ready
+in select(), but trying to tcflush() it will return -EIO, so we'll spin
+around at 100% CPU for no reason. Notice this condition and unregister
+the handler if it happens.
+
+Signed-off-by: Adam Jackson <ajax@redhat.com>
+Reviewed-by: Mikhail Gusarov <dottedmag@dottedmag.net>
+Reviewed-by: Julien Cristau <jcristau@debian.org>
+Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
+---
+diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
+index bf61ceb..7ee9046 100644
+--- a/hw/xfree86/os-support/linux/lnx_init.c
++++ b/hw/xfree86/os-support/linux/lnx_init.c
+@@ -85,7 +85,11 @@ static void *console_handler;
+ static void
+ drain_console(int fd, void *closure)
+ {
+- tcflush(fd, TCIOFLUSH);
++ errno = 0;
++ if (tcflush(fd, TCIOFLUSH) == -1 && errno == EIO) {
++ xf86RemoveGeneralHandler(console_handler);
++ console_handler = NULL;
++ }
+ }
+
+ void
+--
+cgit v0.8.3-6-g21f6
--- /dev/null
+--- xorg-server-1.6.5/os/access.c
++++ xorg-server-1.6.5/os/access.c
+@@ -781,7 +781,9 @@
+
+ /*
+ * ignore 'localhost' entries as they're not useful
+- * on the other end of the wire
++ * on the other end of the wire and because on hosts
++ * with shared home dirs they'll result in conflic
++ * entries in ~/.Xauthority
+ */
+ if (ifr->ifa_flags & IFF_LOOPBACK)
+ continue;
+@@ -804,6 +806,14 @@
+ else if (family == FamilyInternet6 &&
+ IN6_IS_ADDR_LOOPBACK((struct in6_addr *)addr))
+ continue;
++
++ /* Ignore IPv6 link local addresses (fe80::/10), because
++ * they need a scope identifier, which we have no way
++ * of telling to the other end.
++ */
++ if (family == FamilyInternet6 &&
++ IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)addr))
++ continue;
+ #endif
+ XdmcpRegisterConnection(family, (char *)addr, len);
+ #if defined(IPv6) && defined(AF_INET6)
--- /dev/null
+Index: xorg-server-1.6.3.901/hw/xfree86/common/xf86AutoConfig.c
+================================================================================
+--- xorg-server-1.7.99/hw/xfree86/common/xf86AutoConfig.c
++++ xorg-server-1.7.99/hw/xfree86/common/xf86AutoConfig.c
+@@ -535,7 +535,8 @@
+ #if !defined(__linux__) && defined(__sparc__)
+ matches[i++] = xnfstrdup("wsfb");
+ #else
+- matches[i++] = xnfstrdup("vesa");
++ if (geteuid() == 0)
++ matches[i++] = xnfstrdup("vesa");
+ #endif
+ }
+ }
--- /dev/null
+Also, don't treat DRI setup failure as an error for nouveau.
+---
+
+diff --git a/glx/glxdri.c b/glx/glxdri.c
+index 21e44d1..30b820c 100644
+--- a/glx/glxdri.c
++++ b/glx/glxdri.c
+@@ -968,6 +968,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
+ const __DRIconfig **driConfigs;
+ const __DRIextension **extensions;
+ int i;
++ int from = X_ERROR;
+
+ if (!xf86LoaderCheckSymbol("DRIQueryDirectRenderingCapable") ||
+ !DRIQueryDirectRenderingCapable(pScreen, &isCapable) ||
+@@ -1047,7 +1048,9 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
+
+ screen->driver = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
+ if (screen->driver == NULL) {
+- LogMessage(X_ERROR, "AIGLX error: dlopen of %s failed (%s)\n",
++ if (!strcmp(driverName, "nouveau"))
++ from = X_INFO;
++ LogMessage(from, "AIGLX error: dlopen of %s failed (%s)\n",
+ filename, dlerror());
+ goto handle_error;
+ }
+@@ -1184,7 +1187,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
+
+ free(screen);
+
+- LogMessage(X_ERROR, "AIGLX: reverting to software rendering\n");
++ LogMessage(from, "AIGLX: reverting to software rendering\n");
+
+ return NULL;
+ }
+diff --git a/glx/glxdri2.c b/glx/glxdri2.c
+index 0f998de..a244809 100644
+--- a/glx/glxdri2.c
++++ b/glx/glxdri2.c
+@@ -676,6 +676,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
+ const __DRIextension **extensions;
+ const __DRIconfig **driConfigs;
+ int i;
++ int from = X_ERROR;
+
+ screen = calloc(1, sizeof *screen);
+ if (screen == NULL)
+@@ -702,7 +703,9 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
+
+ screen->driver = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
+ if (screen->driver == NULL) {
+- LogMessage(X_ERROR, "AIGLX error: dlopen of %s failed (%s)\n",
++ if (!strcmp(driverName, "nouveau"))
++ from = X_INFO;
++ LogMessage(from, "AIGLX error: dlopen of %s failed (%s)\n",
+ filename, dlerror());
+ goto handle_error;
+ }
+@@ -793,7 +796,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
+
+ free(screen);
+
+- LogMessage(X_ERROR, "AIGLX: reverting to software rendering\n");
++ LogMessage(from, "AIGLX: reverting to software rendering\n");
+
+ return NULL;
+ }
--- /dev/null
+From a3e15680da24cb8259f6a83dee0c930dab024290 Mon Sep 17 00:00:00 2001
+From: Kristian <krh@redhat.com>
+Date: Fri, 15 Aug 2008 15:15:14 +1000
+Subject: [PATCH] Add nr for background=none root
+
+---
+ dix/globals.c | 1 +
+ dix/window.c | 22 ++++++++++++----------
+ hw/xfree86/common/xf86Init.c | 11 +++++++++++
+ hw/xfree86/common/xf86str.h | 5 ++++-
+ include/opaque.h | 1 +
+ os/utils.c | 3 +++
+ 6 files changed, 32 insertions(+), 11 deletions(-)
+
+Index: xorg-server-1.8.0/dix/globals.c
+===================================================================
+Index: xorg-server-1.8.0/dix/window.c
+===================================================================
+--- xorg-server-1.8.0.orig/dix/window.c
++++ xorg-server-1.8.0/dix/window.c
+@@ -465,23 +465,24 @@ InitRootWindow(WindowPtr pWin)
+ pWin->cursorIsNone = FALSE;
+ pWin->optional->cursor = rootCursor;
+ rootCursor->refcnt++;
+-
++ pWin->backingStore = defaultBackingStore;
++ pWin->forcedBS = (defaultBackingStore != NotUseful);
+
+ if (party_like_its_1989) {
+ MakeRootTile(pWin);
+ backFlag |= CWBackPixmap;
++ pScreen->ChangeWindowAttributes(pWin, backFlag);
++ } else if (bgNoneRoot) {
++ /* nothing, handled in xf86CreateRootWindow */
+ } else {
+ if (whiteRoot)
+ pWin->background.pixel = pScreen->whitePixel;
+ else
+ pWin->background.pixel = pScreen->blackPixel;
+ backFlag |= CWBackPixel;
+- }
+
+- pWin->backingStore = defaultBackingStore;
+- pWin->forcedBS = (defaultBackingStore != NotUseful);
+- /* We SHOULD check for an error value here XXX */
+- (*pScreen->ChangeWindowAttributes)(pWin, backFlag);
++ pScreen->ChangeWindowAttributes(pWin, backFlag);
++ }
+
+ MapWindow(pWin, serverClient);
+ }
+Index: xorg-server-1.8.0/hw/xfree86/common/xf86Init.c
+===================================================================
+Index: xorg-server-1.8.0/hw/xfree86/common/xf86str.h
+===================================================================
+--- xorg-server-1.8.0.orig/hw/xfree86/common/xf86str.h
++++ xorg-server-1.8.0/hw/xfree86/common/xf86str.h
+@@ -503,7 +503,7 @@ typedef struct _confdrirec {
+ } confDRIRec, *confDRIPtr;
+
+ /* These values should be adjusted when new fields are added to ScrnInfoRec */
+-#define NUM_RESERVED_INTS 16
++#define NUM_RESERVED_INTS 15
+ #define NUM_RESERVED_POINTERS 14
+ #define NUM_RESERVED_FUNCS 11
+
+@@ -775,6 +775,9 @@ typedef struct _ScrnInfoRec {
+ ClockRangePtr clockRanges;
+ int adjustFlags;
+
++ /* -nr support */
++ int canDoBGNoneRoot;
++
+ /*
+ * These can be used when the minor ABI version is incremented.
+ * The NUM_* parameters must be reduced appropriately to keep the
+Index: xorg-server-1.8.0/include/opaque.h
+===================================================================
+--- xorg-server-1.8.0.orig/include/opaque.h
++++ xorg-server-1.8.0/include/opaque.h
+@@ -71,6 +71,7 @@ extern _X_EXPORT Bool defeatAccessContro
+ extern _X_EXPORT long maxBigRequestSize;
+ extern _X_EXPORT Bool party_like_its_1989;
+ extern _X_EXPORT Bool whiteRoot;
++extern _X_EXPORT Bool bgNoneRoot;
+
+ extern _X_EXPORT Bool CoreDump;
+
+Index: xorg-server-1.8.0/os/utils.c
+===================================================================
+--- xorg-server-1.8.0.orig/os/utils.c
++++ xorg-server-1.8.0/os/utils.c
+@@ -511,6 +511,7 @@ void UseMsg(void)
+ #endif
+ ErrorF("-nolisten string don't listen on protocol\n");
+ ErrorF("-noreset don't reset after last client exists\n");
++ ErrorF("-nr create root window with no background\n");
+ ErrorF("-reset reset after last client exists\n");
+ ErrorF("-p # screen-saver pattern duration (minutes)\n");
+ ErrorF("-pn accept failure to listen on all ports\n");
+@@ -852,6 +853,8 @@ ProcessCommandLine(int argc, char *argv[
+ defaultBackingStore = WhenMapped;
+ else if ( strcmp( argv[i], "-wr") == 0)
+ whiteRoot = TRUE;
++ else if ( strcmp( argv[i], "-nr") == 0)
++ bgNoneRoot = TRUE;
+ else if ( strcmp( argv[i], "-maxbigreqsize") == 0) {
+ if(++i < argc) {
+ long reqSizeArg = atol(argv[i]);
+--- xorg-server-1.9.0/dix/globals.c.orig 2010-06-06 19:53:51.000000000 +0200
++++ xorg-server-1.9.0/dix/globals.c 2010-08-23 15:27:52.000000000 +0200
+@@ -122,6 +122,7 @@ FontPtr defaultFont; /* not declared i
+ CursorPtr rootCursor;
+ Bool party_like_its_1989 = FALSE;
+ Bool whiteRoot = FALSE;
++Bool bgNoneRoot = FALSE;
+
+ TimeStamp currentTime;
+ TimeStamp lastDeviceEventTime;
+--- xorg-server-1.9.0/hw/xfree86/common/xf86Init.c.orig 2010-06-10 16:07:55.000000000 +0200
++++ xorg-server-1.9.0/hw/xfree86/common/xf86Init.c 2010-08-23 15:32:56.000000000 +0200
+@@ -76,6 +76,7 @@
+ #include "xf86Xinput.h"
+ #include "xf86InPriv.h"
+ #include "picturestr.h"
++#include "xace.h"
+
+ #include "xf86Bus.h"
+ #include "xf86VGAarbiter.h"
+@@ -242,6 +243,7 @@ xf86CreateRootWindow(WindowPtr pWin)
+ int ret = TRUE;
+ int err = Success;
+ ScreenPtr pScreen = pWin->drawable.pScreen;
++ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ RootWinPropPtr pProp;
+ CreateWindowProcPtr CreateWindow = (CreateWindowProcPtr)
+ dixLookupPrivate(&pScreen->devPrivates, xf86CreateRootWindowKey);
+@@ -293,6 +295,17 @@ xf86CreateRootWindow(WindowPtr pWin)
+ }
+ }
+
++ if (bgNoneRoot) {
++ if (pScrn->canDoBGNoneRoot) {
++ pWin->backgroundState = XaceBackgroundNoneState(pWin);
++ pWin->background.pixel = pScreen->whitePixel;
++ pScreen->ChangeWindowAttributes(pWin, CWBackPixmap | CWBorderPixel | CWCursor | CWBackingStore);
++ } else {
++ pWin->background.pixel = pScreen->blackPixel;
++ pScreen->ChangeWindowAttributes(pWin, CWBackPixel | CWBorderPixel | CWCursor | CWBackingStore);
++ }
++ }
++
+ DebugF("xf86CreateRootWindow() returns %d\n", ret);
+ return ret;
+ }
--- /dev/null
+Index: xorg-server-1.6.3.901/hw/xfree86/common/xf86Config.c
+================================================================================
+--- xorg-server-1.7.99/hw/xfree86/common/xf86Config.c
++++ xorg-server-1.7.99/hw/xfree86/common/xf86Config.c
+@@ -696,6 +696,7 @@
+ FLAG_NOTRAPSIGNALS,
+ FLAG_DONTVTSWITCH,
+ FLAG_DONTZAP,
++ FLAG_ZAPWARNING,
+ FLAG_DONTZOOM,
+ FLAG_DISABLEVIDMODE,
+ FLAG_ALLOWNONLOCAL,
+@@ -734,6 +735,8 @@
+ {0}, FALSE },
+ { FLAG_DONTZAP, "DontZap", OPTV_BOOLEAN,
+ {0}, FALSE },
++ { FLAG_ZAPWARNING, "ZapWarning", OPTV_BOOLEAN,
++ {0}, FALSE },
+ { FLAG_DONTZOOM, "DontZoom", OPTV_BOOLEAN,
+ {0}, FALSE },
+ { FLAG_DISABLEVIDMODE, "DisableVidModeExtension", OPTV_BOOLEAN,
+@@ -840,6 +843,7 @@
+ xf86GetOptValBool(FlagOptions, FLAG_NOTRAPSIGNALS, &xf86Info.notrapSignals);
+ xf86GetOptValBool(FlagOptions, FLAG_DONTVTSWITCH, &xf86Info.dontVTSwitch);
+ xf86GetOptValBool(FlagOptions, FLAG_DONTZAP, &xf86Info.dontZap);
++ xf86GetOptValBool(FlagOptions, FLAG_ZAPWARNING, &xf86Info.ZapWarning);
+ xf86GetOptValBool(FlagOptions, FLAG_DONTZOOM, &xf86Info.dontZoom);
+
+ xf86GetOptValBool(FlagOptions, FLAG_IGNORE_ABI, &xf86Info.ignoreABI);
+--- xorg-server-1.7.99/hw/xfree86/common/xf86Events.c
++++ xorg-server-1.7.99/hw/xfree86/common/xf86Events.c
+@@ -180,12 +180,26 @@
+ DebugF("ProcessActionEvent(%d,%x)\n", (int) action, arg);
+ switch (action) {
+ case ACTION_TERMINATE:
+- if (!xf86Info.dontZap) {
++ if (xf86Info.dontZap)
++ break;
++
++ if (xf86Info.ZapWarning) {
++ static struct timeval LastZap = { 0, 0};
++ struct timeval NewZap;
++
++ gettimeofday(&NewZap, NULL);
++
++ if ((NewZap.tv_sec - LastZap.tv_sec) >= 2) {
++ xf86OSRingBell(100, 1000, 500);
++ LastZap = NewZap;
++ break;
++ }
++ }
++
+ #ifdef XFreeXDGA
+- DGAShutdown();
++ DGAShutdown();
+ #endif
+- GiveUp(0);
+- }
++ GiveUp(0);
+ break;
+ case ACTION_NEXT_MODE:
+ if (!xf86Info.dontZoom)
+--- xorg-server-1.7.99/hw/xfree86/common/xf86Globals.c
++++ xorg-server-1.7.99/hw/xfree86/common/xf86Globals.c
+@@ -109,6 +109,7 @@
+ #endif
+ .dontVTSwitch = FALSE,
+ .dontZap = FALSE,
++ .ZapWarning = TRUE,
+ .dontZoom = FALSE,
+ .notrapSignals = FALSE,
+ .caughtSignal = FALSE,
+--- xorg-server-1.7.99/hw/xfree86/common/xf86Privstr.h
++++ xorg-server-1.7.99/hw/xfree86/common/xf86Privstr.h
+@@ -67,6 +67,7 @@
+ #endif
+ Bool dontVTSwitch;
+ Bool dontZap;
++ Bool ZapWarning;
+ Bool dontZoom;
+ Bool notrapSignals; /* don't exit cleanly - die at fault */
+ Bool caughtSignal;
+--- xorg-server-1.7.99/hw/xfree86/doc/man/Xorg.man.pre
++++ xorg-server-1.7.99/hw/xfree86/doc/man/Xorg.man.pre
+@@ -438,7 +438,7 @@
+ .B Ctrl+Alt+Backspace
+ Immediately kills the server -- no questions asked. It can be disabled by
+ setting the
+-.B DontZap
++.B DontZap/ZapWarning
+ __xconfigfile__(__filemansuffix__) file option to a TRUE value.
+ .PP
+ .RS 8
+--- xorg-server-1.7.99/hw/xfree86/doc/man/xorg.conf.man.pre
++++ xorg-server-1.7.99/hw/xfree86/doc/man/xorg.conf.man.pre
+@@ -507,6 +507,13 @@
+ When this option is enabled, the action has no effect.
+ Default: off.
+ .TP 7
++.BI "Option \*qZapWarning\*q \*q" boolean \*q
++This warns the user loudly when the
++.B Ctrl+Alt+Backspace
++sequence is pressed for the first time but still terminates the __xservername__
++server when this key-sequence is pressed again shortly after.
++Default: on.
++.TP 7
+ .BI "Option \*qDontZoom\*q \*q" boolean \*q
+ This disallows the use of the
+ .B Ctrl+Alt+Keypad\-Plus
--- /dev/null
+#
+# spec file for package xorg-x11-Xvnc
+#
+# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany.
+#
+# All modifications and additions to the file contributed by third parties
+# remain the property of their copyright owners, unless otherwise agreed
+# upon. The license for this file, and modifications and additions to the
+# file, is the same license as for the pristine package itself (unless the
+# license for the pristine package is not an Open Source License, in which
+# case the license is the MIT License). An "Open Source License" is a
+# license that conforms to the Open Source Definition (Version 1.9)
+# published by the Open Source Initiative.
+
+# Please submit bugfixes or comments via http://bugs.opensuse.org/
+#
+%define snap 20131202svn5145
+%define debug_package %{nil}
+
+
+Name: tigervnc
+Version: 1.3.80
+Release: 1%{?snap:.%{snap}}%{?dist}
+Packager: Brian P. Hinz <bphinz@users.sourceforge.net>
+License: GPL-2.0 and MIT
+Conflicts: tightvnc xorg-x11-Xvnc
+Requires: xorg-x11-fonts-core xorg-x11
+Requires: libpixman-1-0 >= 0.15.2
+Requires: xinetd
+BuildRequires: Mesa-devel bison flex fontconfig-devel freetype2-devel ghostscript-library libdrm-devel libopenssl-devel pkgconfig xorg-x11 xorg-x11-devel xorg-x11-fonts-devel xorg-x11-libICE-devel xorg-x11-libSM-devel xorg-x11-libX11-devel xorg-x11-libXau-devel xorg-x11-libXdmcp-devel xorg-x11-libXext-devel xorg-x11-libXfixes-devel xorg-x11-libXmu-devel xorg-x11-libXp-devel xorg-x11-libXpm-devel xorg-x11-libXprintUtil-devel xorg-x11-libXrender-devel xorg-x11-libXt-devel xorg-x11-libXv-devel xorg-x11-libfontenc-devel xorg-x11-libxkbfile-devel xorg-x11-proto-devel xorg-x11-xtrans-devel
+BuildRequires: xorg-x11-devel gcc-c++ libstdc++-devel zlib-devel libpng-devel
+%ifarch %ix86
+BuildRequires: nasm
+%endif
+BuildRequires: java-devel update-alternatives
+BuildRequires: gcc make glibc-devel gettext gettext-devel intltool
+%if 0%{?%suse_version} >= 1100
+BuildRequires: gettext-tools
+%endif
+BuildRequires: autoconf automake libtool update-desktop-files perl
+BuildRequires: xorg-x11-server-sdk Mesa-devel libopenssl-devel gcc patch
+BuildRequires: nasm gcc-c++ pkgconfig(xproto) pkgconfig(x11) pkgconfig(xext) pkgconfig(xtst)
+BuildRequires: cmake >= 2.8 autoconf automake libtool binutils-gold
+BuildRequires: java-devel jpackage-utils
+# Because of keytool to build java client
+BuildRequires: mozilla-nss
+BuildRequires: xorg-x11-libICE-devel xorg-x11-libSM-devel pkgconfig(libtasn1) pkgconfig(gnutls) libgcrypt-devel libgpg-error-devel pam-devel
+BuildRequires: pkgconfig(fontutil)
+BuildRequires: pkg-config xmlto pkgconfig(pixman-1) >= 0.15.20 pkgconfig(glproto) pkgconfig(gl) pkgconfig(dri) pkgconfig(openssl)
+BuildRequires: pkgconfig(fixesproto) >= 4.1 pkgconfig(damageproto) >= 1.1 pkgconfig(xcmiscproto) >= 1.2.0
+BuildRequires: pkgconfig(bigreqsproto) >= 1.1.0 pkgconfig(xproto) >= 7.0.17 pkgconfig(randrproto) >= 1.2.99.3 pkgconfig(renderproto) >= 0.11
+BuildRequires: pkgconfig(xextproto) >= 7.0.99.3 pkgconfig(inputproto) >= 1.9.99.902 pkgconfig(kbproto) >= 1.0.3 pkgconfig(fontsproto)
+BuildRequires: pkgconfig(videoproto) pkgconfig(compositeproto) >= 0.4 pkgconfig(recordproto) >= 1.13.99.1 pkgconfig(scrnsaverproto) >= 1.1
+BuildRequires: pkgconfig(resourceproto) pkgconfig(xineramaproto) pkgconfig(xkbfile) pkgconfig(xau) pkgconfig(xdmcp) pkgconfig(xfont) >= 1.4.2
+BuildRequires: pkgconfig(pciaccess) >= 0.8.0
+URL: http://sourceforge.net/apps/mediawiki/tigervnc/
+BuildRoot: %{_tmppath}/%{name}-%{version}-build
+Group: System/X11/Servers/XF86_4
+Summary: A high-performance, platform-neutral implementation of VNC
+Source1: %{name}-%{version}%{?snap:-%{snap}}.tar.bz2
+Source2: xorg-server-1.9.3.tar.bz2
+Source3: vnc.xinetd
+Source4: 10-libvnc.conf
+Source5: vnc-server.firewall
+Source6: vnc-httpd.firewall
+Source7: vnc_inetd_httpd
+Source8: vnc.reg
+Source11: http://fltk.org/pub/fltk/1.3.2/fltk-1.3.2-source.tar.gz
+Source12: http://downloads.sourceforge.net/project/libjpeg-turbo/1.3.0/libjpeg-turbo-1.3.0.tar.gz
+
+
+# Tiger vnc patches
+Patch3: u_tigervnc-1.3.0-fix-use-after-free.patch
+Patch4: tigervnc-newfbsize.patch
+Patch5: tigervnc-clean-pressed-key-on-exit.patch
+
+# Xserver patches
+Patch1: fpic.diff
+Patch2: p_default-module-path.diff
+Patch6: pu_fixes.diff
+Patch8: p_bug96328.diff
+Patch13: p_xorg_acpi.diff
+Patch14: p_xkills_wrong_client.diff
+Patch16: p_xnest-ignore-getimage-errors.diff
+Patch23: disable-fbblt-opt.diff
+Patch27: mouse.diff
+Patch29: xephyr.diff
+Patch36: libdrm.diff
+
+Patch45: bug-197858_dpms.diff
+Patch67: xorg-docs.diff
+Patch77: fbdevhw.diff
+Patch79: edit_data_sanity_check.diff
+Patch93: pixman.diff
+Patch101: zap_warning_xserver.diff
+Patch103: confine_to_shape.diff
+Patch104: bitmap_always_unscaled.diff
+Patch106: randr1_1-sig11.diff
+Patch112: fix-dpi-values.diff
+Patch123: vidmode-sig11.diff
+Patch125: 0001-Xinput-Catch-missing-configlayout-when-deleting-dev.patch
+Patch127: dpms_screensaver.diff
+Patch128: pci-legacy-mem-fallback.diff
+Patch129: bug474071-fix1.diff
+Patch143: autoconfig_fallback_fbdev_first.diff
+Patch145: driver-autoconfig.diff
+Patch147: xserver-1.6.1-nouveau.patch
+Patch162: cache-xkbcomp-output-for-fast-start-up.patch
+Patch163: xserver-bg-none-root.patch
+Patch164: xorg-detect-psb.patch
+Patch168: xorg-server-nohwaccess.diff
+Patch169: xorg-x11-nonroot-vesa.patch
+Patch200: bug534768-prefer_local_symbols.patch
+Patch202: 0001-Check-harder-for-primary-PCI-device.patch
+Patch203: 0001-Fix-segfault-when-killing-X-with-ctrl-alt-backspace.patch
+Patch204: missing_font_paths.diff
+Patch205: xorg-server-1.8.0.diff
+Patch206: fix_fglrx_screendepth_issue.patch
+Patch207: xorg-server-option_libxf86config.diff
+Patch210: pio_ia64.diff
+Patch211: 0001-Prevent-XSync-Alarms-from-senslessly-calling-CheckTr.patch
+Patch213: xorg-server-xdmcp.patch
+Patch217: CVE-2010-2240-address_space_limit.patch
+Patch218: CVE-2010-2240-tree_depth_limit.patch
+Patch220: Use-external-tool-for-creating-backtraces-on-crashes.patch
+Patch221: commit-5c6a2f9.diff
+Patch222: sync-fix.patch
+Patch223: use-last-screen.patch
+Patch224: pad-size-of-system-memory-copy-for-1x1-pixmaps
+Patch225: xorg-server-stop-cpu-eating.diff
+Patch226: EXA-mixed-ModifyPixmapHeader-pitch-fixes.-bug-33929.patch
+Patch227: U_01-glx-make-sure-screen-is-non-negative-in-validGlxScreen.patch
+Patch228: U_02-glx-validate-request-lengths.patch
+Patch229: U_03-glx-check-request-length-before-swapping.patch
+Patch230: U_04-glx-swap-the-request-arrays-entirely-not-just-half-of-them.patch
+Patch231: U_05-glx-validate-numAttribs-field-before-using-it.patch
+Patch232: U_06-glx-fix-request-length-check-for-CreateGLXPbufferSGIX.patch
+Patch233: U_07-glx-fix-BindTexImageEXT-length-check.patch
+Patch234: U_08-glx-Work-around-wrong-request-lengths-sent-by-mesa.patch
+Patch235: U_xf86-fix-flush-input-to-work-with-Linux-evdev-device.patch
+Patch236: u_xserver_xvfb-randr.patch
+Patch237: U_os-Reset-input-buffer-s-ignoreBytes-field.patch
+Patch238: u_Avoid-use-after-free-in-dix-dixfonts.c-doImageText.patch
+
+# Fltk patches
+# Export dead key information from FLTK to the apps
+# http://www.fltk.org/str.php?L2599
+Patch510: http://www.fltk.org/strfiles/2599/fltk-1_v4.3.x-keyboard-x11.patch
+Patch511: http://www.fltk.org/strfiles/2599/fltk-1_v4.3.x-keyboard-win32.patch
+Patch512: http://www.fltk.org/strfiles/2599/fltk-1_v6.3.x-keyboard-osx.patch
+
+# Notify applications of changes to the clipboard
+# http://www.fltk.org/str.php?L2636
+Patch513: http://www.fltk.org/strfiles/2636/fltk-1.3.x-clipboard.patch
+Patch514: http://www.fltk.org/strfiles/2636/fltk-1_v6.3.x-clipboard-x11.patch
+Patch515: http://www.fltk.org/strfiles/2636/fltk-1_v3.3.x-clipboard-win32-fix.patch
+Patch516: http://www.fltk.org/strfiles/2636/fltk-1_v2.3.x-clipboard-win32.patch
+Patch517: http://www.fltk.org/strfiles/2636/fltk-1_v2.3.x-clipboard-osx.patch
+
+# Ability to convert a Fl_Pixmap to a Fl_RGB_Image
+# http://www.fltk.org/str.php?L2659
+Patch518: http://www.fltk.org/strfiles/2659/pixmap_v2.patch
+
+# Support for custom cursors
+# http://www.fltk.org/str.php?L2660
+Patch519: http://www.fltk.org/strfiles/2660/fltk-1_v5.3.x-cursor.patch
+
+# Improve modality interaction with WM
+# http://www.fltk.org/str.php?L2802
+Patch520: http://www.fltk.org/strfiles/2802/fltk-1_v2.3.0-modal.patch
+
+# Window icons
+# http://www.fltk.org/str.php?L2816
+Patch521: http://www.fltk.org/strfiles/2816/fltk-1_v3.3.0-icons.patch
+
+# Multihead
+# http://fltk.org/str.php?L2860
+Patch522: http://www.fltk.org/strfiles/2860/fltk-1.3.x-screen_num.patch
+Patch523: http://www.fltk.org/strfiles/2860/fltk-1_v3.3.x-multihead.patch
+
+%description
+TigerVNC is a high-performance, platform-neutral implementation of VNC (Virtual Network Computing),
+a client/server application that allows users to launch and interact with graphical applications on remote machines.
+TigerVNC provides the levels of performance necessary to run 3D and video applications;
+it attempts to maintain a common look and feel and re-use components, where possible, across the various platforms that it supports.
+TigerVNC also provides extensions for advanced authentication methods and TLS encryption.
+
+%prep
+%setup -T -b1 -q -n %{name}-%{version}%{?snap:-%{snap}}
+
+tar xjf %SOURCE2
+cp -r ./xorg-server-*/* unix/xserver/
+
+%patch3 -p1
+%patch4 -p1
+%patch5 -p1
+
+pushd unix/xserver
+for all in `find . -type f -perm -001`; do
+ chmod -x "$all"
+done
+patch -p1 < ../xserver19.patch
+%patch1
+%patch2
+%patch6
+%patch8 -p0
+%patch13
+%patch14
+%patch16 -p2
+%patch23
+%patch27
+%patch29
+%patch36 -p0
+
+%patch45 -p0
+%patch77
+%patch79 -p1
+%patch93
+%patch101 -p1
+%patch103
+%patch104 -p1
+%patch106 -p1
+%patch112 -p0
+%patch123 -p0
+%patch125 -p1
+%patch127 -p1
+%patch128
+pushd hw/xfree86/os-support/bus
+%patch129 -p0
+popd
+%patch143 -p0
+%patch145 -p0
+%patch147 -p1
+%patch162 -p1
+%patch163 -p1
+%patch164 -p1
+%patch168 -p1
+%patch169 -p1
+%patch200 -p1
+%patch202 -p1
+%patch203 -p1
+%patch204 -p0
+%patch205 -p0
+%patch206 -p0
+%patch207 -p0
+%patch210 -p1
+%patch211 -p1
+%patch213 -p1
+%patch217 -p1
+%patch218 -p1
+
+%patch221 -p1
+%patch222 -p1
+%patch223 -p1
+%patch224 -p1
+%patch225 -p1
+%patch226 -p1
+%patch227 -p1
+%patch228 -p1
+%patch229 -p1
+%patch230 -p1
+%patch231 -p1
+%patch232 -p1
+%patch233 -p1
+%patch234 -p1
+%patch235 -p1
+%patch236 -p1
+%patch237 -p1
+%patch238 -p1
+
+popd
+
+tar xzf %SOURCE11
+pushd fltk-*
+%patch510 -p1 -b .keyboard-x11
+%patch511 -p1 -b .keyboard-win32
+%patch512 -p1 -b .keyboard-osx
+%patch513 -p1 -b .clipboard
+%patch514 -p1 -b .clipboard-x11
+%patch515 -p1 -b .clipboard-win32-fix
+%patch516 -p1 -b .clipboard-win32
+%patch517 -p1 -b .clipboard-osx
+%patch518 -p1 -b .pixmap
+%patch519 -p1 -b .cursor
+%patch520 -p1 -b .modal
+%patch521 -p1 -b .icons
+%patch522 -p1 -b .screen_num
+%patch523 -p1 -b .multihead
+popd
+
+tar xzf %SOURCE12
+
+%build
+%define tigervnc_src_dir %{_builddir}/%{name}-%{version}%{?snap:-%{snap}}
+%define static_lib_buildroot %{tigervnc_src_dir}/build
+%ifarch sparcv9 sparc64 s390 s390x
+export CFLAGS="$RPM_OPT_FLAGS -fPIC"
+%else
+export CFLAGS="$RPM_OPT_FLAGS -fpic"
+%endif
+export CXXFLAGS="$CFLAGS"
+
+echo "*** Building fltk ***"
+pushd fltk-*
+cmake -G"Unix Makefiles" \
+ -DCMAKE_INSTALL_PREFIX=%{_prefix} \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DOPTION_PREFIX_LIB=%{_libdir} \
+ -DOPTION_PREFIX_CONFIG=%{_libdir} \
+ -DOPTION_BUILD_EXAMPLES=off \
+ -DOPTION_USE_SYSTEM_LIBPNG=on
+make %{?_smp_mflags}
+popd
+
+echo "*** Building libjpeg-turbo ***"
+pushd libjpeg-turbo-*
+export CXXFLAGS="$CFLAGS -static-libgcc"
+./configure --prefix=%{_prefix} --libdir=%{_libdir} --disable-nls --enable-static --disable-shared
+make %{?_smp_mflags} DESTDIR=%{static_lib_buildroot} install
+popd
+
+# Build all tigervnc
+cmake -G"Unix Makefiles" \
+ -DCMAKE_INSTALL_PREFIX:PATH=%{_prefix} \
+ -DCMAKE_BUILD_TYPE=RelWithDebInfo \
+ -DJPEG_INCLUDE_DIR=%{static_lib_buildroot}%{_includedir} \
+ -DJPEG_LIBRARY=%{static_lib_buildroot}%{_libdir}/libjpeg.a \
+ -DFLTK_LIBRARIES="%{tigervnc_src_dir}/fltk-1.3.2/lib/libfltk.a;%{tigervnc_src_dir}/fltk-1.3.2/lib/libfltk_images.a;-lpng" \
+ -DFLTK_INCLUDE_DIR=%{tigervnc_src_dir}/fltk-1.3.2
+make LDFLAGS="-lpng" %{?_smp_mflags}
+make %{?_smp_mflags}
+
+# Build Xvnc server
+pushd unix/xserver
+autoreconf -fiv
+chmod +x ./configure
+%configure CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing" \
+ --sysconfdir=/etc \
+ --enable-xdmcp \
+ --enable-xdm-auth-1 \
+ --enable-record \
+ --enable-xcsecurity \
+ --with-sha1=libcrypto \
+ --disable-xorg --disable-xnest --disable-xvfb --disable-dmx \
+ --disable-xwin --disable-xephyr --disable-kdrive --with-pic \
+ --disable-static --disable-xinerama \
+ --with-log-dir="/var/log" \
+ --with-os-name="openSUSE" \
+ --with-os-vendor="SUSE LINUX" \
+ --with-xkb-path="/usr/share/X11/xkb" \
+ --with-xkb-output="/var/lib/xkb/compiled" \
+ --enable-glx --disable-dri --enable-dri2 \
+ --disable-config-dbus \
+ --disable-config-hal \
+ --disable-config-udev \
+ --without-dtrace \
+ --disable-unit-tests \
+ --disable-devel-docs \
+ --with-fontrootdir=/usr/share/fonts \
+ --disable-selective-werror
+make %{?_smp_mflags}
+popd
+
+# Build icons
+pushd media
+make
+popd
+
+# Build java client
+pushd java
+cmake -DCMAKE_INSTALL_PREFIX:PATH=%{_prefix}
+make %{?_smp_mflags}
+popd
+
+%install
+
+%make_install
+
+pushd unix/xserver
+%make_install
+popd
+
+pushd java
+mkdir -p $RPM_BUILD_ROOT%{_datadir}/vnc/classes
+install -m755 VncViewer.jar $RPM_BUILD_ROOT%{_datadir}/vnc/classes
+install -m644 com/tigervnc/vncviewer/index.vnc $RPM_BUILD_ROOT%{_datadir}/vnc/classes
+popd
+
+# Install desktop stuff
+mkdir -p $RPM_BUILD_ROOT%{_datadir}/icons/hicolor/{16x16,24x24,48x48}/apps
+
+pushd media/icons
+for s in 16 24 48; do
+install -m644 tigervnc_$s.png $RPM_BUILD_ROOT%{_datadir}/icons/hicolor/${s}x$s/apps/tigervnc.png
+done
+popd
+
+install -D -m 644 %{SOURCE3} $RPM_BUILD_ROOT/etc/xinetd.d/vnc
+install -D -m 644 %{SOURCE4} $RPM_BUILD_ROOT/etc/X11/xorg.conf.d/10-libvnc.conf
+install -D -m 644 %{SOURCE5} $RPM_BUILD_ROOT/etc/sysconfig/SuSEfirewall2.d/services/vnc-server
+install -D -m 644 %{SOURCE6} $RPM_BUILD_ROOT/etc/sysconfig/SuSEfirewall2.d/services/vnc-httpd
+install -D -m 755 %{SOURCE7} $RPM_BUILD_ROOT%{_bindir}/vnc_inetd_httpd
+install -D -m 644 %{SOURCE8} $RPM_BUILD_ROOT/etc/slp.reg.d/vnc.reg
+
+%find_lang '%{name}'
+
+%files -f %{name}.lang
+%defattr(-,root,root,-)
+%{_bindir}/vncviewer
+%exclude /usr/share/doc/tigervnc-%{version}
+%doc LICENCE.TXT
+%doc README.txt
+%{_mandir}/man1/vncviewer.1*
+
+%{_bindir}/Xvnc
+%{_bindir}/vncconfig
+%{_bindir}/vncpasswd
+%{_bindir}/vncserver
+%{_bindir}/x0vncserver
+%{_bindir}/vnc_inetd_httpd
+
+%exclude %{_mandir}/man1/Xserver.1*
+%{_mandir}/man1/Xvnc.1*
+%{_mandir}/man1/vncconfig.1*
+%{_mandir}/man1/vncpasswd.1*
+%{_mandir}/man1/vncserver.1*
+%{_mandir}/man1/x0vncserver.1*
+
+%exclude /usr/%{_lib}/xorg/protocol.txt
+%exclude /usr/%{_lib}/xorg/modules/extensions/libvnc.la
+%{_libdir}/xorg/modules/extensions/libvnc.so
+
+%exclude /var/lib/xkb/compiled/README.compiled
+
+/etc/sysconfig/SuSEfirewall2.d/services/vnc-server
+/etc/sysconfig/SuSEfirewall2.d/services/vnc-httpd
+
+%config(noreplace) /etc/X11/xorg.conf.d/10-libvnc.conf
+%config(noreplace) /etc/xinetd.d/vnc
+%dir /etc/slp.reg.d
+%config(noreplace) /etc/slp.reg.d/vnc.reg
+
+%doc java/com/tigervnc/vncviewer/README
+%{_datadir}/vnc
+
+%{_datadir}/icons/hicolor/*/apps/*
+
+%changelog
+* Sat Dec 7 2013 Brian P. Hinz <bphinz@users.sourceforge.net>
+- Initial spec file created based on existing SLES & OpenSUSE spec files